Skip to content

Commit

Permalink
[MM-53841] Remove upgrade notification if auto updates were switched …
Browse files Browse the repository at this point in the history
…off (#2801)
  • Loading branch information
devinbinnie committed Jul 31, 2023
1 parent a979a07 commit a05f408
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/main/downloadsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,6 +88,7 @@ jest.mock('common/config', () => {
const original = jest.requireActual('common/config');
return {
...original,
canUpgrade: true,
downloadLocation: downloadLocationMock,
};
});
Expand Down Expand Up @@ -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);
});
});

4 changes: 2 additions & 2 deletions src/main/downloadsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a05f408

Please sign in to comment.