[MM-53841] Remove upgrade notification if auto updates were switched off (#2801)

This commit is contained in:
Devin Binnie
2023-07-31 09:19:40 -04:00
committed by GitHub
parent a979a0727f
commit a05f408b80
2 changed files with 27 additions and 2 deletions

View File

@@ -7,6 +7,9 @@ import {shell} from 'electron';
import {getDoNotDisturb as getDarwinDoNotDisturb} from 'macos-notification-state';
import Config from 'common/config';
import {APP_UPDATE_KEY} from 'common/constants';
import {DownloadsManager} from 'main/downloadsManager';
const downloadLocationMock = '/path/to/downloads';
@@ -85,6 +88,7 @@ jest.mock('common/config', () => {
const original = jest.requireActual('common/config');
return {
...original,
canUpgrade: true,
downloadLocation: downloadLocationMock,
};
});
@@ -224,5 +228,26 @@ describe('main/downloadsManager', () => {
expect(Object.keys(dl.downloads).includes('invalid_file5.txt')).toBe(false);
expect(Object.keys(dl.downloads).includes('invalid_file6.txt')).toBe(false);
});
it('should remove updates if they are disabled', () => {
const file = JSON.stringify({
...downloadsJson,
[APP_UPDATE_KEY]: {
type: 'update',
progress: 0,
location: '',
addedAt: 0,
receivedBytes: 0,
totalBytes: 0,
state: 'available',
filename: '1.2.3',
},
});
const dl = new DownloadsManager(file);
expect(dl.hasUpdate()).toBe(true);
Config.canUpgrade = false;
dl.init();
expect(dl.hasUpdate()).toBe(false);
});
});

View File

@@ -201,9 +201,9 @@ export class DownloadsManager extends JsonFileManager<DownloadedItems> {
continue;
}
// Remove update if app was updated and restarted
// Remove update if app was updated and restarted OR if we disabled auto updates
if (fileId === APP_UPDATE_KEY) {
if (appVersionManager.lastAppVersion === file.filename) {
if (appVersionManager.lastAppVersion === file.filename || !Config.canUpgrade) {
delete downloads[APP_UPDATE_KEY];
modified = true;
continue;