From 376e4ebde09ad0b548ebc1fedddaced461b0a518 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 3 Apr 2023 18:01:06 +0200 Subject: [PATCH] Desktop: Fixed display of installed plugins in About box --- packages/app-desktop/gui/MenuBar.tsx | 7 +++++-- packages/lib/services/plugins/PluginService.ts | 5 +++++ packages/lib/versionInfo.test.ts | 18 ------------------ packages/lib/versionInfo.ts | 12 ++++-------- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/packages/app-desktop/gui/MenuBar.tsx b/packages/app-desktop/gui/MenuBar.tsx index 22cf6dbab..79589d4f4 100644 --- a/packages/app-desktop/gui/MenuBar.tsx +++ b/packages/app-desktop/gui/MenuBar.tsx @@ -21,7 +21,7 @@ import checkForUpdates from '../checkForUpdates'; const { connect } = require('react-redux'); import { reg } from '@joplin/lib/registry'; import { ProfileConfig } from '@joplin/lib/services/profileConfig/types'; -import PluginService from '@joplin/lib/services/plugins/PluginService'; +import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService'; const packageInfo = require('../packageInfo.js'); const { clipboard } = require('electron'); const Menu = bridge().Menu; @@ -128,6 +128,7 @@ interface Props { customCss: string; locale: string; profileConfig: ProfileConfig; + pluginSettings: PluginSettings; } const commandNames: string[] = menuCommandNames(); @@ -487,7 +488,7 @@ function useMenu(props: Props) { } function _showAbout() { - const v = versionInfo(packageInfo, PluginService.instance().plugins); + const v = versionInfo(packageInfo, PluginService.instance().enabledPlugins(props.pluginSettings)); const copyToClipboard = bridge().showMessageBox(v.message, { icon: `${bridge().electronApp().buildDir()}/icons/128x128.png`, @@ -930,6 +931,7 @@ function useMenu(props: Props) { props['spellChecker.languages'], // eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied props['spellChecker.enabled'], + props.pluginSettings, props.customCss, props.locale, props.profileConfig, @@ -985,6 +987,7 @@ const mapStateToProps = (state: AppState) => { ['folders.sortOrder.field']: state.settings['folders.sortOrder.field'], ['notes.sortOrder.reverse']: state.settings['notes.sortOrder.reverse'], ['folders.sortOrder.reverse']: state.settings['folders.sortOrder.reverse'], + pluginSettings: state.settings['plugins.states'], showNoteCounts: state.settings.showNoteCounts, uncompletedTodosOnTop: state.settings.uncompletedTodosOnTop, showCompletedTodos: state.settings.showCompletedTodos, diff --git a/packages/lib/services/plugins/PluginService.ts b/packages/lib/services/plugins/PluginService.ts index f327b77eb..40a10e54e 100644 --- a/packages/lib/services/plugins/PluginService.ts +++ b/packages/lib/services/plugins/PluginService.ts @@ -100,6 +100,11 @@ export default class PluginService extends BaseService { return this.plugins_; } + public enabledPlugins(pluginSettings: PluginSettings): Plugins { + const enabledPlugins = Object.fromEntries(Object.entries(this.plugins_).filter((p) => this.pluginEnabled(pluginSettings, p[0]))); + return enabledPlugins; + } + public get pluginIds(): string[] { return Object.keys(this.plugins_); } diff --git a/packages/lib/versionInfo.test.ts b/packages/lib/versionInfo.test.ts index 5faa204d7..6ba1f2aa5 100644 --- a/packages/lib/versionInfo.test.ts +++ b/packages/lib/versionInfo.test.ts @@ -2,8 +2,6 @@ import versionInfo from './versionInfo'; import { reg } from './registry'; import { Plugins } from './services/plugins/PluginService'; import Plugin from './services/plugins/Plugin'; -import Setting from './models/Setting'; -import { PluginSettings } from './services/plugins/PluginService'; jest.mock('./registry'); @@ -66,10 +64,6 @@ describe('getPluginLists', () => { const plugins: Plugins = {}; plugins[plugin.manifest.id] = plugin; - const pluginSettings: PluginSettings = {}; - pluginSettings[plugin.id] = { enabled: true, deleted: false, hasBeenUpdated: false }; - Setting.setValue('plugins.states', pluginSettings); - const v = versionInfo(packageInfo, plugins); expect(v.body).toMatch(/\n\nPlugin1: 1/); expect(v.message).toMatch(/\n\nPlugin1: 1/); @@ -93,12 +87,6 @@ describe('getPluginLists', () => { plugins[plugin.manifest.id] = plugin; } - const pluginSettings: PluginSettings = {}; - for (const key of Object.keys(plugins)) { - pluginSettings[key] = { enabled: true, deleted: false, hasBeenUpdated: false }; - } - Setting.setValue('plugins.states', pluginSettings); - const v = versionInfo(packageInfo, plugins); expect(v.body).toMatch(/\n\nPlugin1: 1\nPlugin2: 1\nPlugin3: 1/); @@ -124,12 +112,6 @@ describe('getPluginLists', () => { plugins[plugin.manifest.id] = plugin; } - const pluginSettings: PluginSettings = {}; - for (const key of Object.keys(plugins)) { - pluginSettings[key] = { enabled: true, deleted: false, hasBeenUpdated: false }; - } - Setting.setValue('plugins.states', pluginSettings); - const v = versionInfo(packageInfo, plugins); const body = '\n'; diff --git a/packages/lib/versionInfo.ts b/packages/lib/versionInfo.ts index 7ee4b67f0..78d8b347d 100644 --- a/packages/lib/versionInfo.ts +++ b/packages/lib/versionInfo.ts @@ -2,7 +2,6 @@ import { _ } from './locale'; import Setting from './models/Setting'; import { reg } from './registry'; import { Plugins } from './services/plugins/PluginService'; -import PluginService from './services/plugins/PluginService'; interface PluginList { completeList: string; @@ -11,16 +10,13 @@ interface PluginList { function getPluginLists(plugins: Plugins): PluginList { const pluginList = []; - const pluginSettings = PluginService.instance().unserializePluginSettings(Setting.value('plugins.states')); - const enabledPlugins = Object.fromEntries(Object.entries(plugins).filter((p) => pluginSettings[p[0]] && pluginSettings[p[0]].enabled === true)); - - if (Object.keys(enabledPlugins).length > 0) { - for (const pluginId in enabledPlugins) { - pluginList.push(`${enabledPlugins[pluginId].manifest.name}: ${enabledPlugins[pluginId].manifest.version}`); + if (Object.keys(plugins).length > 0) { + for (const pluginId in plugins) { + pluginList.push(`${plugins[pluginId].manifest.name}: ${plugins[pluginId].manifest.version}`); } } - pluginList.sort(); + pluginList.sort(Intl.Collator().compare); let completeList = ''; let summary = '';