Skip to content

Commit

Permalink
fix reloading plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
AAGaming00 committed Aug 8, 2024
1 parent 7a161a5 commit 93b3919
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 0 additions & 2 deletions frontend/src/components/settings/pages/plugin_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ function PluginInteractables(props: { entry: ReorderableEntry<PluginTableData> }
} catch (err) {
console.error('Error Reloading Plugin Backend', err);
}

DeckyPluginLoader.importPlugin(name, version);
}}
>
{t('PluginListIndex.reload')}
Expand Down
15 changes: 9 additions & 6 deletions frontend/src/plugin-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PluginLoader extends Logger {

private reloadLock: boolean = false;
// stores a list of plugin names which requested to be reloaded
private pluginReloadQueue: { name: string; version?: string }[] = [];
private pluginReloadQueue: { name: string; version?: string; loadType: PluginLoadType }[] = [];

private loaderUpdateToast?: ToastNotification;
private pluginUpdateToast?: ToastNotification;
Expand Down Expand Up @@ -369,11 +369,11 @@ class PluginLoader extends Logger {
this.errorBoundaryHook.deinit();
}

public unloadPlugin(name: string) {
public unloadPlugin(name: string, skipStateUpdate: boolean = false) {
const plugin = this.plugins.find((plugin) => plugin.name === name);
plugin?.onDismount?.();
this.plugins = this.plugins.filter((p) => p !== plugin);
this.deckyState.setPlugins(this.plugins);
if (!skipStateUpdate) this.deckyState.setPlugins(this.plugins);
}

public async importPlugin(
Expand All @@ -384,15 +384,15 @@ class PluginLoader extends Logger {
) {
if (useQueue && this.reloadLock) {
this.log('Reload currently in progress, adding to queue', name);
this.pluginReloadQueue.push({ name, version: version });
this.pluginReloadQueue.push({ name, version: version, loadType });
return;
}

try {
if (useQueue) this.reloadLock = true;
this.log(`Trying to load ${name}`);

this.unloadPlugin(name);
this.unloadPlugin(name, true);
const startTime = performance.now();
await this.importReactPlugin(name, version, loadType);
const endTime = performance.now();
Expand All @@ -406,7 +406,7 @@ class PluginLoader extends Logger {
this.reloadLock = false;
const nextPlugin = this.pluginReloadQueue.shift();
if (nextPlugin) {
this.importPlugin(nextPlugin.name, nextPlugin.version);
this.importPlugin(nextPlugin.name, nextPlugin.version, loadType);
}
}
}
Expand All @@ -428,6 +428,7 @@ class PluginLoader extends Logger {
...plugin,
name: name,
version: version,
loadType,
});
break;

Expand All @@ -447,6 +448,7 @@ class PluginLoader extends Logger {
...plugin,
name: name,
version: version,
loadType,
});
} else throw new Error(`${name} frontend_bundle not OK`);
break;
Expand Down Expand Up @@ -484,6 +486,7 @@ class PluginLoader extends Logger {
version: version,
content: <TheError />,
icon: <FaExclamationCircle />,
loadType,
});
this.toaster.toast({
title: (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum PluginLoadType {
export interface Plugin {
name: string;
version?: string;
loadType?: PluginLoadType;
icon: JSX.Element;
content?: JSX.Element;
onDismount?(): void;
Expand Down

0 comments on commit 93b3919

Please sign in to comment.