Skip to content

Commit 81c654b

Browse files
committed
feat(updater): download progress bar
1 parent 55b8c6b commit 81c654b

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

src/main/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function createWindow() {
3434
show: true
3535
});
3636

37-
runAutoUpdater();
37+
runAutoUpdater(mainWindow);
3838

3939
mainWindowState.manage(mainWindow);
4040
mainWindow.loadFile(path.join(__dirname, '../index.html'));

src/main/runAutoUpdater.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ autoUpdater.logger = electronLog;
1313

1414
autoUpdater.autoDownload = false;
1515

16-
const setAutoUpdater = () => {
16+
const setAutoUpdater = mainWindow => () => {
1717
const isNotificationsSupported = Notification.isSupported();
1818
electronLog.debug('isNotificationsSupported', isNotificationsSupported);
1919

@@ -51,6 +51,14 @@ const setAutoUpdater = () => {
5151
}
5252
});
5353

54+
autoUpdater.on('download-progress', (progressObj) => {
55+
electronLog.debug('progressObj', JSON.stringify(progressObj));
56+
const percent = progressObj && progressObj.percent;
57+
if (typeof percent === 'number') {
58+
mainWindow.setProgressBar(percent / 100);
59+
}
60+
});
61+
5462
autoUpdater.on('update-downloaded', () => {
5563
// For Windows: If update-downloaded notification is created before update-available is closed,
5664
// click event does not work. Thats why we add setTimeout 3000
@@ -84,25 +92,6 @@ const setAutoUpdater = () => {
8492
}, 5000)
8593
});
8694

87-
// autoUpdater.on('download-progress', (progressObj: any) => {
88-
// let logMessage: string = 'Downloaded ';
89-
// const percent = progressObj.percent;
90-
// TYPE NUMBER
91-
// electronLog.debug('typeof percent', typeof percent);
92-
// electronLog.debug('percent', percent);
93-
// if (typeof percent === 'string' || percent instanceof String) {
94-
// logMessage += percent.substr(0, 5);
95-
// } else if (typeof percent === 'number') {
96-
// logMessage += Math.floor(percent);
97-
// } else {
98-
// logMessage += percent;
99-
// }
100-
// logMessage += '%';
101-
// // let log_message = 'Download speed: ' + progressObj.bytesPerSecond;
102-
// // log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
103-
// // log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')';
104-
// sendNotificationToWindow(logMessage);
105-
// });
10695
};
10796

108-
exports.runAutoUpdater = () => setTimeout(setAutoUpdater, START_DELAY);
97+
exports.runAutoUpdater = (mainWindow) => setTimeout(setAutoUpdater(mainWindow), START_DELAY);

0 commit comments

Comments
 (0)