Skip to content

Commit 5b1fcfa

Browse files
committed
auto update dialog moduler
1 parent a3d74d5 commit 5b1fcfa

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

src/controller/CheckForUpdate.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { dialog } = require('electron');
12
const { autoUpdater } = require('electron-updater');
23

34
const status = {
@@ -37,6 +38,28 @@ const checkForUpdate = () => {
3738
return status;
3839
};
3940

41+
const showDialog = () => {
42+
// const status = this.updateStatus;
43+
const detail = status.updateAvailable
44+
? status.updateAvailable.releaseNotes
45+
: status.details;
46+
const dialogOpts = {
47+
type: 'info',
48+
buttons: [status.details.releaseNotes ? 'Update' : 'Ok', 'Cancel'],
49+
title: 'DevTop Essential Update',
50+
message: status.message,
51+
detail,
52+
};
53+
dialog.showMessageBox(dialogOpts, response => {
54+
if (status.details.releaseNotes && response === 0) {
55+
console.log('Update Now');
56+
} else if (response === 0) {
57+
console.log('Okay go out');
58+
}
59+
});
60+
};
61+
4062
module.exports = {
4163
checkForUpdate,
64+
showDialog,
4265
};

src/controller/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const { checkForUpdate } = require('./checkForUpdate');
1+
const { checkForUpdate, showDialog } = require('./checkForUpdate');
22
const { autoLaunch } = require('./autoLaunch');
33

44
module.exports = {
55
checkForUpdate,
6+
showDialog,
67
autoLaunch,
78
};

src/module/ApplicationTray.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { app, Tray, Menu, MenuItem, dialog } = require('electron');
22

33
const { getPosition } = require('../utils');
4-
const { checkForUpdate, autoLaunch } = require('../controller');
4+
const { checkForUpdate, showDialog, autoLaunch } = require('../controller');
55

66
class ApplicationTray extends Tray {
77
constructor(iconPath, mainWindow) {
@@ -11,13 +11,12 @@ class ApplicationTray extends Tray {
1111
this.on('right-click', this.onRightClick.bind(this));
1212
this.setToolTip('DevTop');
1313
this.autoStart = false;
14-
this.updateStatus = null;
1514
this.setAutoStart();
1615
this.onUpdate();
1716
}
1817

1918
onUpdate() {
20-
this.updateStatus = checkForUpdate();
19+
checkForUpdate();
2120
}
2221

2322
setAutoStart() {
@@ -87,29 +86,7 @@ class ApplicationTray extends Tray {
8786
new MenuItem({
8887
label: 'Check for Updates',
8988
type: 'checkbox',
90-
click: () => {
91-
const status = this.updateStatus;
92-
const detail = status.updateAvailable
93-
? status.updateAvailable.releaseNotes
94-
: status.details;
95-
const dialogOpts = {
96-
type: 'info',
97-
buttons: [
98-
status.details.releaseNotes ? 'Update' : 'Ok',
99-
'Cancel',
100-
],
101-
title: 'DevTop Essential Update',
102-
message: status.message,
103-
detail,
104-
};
105-
dialog.showMessageBox(dialogOpts, response => {
106-
if (status.details.releaseNotes && response === 0) {
107-
console.log('Update Now');
108-
} else if (response === 0) {
109-
console.log('Okay go out');
110-
}
111-
});
112-
},
89+
click: () => showDialog(),
11390
})
11491
);
11592
menu.append(new MenuItem({ type: 'separator' }));

0 commit comments

Comments
 (0)