1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -18,14 +18,14 @@ const onPluginSettingsChange = jest.fn();
const itemEvent = ({
item: { manifest: { id: pluginId } },
} as ItemEvent);
const callHook = (isUpdate: boolean, pluginEnabled = true) => () => useOnInstallHandler(
const callHook = (isUpdate: boolean, pluginEnabled = true, pluginInstalledViaGUI = true) => () => useOnInstallHandler(
setInstallingPluginIds,
{
[pluginId]: {
[pluginId]: pluginInstalledViaGUI ? {
enabled: pluginEnabled,
deleted: false,
hasBeenUpdated: false,
},
} : undefined,
},
repoApi,
onPluginSettingsChange,
@ -83,4 +83,9 @@ describe('useOnInstallHandler', () => {
const newSettings = onPluginSettingsChange.mock.calls[0][0].value;
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) => {
draft[pluginId] = defaultPluginSetting();
if (isUpdate) {
draft[pluginId].enabled = pluginSettings[pluginId].enabled;
if (pluginSettings[pluginId]) {
draft[pluginId].enabled = pluginSettings[pluginId].enabled;
}
draft[pluginId].hasBeenUpdated = true;
}
});