1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixed display of installed plugins in About box

This commit is contained in:
Laurent Cozic 2023-04-03 18:01:06 +02:00
parent fc335cd15d
commit 376e4ebde0
4 changed files with 14 additions and 28 deletions

View File

@ -21,7 +21,7 @@ import checkForUpdates from '../checkForUpdates';
const { connect } = require('react-redux'); const { connect } = require('react-redux');
import { reg } from '@joplin/lib/registry'; import { reg } from '@joplin/lib/registry';
import { ProfileConfig } from '@joplin/lib/services/profileConfig/types'; 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 packageInfo = require('../packageInfo.js');
const { clipboard } = require('electron'); const { clipboard } = require('electron');
const Menu = bridge().Menu; const Menu = bridge().Menu;
@ -128,6 +128,7 @@ interface Props {
customCss: string; customCss: string;
locale: string; locale: string;
profileConfig: ProfileConfig; profileConfig: ProfileConfig;
pluginSettings: PluginSettings;
} }
const commandNames: string[] = menuCommandNames(); const commandNames: string[] = menuCommandNames();
@ -487,7 +488,7 @@ function useMenu(props: Props) {
} }
function _showAbout() { function _showAbout() {
const v = versionInfo(packageInfo, PluginService.instance().plugins); const v = versionInfo(packageInfo, PluginService.instance().enabledPlugins(props.pluginSettings));
const copyToClipboard = bridge().showMessageBox(v.message, { const copyToClipboard = bridge().showMessageBox(v.message, {
icon: `${bridge().electronApp().buildDir()}/icons/128x128.png`, icon: `${bridge().electronApp().buildDir()}/icons/128x128.png`,
@ -930,6 +931,7 @@ function useMenu(props: Props) {
props['spellChecker.languages'], props['spellChecker.languages'],
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied // eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
props['spellChecker.enabled'], props['spellChecker.enabled'],
props.pluginSettings,
props.customCss, props.customCss,
props.locale, props.locale,
props.profileConfig, props.profileConfig,
@ -985,6 +987,7 @@ const mapStateToProps = (state: AppState) => {
['folders.sortOrder.field']: state.settings['folders.sortOrder.field'], ['folders.sortOrder.field']: state.settings['folders.sortOrder.field'],
['notes.sortOrder.reverse']: state.settings['notes.sortOrder.reverse'], ['notes.sortOrder.reverse']: state.settings['notes.sortOrder.reverse'],
['folders.sortOrder.reverse']: state.settings['folders.sortOrder.reverse'], ['folders.sortOrder.reverse']: state.settings['folders.sortOrder.reverse'],
pluginSettings: state.settings['plugins.states'],
showNoteCounts: state.settings.showNoteCounts, showNoteCounts: state.settings.showNoteCounts,
uncompletedTodosOnTop: state.settings.uncompletedTodosOnTop, uncompletedTodosOnTop: state.settings.uncompletedTodosOnTop,
showCompletedTodos: state.settings.showCompletedTodos, showCompletedTodos: state.settings.showCompletedTodos,

View File

@ -100,6 +100,11 @@ export default class PluginService extends BaseService {
return this.plugins_; 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[] { public get pluginIds(): string[] {
return Object.keys(this.plugins_); return Object.keys(this.plugins_);
} }

View File

@ -2,8 +2,6 @@ import versionInfo from './versionInfo';
import { reg } from './registry'; import { reg } from './registry';
import { Plugins } from './services/plugins/PluginService'; import { Plugins } from './services/plugins/PluginService';
import Plugin from './services/plugins/Plugin'; import Plugin from './services/plugins/Plugin';
import Setting from './models/Setting';
import { PluginSettings } from './services/plugins/PluginService';
jest.mock('./registry'); jest.mock('./registry');
@ -66,10 +64,6 @@ describe('getPluginLists', () => {
const plugins: Plugins = {}; const plugins: Plugins = {};
plugins[plugin.manifest.id] = plugin; 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); const v = versionInfo(packageInfo, plugins);
expect(v.body).toMatch(/\n\nPlugin1: 1/); expect(v.body).toMatch(/\n\nPlugin1: 1/);
expect(v.message).toMatch(/\n\nPlugin1: 1/); expect(v.message).toMatch(/\n\nPlugin1: 1/);
@ -93,12 +87,6 @@ describe('getPluginLists', () => {
plugins[plugin.manifest.id] = plugin; 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 v = versionInfo(packageInfo, plugins);
expect(v.body).toMatch(/\n\nPlugin1: 1\nPlugin2: 1\nPlugin3: 1/); expect(v.body).toMatch(/\n\nPlugin1: 1\nPlugin2: 1\nPlugin3: 1/);
@ -124,12 +112,6 @@ describe('getPluginLists', () => {
plugins[plugin.manifest.id] = plugin; 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 v = versionInfo(packageInfo, plugins);
const body = '\n'; const body = '\n';

View File

@ -2,7 +2,6 @@ import { _ } from './locale';
import Setting from './models/Setting'; import Setting from './models/Setting';
import { reg } from './registry'; import { reg } from './registry';
import { Plugins } from './services/plugins/PluginService'; import { Plugins } from './services/plugins/PluginService';
import PluginService from './services/plugins/PluginService';
interface PluginList { interface PluginList {
completeList: string; completeList: string;
@ -11,16 +10,13 @@ interface PluginList {
function getPluginLists(plugins: Plugins): PluginList { function getPluginLists(plugins: Plugins): PluginList {
const pluginList = []; const pluginList = [];
const pluginSettings = PluginService.instance().unserializePluginSettings(Setting.value('plugins.states')); if (Object.keys(plugins).length > 0) {
const enabledPlugins = Object.fromEntries(Object.entries(plugins).filter((p) => pluginSettings[p[0]] && pluginSettings[p[0]].enabled === true)); for (const pluginId in plugins) {
pluginList.push(`${plugins[pluginId].manifest.name}: ${plugins[pluginId].manifest.version}`);
if (Object.keys(enabledPlugins).length > 0) {
for (const pluginId in enabledPlugins) {
pluginList.push(`${enabledPlugins[pluginId].manifest.name}: ${enabledPlugins[pluginId].manifest.version}`);
} }
} }
pluginList.sort(); pluginList.sort(Intl.Collator().compare);
let completeList = ''; let completeList = '';
let summary = ''; let summary = '';