1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Fixes #4723: Plugin Update error when plugin was installed manually (#4725)

This commit is contained in:
mbalint
2021-03-24 15:15:49 +01:00
committed by GitHub
parent c119821c19
commit cd1f95c5ea
2 changed files with 11 additions and 4 deletions

View File

@ -18,14 +18,14 @@ const onPluginSettingsChange = jest.fn();
const itemEvent = ({ const itemEvent = ({
item: { manifest: { id: pluginId } }, item: { manifest: { id: pluginId } },
} as ItemEvent); } as ItemEvent);
const callHook = (isUpdate: boolean, pluginEnabled = true) => () => useOnInstallHandler( const callHook = (isUpdate: boolean, pluginEnabled = true, pluginInstalledViaGUI = true) => () => useOnInstallHandler(
setInstallingPluginIds, setInstallingPluginIds,
{ {
[pluginId]: { [pluginId]: pluginInstalledViaGUI ? {
enabled: pluginEnabled, enabled: pluginEnabled,
deleted: false, deleted: false,
hasBeenUpdated: false, hasBeenUpdated: false,
}, } : undefined,
}, },
repoApi, repoApi,
onPluginSettingsChange, onPluginSettingsChange,
@ -83,4 +83,9 @@ describe('useOnInstallHandler', () => {
const newSettings = onPluginSettingsChange.mock.calls[0][0].value; const newSettings = onPluginSettingsChange.mock.calls[0][0].value;
expect(newSettings[pluginId].hasBeenUpdated).toBe(true); expect(newSettings[pluginId].hasBeenUpdated).toBe(true);
}); });
test('should not fail when plugin was not installed through the GUI', async () => {
const { result: { current: onUpdate } } = renderHook(callHook(true, true, false));
await onUpdate(itemEvent);
});
}); });

View File

@ -40,7 +40,9 @@ export default function(setInstallingPluginIds: Function, pluginSettings: Plugin
const newSettings = produce(pluginSettings, (draft: PluginSettings) => { const newSettings = produce(pluginSettings, (draft: PluginSettings) => {
draft[pluginId] = defaultPluginSetting(); draft[pluginId] = defaultPluginSetting();
if (isUpdate) { if (isUpdate) {
draft[pluginId].enabled = pluginSettings[pluginId].enabled; if (pluginSettings[pluginId]) {
draft[pluginId].enabled = pluginSettings[pluginId].enabled;
}
draft[pluginId].hasBeenUpdated = true; draft[pluginId].hasBeenUpdated = true;
} }
}); });