Skip to content

Commit

Permalink
Desktop: Fixes #9725: Fix warning logged when uninstalling multiple p…
Browse files Browse the repository at this point in the history
…lugins (#9726)
  • Loading branch information
personalizedrefrigerator authored Jan 18, 2024
1 parent bdc970d commit d8d0e70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion packages/app-cli/tests/services/plugins/PluginService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion packages/lib/services/plugins/PluginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down

0 comments on commit d8d0e70

Please sign in to comment.