| 66 | ); |
| 67 | |
| 68 | class PluginLoader extends Logger { |
| 69 | private plugins: Plugin[] = []; |
| 70 | public errorBoundaryHook: ErrorBoundaryHook = new ErrorBoundaryHook(); |
| 71 | private tabsHook: TabsHook = new TabsHook(); |
| 72 | public routerHook: RouterHook = new RouterHook(); |
| 73 | public toaster: Toaster = new Toaster(); |
| 74 | private deckyState: DeckyState = new DeckyState(); |
| 75 | // stores a map of plugin names to all their event listeners |
| 76 | private pluginEventListeners: Map<string, listenerMap> = new Map(); |
| 77 | |
| 78 | public frozenPluginsService = new FrozenPluginService(this.deckyState); |
| 79 | public hiddenPluginsService = new HiddenPluginsService(this.deckyState); |
| 80 | public notificationService = new NotificationService(this.deckyState); |
| 81 | |
| 82 | private reloadLock: boolean = false; |
| 83 | // stores a list of plugin names which requested to be reloaded |
| 84 | private pluginReloadQueue: { name: string; version?: string; loadType: PluginLoadType }[] = []; |
| 85 | |
| 86 | private loaderUpdateToast?: ToastNotification; |
| 87 | private pluginUpdateToast?: ToastNotification; |
| 88 | |
| 89 | constructor() { |
| 90 | super(PluginLoader.name); |
| 91 | |
| 92 | DeckyBackend.addEventListener('loader/notify_updates', this.notifyUpdates.bind(this)); |
| 93 | DeckyBackend.addEventListener('loader/import_plugin', this.importPlugin.bind(this)); |
| 94 | DeckyBackend.addEventListener('loader/unload_plugin', this.unloadPlugin.bind(this)); |
| 95 | DeckyBackend.addEventListener('loader/disable_plugin', this.doDisablePlugin.bind(this)); |
| 96 | DeckyBackend.addEventListener('loader/add_plugin_install_prompt', this.addPluginInstallPrompt.bind(this)); |
| 97 | DeckyBackend.addEventListener( |
| 98 | 'loader/add_multiple_plugins_install_prompt', |
| 99 | this.addMultiplePluginsInstallPrompt.bind(this), |
| 100 | ); |
| 101 | DeckyBackend.addEventListener('updater/update_download_percentage', () => { |
| 102 | this.deckyState.setIsLoaderUpdating(true); |
| 103 | }); |
| 104 | DeckyBackend.addEventListener(`loader/plugin_event`, this.pluginEventListener); |
| 105 | |
| 106 | this.tabsHook.init(); |
| 107 | |
| 108 | const TabBadge = () => { |
| 109 | const { updates, hasLoaderUpdate } = useDeckyState(); |
| 110 | return <NotificationBadge show={(updates && updates.size > 0) || hasLoaderUpdate} />; |
| 111 | }; |
| 112 | |
| 113 | this.tabsHook.add({ |
| 114 | id: QuickAccessTab.Decky, |
| 115 | title: null, |
| 116 | content: ( |
| 117 | <DeckyStateContextProvider deckyState={this.deckyState}> |
| 118 | <PluginView /> |
| 119 | </DeckyStateContextProvider> |
| 120 | ), |
| 121 | icon: ( |
| 122 | <DeckyStateContextProvider deckyState={this.deckyState}> |
| 123 | <FaPlug /> |
| 124 | <TabBadge /> |
| 125 | </DeckyStateContextProvider> |