From d8d0e705f23c59f4693b9104bd37604b3b7a22fb Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Thu, 18 Jan 2024 03:24:44 -0800 Subject: [PATCH] Desktop: Fixes #9725: Fix warning logged when uninstalling multiple plugins (#9726) --- .../tests/services/plugins/PluginService.ts | 31 ++++++++++++++++++- .../lib/services/plugins/PluginService.ts | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/app-cli/tests/services/plugins/PluginService.ts b/packages/app-cli/tests/services/plugins/PluginService.ts index d5d0a715e..9bdb062c7 100644 --- a/packages/app-cli/tests/services/plugins/PluginService.ts +++ b/packages/app-cli/tests/services/plugins/PluginService.ts @@ -1,5 +1,5 @@ import PluginRunner from '../../../app/services/plugins/PluginRunner'; -import PluginService from '@joplin/lib/services/plugins/PluginService'; +import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService'; import { ContentScriptType } from '@joplin/lib/services/plugins/api/types'; import MdToHtml from '@joplin/renderer/MdToHtml'; import shim from '@joplin/lib/shim'; @@ -304,4 +304,33 @@ describe('services_PluginService', () => { expect(JSON.parse(folders[0].title)).toBe(expectedPath); })); + it('should uninstall multiple plugins', async () => { + const service = newPluginService(); + const pluginId1 = 'org.joplinapp.FirstJplPlugin'; + const pluginId2 = 'org.joplinapp.plugins.TocDemo'; + const pluginPath1 = `${testPluginDir}/jpl_test/${pluginId1}.jpl`; + const pluginPath2 = `${testPluginDir}/toc/${pluginId2}.jpl`; + + await service.installPlugin(pluginPath1); + await service.installPlugin(pluginPath2); + + // Both should be installed + expect(await fs.pathExists(`${Setting.value('pluginDir')}/${pluginId1}.jpl`)).toBe(true); + expect(await fs.pathExists(`${Setting.value('pluginDir')}/${pluginId2}.jpl`)).toBe(true); + + const pluginSettings: PluginSettings = { + [pluginId1]: { enabled: true, deleted: true, hasBeenUpdated: false }, + [pluginId2]: { enabled: true, deleted: true, hasBeenUpdated: false }, + }; + + const newPluginSettings = await service.uninstallPlugins(pluginSettings); + + // Should have deleted plugins + expect(await fs.pathExists(`${Setting.value('pluginDir')}/${pluginId1}.jpl`)).toBe(false); + expect(await fs.pathExists(`${Setting.value('pluginDir')}${pluginId2}.jpl`)).toBe(false); + + // Should clear deleted plugins from settings + expect(newPluginSettings[pluginId1]).toBe(undefined); + expect(newPluginSettings[pluginId2]).toBe(undefined); + }); }); diff --git a/packages/lib/services/plugins/PluginService.ts b/packages/lib/services/plugins/PluginService.ts index 8ef1de7a7..572242de6 100644 --- a/packages/lib/services/plugins/PluginService.ts +++ b/packages/lib/services/plugins/PluginService.ts @@ -505,7 +505,7 @@ export default class PluginService extends BaseService { for (const pluginId in settings) { if (settings[pluginId].deleted) { await this.uninstallPlugin(pluginId); - newSettings = { ...settings }; + newSettings = { ...newSettings }; delete newSettings[pluginId]; } }