Skip to content

Commit

Permalink
v1.6.2 fix issues checking plugin enablement status and improve lazy-…
Browse files Browse the repository at this point in the history
…plugin handling (#140)
  • Loading branch information
swar8080 authored Feb 4, 2025
1 parent 9358cfa commit 982c156
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 27 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,9 @@ Example Response, which contains info on the 10 latest versions of the plugin th
The goal is sending the API only information needed for the plugin to function. Currently that's your list of installed plugins and their versions. AWS also automatically collects your IP which I have access to, and have no way of disabling.

Any changes in what's collected will be included in release notes, but it's unlikely to change.

# Usage with lazy-plugin

When combining the *Ignore Updates to Disabled Plugins* setting with lazy-plugin, ensure that this plugin is loaded with the longest delay or else it may incorrectly identify another plugin as disabled.

Also, when this plugin detects that lazy-plugin and *Ignore Updates to Disabled Plugins* are enabled, this plugin will remain in the loading state for an extra 10 seconds before actually checking for updates. This helps avoid the issue of incorrectly considering a plugin disabled.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-plugin-update-tracker",
"name": "Plugin Update Tracker",
"version": "1.6.1",
"version": "1.6.2",
"minAppVersion": "0.15.0",
"description": "Know when installed plugins have updates and evaluate the risk of upgrading",
"author": "Obsidian",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-plugin-update-tracker",
"name": "Plugin Update Tracker",
"version": "1.6.1",
"version": "1.6.2",
"minAppVersion": "0.15.0",
"description": "Know when installed plugins have updates and evaluate the risk of upgrading",
"author": "Obsidian",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-plugin-update-tracker",
"version": "1.6.1",
"version": "1.6.2",
"description": "Know when installed plugins have updates and evaluate the risk of upgrading",
"main": "main.js",
"scripts": {
Expand Down
15 changes: 13 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@ export default class PluginUpdateCheckerPlugin extends Plugin {
store.dispatch(syncThisPluginId(this.manifest.id));

await this.loadSettings();
const {
payload: { enabledPlugins },
} = await store.dispatch(syncApp(this.app));
this.pollForInstalledPluginVersions();

store.dispatch(fetchReleases());
if (this.settings.excludeDisabledPlugins && enabledPlugins?.['lazy-plugin']) {
setTimeout(async () => {
// Avoid race conditions checking whether a plugin is enabled. Wait a bit before lazy plugin is done enabling plugins before displaying the filtered update count.
await store.dispatch(syncApp(this.app));
store.dispatch(fetchReleases());
}, 10000);
} else {
store.dispatch(fetchReleases());
}

this.pollForPluginReleases(this.settings, this.settings.hoursBetweenCheckingForUpdates);

if (Platform.isDesktop || SHOW_STATUS_BAR_ICON_ALL_PLATFORMS) {
Expand Down Expand Up @@ -98,7 +110,6 @@ export default class PluginUpdateCheckerPlugin extends Plugin {
}

pollForInstalledPluginVersions() {
store.dispatch(syncApp(this.app));
this.registerInterval(
window.setInterval(() => {
store.dispatch(syncApp(this.app));
Expand Down
38 changes: 19 additions & 19 deletions src/state/actionProducers/syncApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ export const syncApp = (app: App) => {
const obsidianApp = app as ObsidianApp;
const manifests = values(obsidianApp.plugins?.manifests) || [];

let enabledPlugins: Record<string, boolean> | undefined = undefined;
let enabledPlugins: Record<string, boolean> | undefined = {};

if (typeof obsidianApp.plugins?.isEnabled == 'function') {
// The isEnabled() function checks if the plugin is currently enabled, regardless of whether enablement is persisted.
// This is needed to work with plugins like lazy-plugin which seems to persist a disabled status and temporarily enable without persisting.
enabledPlugins = {};
const pluginIds = manifests.map((manifest) => manifest.id);
for (let pluginId of pluginIds) {
enabledPlugins[pluginId] = obsidianApp.plugins.isEnabled(pluginId);
}
} else if (obsidianApp.plugins?.enabledPlugins instanceof Set) {
// Old way of checking enabled plugins, which may be needed for compatibility with older versions of obsidian.
// This checks plugins saved as enabled, as in their enablement persists between reloads.
enabledPlugins = {};
for (let pluginId of obsidianApp.plugins.enabledPlugins) {
enabledPlugins[pluginId] = true;
const pluginIds = manifests.map((manifest) => manifest.id);
const persistedAsEnabledSet =
obsidianApp.plugins?.enabledPlugins instanceof Set
? obsidianApp.plugins.enabledPlugins
: undefined;

for (let pluginId of pluginIds) {
const currentlyEnabled = obsidianApp.plugins?.plugins?.[pluginId]?._loaded;
if (currentlyEnabled != undefined) {
// This is needed to work with plugins like lazy-plugin which seems to persist a disabled status and temporarily enable without persisting.
enabledPlugins[pluginId] = currentlyEnabled;
} else if (persistedAsEnabledSet) {
// Fallback in case undocumented _loaded API changes
enabledPlugins[pluginId] = persistedAsEnabledSet.has(pluginId);
} else {
console.warn(
'Unable to determine enabled plugins, obsidian APIs may have changed! Please file a bug report at https://github.com/swar8080/obsidian-plugin-update-tracker.'
);
}
} else {
console.warn(
'Unable to determine enabled plugins, obsidian APIs may have changed! Please file a bug report at https://github.com/swar8080/obsidian-plugin-update-tracker.'
);
}

return syncPluginManifests({ manifests, enabledPlugins });
Expand Down
2 changes: 1 addition & 1 deletion src/state/actionProducers/updatePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const updatePlugins = createAsyncThunk(
installedPlugin.getReleaseAssetIdsForVersion(versionToInstall);
const pluginRepoPath = installedPlugin.getRepoPath();
const isPluginEnabled =
state.obsidian.enabledPlugins != null && pluginId in state.obsidian.enabledPlugins;
state.obsidian.enabledPlugins != null && state.obsidian.enabledPlugins[pluginId];
const isUpdatingThisPlugin = pluginId === state.obsidian.thisPluginId;

let success: boolean;
Expand Down
7 changes: 6 additions & 1 deletion src/state/obsidianReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export type ObsidianApp = App & {
plugins?: {
manifests?: Record<string, PluginManifest>;
enabledPlugins?: Set<string>;
plugins?: Record<
string,
{
_loaded?: boolean;
}
>;
disablePlugin?: (pluginId: string) => Promise<any>;
enablePlugin?: (pluginId: string) => Promise<any>;
isEnabled?: (pluginId: string) => boolean;
loadManifests?: () => Promise<any>;
};
};
Expand Down
4 changes: 3 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
"1.5.0": "0.15.0",
"1.5.1": "0.15.0",
"1.5.2": "0.15.0",
"1.6.0": "0.15.0"
"1.6.0": "0.15.0",
"1.6.1": "0.15.0",
"1.6.2": "0.15.0"
}

0 comments on commit 982c156

Please sign in to comment.