Skip to content

Commit 4edec99

Browse files
committed
🚧 Automatic Update checking in background implemented
1 parent e3dc8f5 commit 4edec99

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

src/main/ipc/channel_types/PaletteChannel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PaletteChannel extends Channel {
1212
* Creates an instance of PaletteChannel.
1313
* @param {{windowManager: WindowManager, store: ElectronStore, tray: ElectronTray, colorFormats: ColorFormats}} channelProps
1414
* @param {event} ipcEventObject ipc event object
15-
* @param {{type: 'GET' | 'GET_ALL' | 'SAVE' | 'REMOVE_COLOR' | 'DELETE', args: *}} [ipcEventDataObject] the included data
15+
* @param {{type: 'GET' | 'GET_ALL' | 'SAVE' | 'DELETE', args: *}} [ipcEventDataObject] the included data
1616
* @memberof PaletteChannel
1717
*/
1818
constructor(channelProps, ipcEventObject, ipcEventDataObject) {

src/main/ipc/channel_types/SettingChannel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SettingChannel extends Channel {
2121
case "INSTALL_UPDATE":
2222
return this.installUpdate(autoUpdater);
2323
case "MODIFY_SETTING":
24-
return this.modifySetting(ipcEventDataObject.args, appController);
24+
return this.modifySetting(ipcEventDataObject.args, autoUpdater, appController);
2525
case "GET_SETTING":
2626
return this.getSetting(ipcEventDataObject.args);
2727
case "GET_ALL_SETTINGS":
@@ -52,7 +52,7 @@ class SettingChannel extends Channel {
5252
* Set or update a setting property
5353
* @param {{key: string, value: *}} args setting arguments
5454
*/
55-
modifySetting(args, appController) {
55+
modifySetting(args, autoUpdater, appController) {
5656
const currentSettings = this.Store.get("settings", {}); //TODO: create default settings object
5757
currentSettings[args.key] = args.value;
5858
this.Store.set("settings", currentSettings);
@@ -62,6 +62,11 @@ class SettingChannel extends Channel {
6262
case "launchOnStartup":
6363
appController.setLoginItem(args.value);
6464
break;
65+
case "autoCheckDownloadUpdates":
66+
autoUpdater.stopCheckInterval();
67+
if (args.value) {
68+
autoUpdater.startCheckInterval();
69+
}
6570
default:
6671
//log.log("Unhandled settings key", args.key);
6772
break;

src/main/resources/Updater.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,53 @@ class Updater {
1717
this._Store = store;
1818
this._WindowManager = wm;
1919
this._configureEventListener();
20+
this._AutoUpdaterInterval = null;
2021
autoUpdater.logger = log;
2122
autoUpdater.logger.transports.file.level = "info";
22-
autoUpdater.autoDownload = false;
23+
const settings = store.get("settings", {});
24+
this._AutoCheck =
25+
settings.autoCheckDownloadUpdates === undefined || settings.autoCheckDownloadUpdates === true ? true : false;
26+
autoUpdater.autoDownload = this._AutoCheck;
27+
28+
// Attempt to start auto updating interval if settings permit
29+
this.startCheckInterval();
30+
}
31+
32+
/**
33+
* Start the automatic update checking interval
34+
*
35+
* @memberof Updater
36+
*/
37+
startCheckInterval() {
38+
if (this._AutoCheck) {
39+
log.info("Starting Automatic Update Checking Interval");
40+
this._AutoUpdaterInterval = setInterval(() => {
41+
const settings = this._Store.get("settings", {});
42+
this._AutoCheck =
43+
settings.autoCheckDownloadUpdates === undefined || settings.autoCheckDownloadUpdates === true ? true : false;
44+
if (
45+
this._AutoCheck &&
46+
settings.lastUpdateCheck !== undefined &&
47+
new Date().getTime() - settings.lastUpdateCheck >= 3600000
48+
) {
49+
log.info("Auto Checking For Updates");
50+
this.checkForUpdates();
51+
}
52+
}, 3600000);
53+
}
54+
}
55+
56+
/**
57+
* Stop the automatic update checking interval
58+
*
59+
* @memberof Updater
60+
*/
61+
stopCheckInterval() {
62+
if (this._AutoUpdaterInterval !== null) {
63+
log.info("Stopping Automatic Update Checking Interval");
64+
clearInterval(this._AutoUpdaterInterval);
65+
this._AutoUpdaterInterval = null;
66+
}
2367
}
2468

2569
/**
@@ -28,7 +72,6 @@ class Updater {
2872
async checkForUpdates() {
2973
return await autoUpdater.checkForUpdates().catch(err => {
3074
log.error(err);
31-
reject(err);
3275
});
3376
}
3477

0 commit comments

Comments
 (0)