Skip to content

Commit 0b3b94a

Browse files
JulianAdams4not-gabriel
authored andcommitted
Windows update & Fix empty events (#368)
* Settings for windows auto-update * Mailbox: Fix get events error. closes #367 * Requested changes
1 parent a6cce89 commit 0b3b94a

File tree

6 files changed

+235
-590
lines changed

6 files changed

+235
-590
lines changed

electron_app/package.json

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"package-linux": "bash ./installerResources/converge_builds.sh && electron-packager . Criptext --overwrite --asar --platform=linux --arch=x64 --icon=resources/launch-icons/icon.png --out=release-builds --no-package-manager",
2727
"package-mac": "sh ./installerResources/converge_builds.sh && electron-packager . Criptext --overwrite --platform=darwin --arch=x64 --icon=./resources/launch-icons/icon.icns --prune=true --out=release-builds",
2828
"package-windows": "bash ./installerResources/converge_builds.sh && electron-packager . Criptext --platform=win32 --arch=x64 --out=release-builds",
29-
"installer-linux": "electron-installer-debian --src ./release-builds/Criptext-linux-x64/ --arch amd64 --config ./installerResources/debian.json",
30-
"installer-mac": "electron-installer-dmg ./release-builds/Criptext-darwin-x64/Criptext.app Criptext --out=release-builds --overwrite",
31-
"installer-windows": "electron-installer-windows --src ./release-builds/Criptext-win32-x64/ --dest ./release-builds/ --config ./installerResources/windows.json",
3229
"pack": "build --dir",
3330
"dist": "electron-builder --publish onTag",
3431
"clear-build": "bash ./installerResources/clearBuild.sh",
@@ -46,13 +43,25 @@
4643
"category": "public.app-category.productivity",
4744
"identity": "Criptext Inc.",
4845
"provisioningProfile": "build/Criptext_Mail_Distribution.provisionprofile",
49-
"type": "distribution"
46+
"type": "distribution",
47+
"publish": [
48+
{
49+
"provider": "generic",
50+
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
51+
}
52+
]
5053
},
5154
"mas": {
5255
"category": "public.app-category.productivity",
5356
"identity": "Criptext Inc.",
5457
"provisioningProfile": "build/Criptext_Mail_Distribution.provisionprofile",
55-
"type": "distribution"
58+
"type": "distribution",
59+
"publish": [
60+
{
61+
"provider": "generic",
62+
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
63+
}
64+
]
5665
},
5766
"pkg": {
5867
"identity": "Criptext Inc.",
@@ -81,31 +90,36 @@
8190
"deb"
8291
],
8392
"icon": "build/icon.png",
84-
"category": "Network"
93+
"category": "Network",
94+
"artifactName": "${productName}-${version}.${ext}",
95+
"publish": [
96+
{
97+
"provider": "generic",
98+
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/linux"
99+
}
100+
]
85101
},
86102
"win": {
87103
"target": "nsis",
88-
"icon": "build/icon.ico"
104+
"icon": "build/icon.ico",
105+
"publish": [
106+
{
107+
"provider": "generic",
108+
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/windows"
109+
}
110+
]
89111
},
90112
"nsis": {
91113
"oneClick": true,
92-
"installerIcon": "build/icon.ico",
93-
"deleteAppDataOnUninstall": true
94-
},
95-
"publish": [
96-
{
97-
"provider": "generic",
98-
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
99-
}
100-
]
114+
"menuCategory": true,
115+
"deleteAppDataOnUninstall": true,
116+
"artifactName": "${productName}-${version}.${ext}"
117+
}
101118
},
102119
"devDependencies": {
103120
"criptext-js-tools": "0.5.0",
104121
"electron": "^1.7.10",
105122
"electron-builder": "^20.18.0",
106-
"electron-installer-debian": "^0.8.0",
107-
"electron-installer-dmg": "^0.2.1",
108-
"electron-installer-windows": "^1.1.0",
109123
"electron-packager": "^10.1.2"
110124
},
111125
"dependencies": {
@@ -114,8 +128,9 @@
114128
"electron-updater": "^3.0.3",
115129
"electron-window-state": "^4.1.1",
116130
"knex": "^0.14.2",
131+
"node-notifier": "^5.2.1",
117132
"opn": "^5.3.0",
118-
"sqlite3": "^3.1.13",
133+
"sqlite3": "^4.0.2",
119134
"websocket": "^1.0.25"
120135
}
121136
}

electron_app/src/clientManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class ClientManager {
4343
}
4444

4545
async getEvents() {
46-
this.check();
47-
const res = await client.getPendingEvents();
48-
return this.formEvents(res.body);
46+
await this.check();
47+
const { status, body } = await client.getPendingEvents();
48+
return status === 204 ? [] : this.formEvents(body);
4949
}
5050

5151
formEvents(events) {

electron_app/src/updater.js

Lines changed: 102 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,128 @@
11
const { dialog } = require('electron');
22
const { autoUpdater } = require('electron-updater');
3+
const notifier = require('node-notifier');
4+
const path = require('path');
5+
const appId = 'com.criptext.criptextmail';
36

4-
const appUpdater = () => {
5-
autoUpdater.checkForUpdatesAndNotify();
7+
let currentUpdaterType;
8+
let isDownloadingUpdate = false;
9+
const updaterTypes = {
10+
AUTO: 'auto',
11+
MANUAL: 'manual',
12+
NONE: 'none'
13+
};
14+
const iconPath = path.join(__dirname, './../resources/launch-icons/icon.png');
15+
autoUpdater.autoDownload = false;
616

7-
autoUpdater.on('error', error => {
8-
dialog.showErrorBox(
9-
'Error: ',
10-
error == null ? 'unknown' : (error.stack || error).toString()
11-
);
12-
});
17+
autoUpdater.on('error', error => {
18+
const errorMessage = process.env.DEBUG
19+
? error == null
20+
? 'unknown'
21+
: (error.stack || error).toString()
22+
: 'An error occurred while downloading the update. Try again later.';
23+
dialog.showErrorBox('Error: ', errorMessage);
24+
currentUpdaterType = updaterTypes.NONE;
25+
isDownloadingUpdate = false;
26+
});
1327

14-
autoUpdater.on('update-not-available', () => {
28+
autoUpdater.on('update-not-available', () => {
29+
if (currentUpdaterType === updaterTypes.MANUAL) {
1530
dialog.showMessageBox({
1631
title: 'No Updates',
17-
message: 'Current version is up-to-date.'
32+
message: 'Current version is up-to-date.',
33+
buttons: ['Ok']
1834
});
19-
});
35+
}
36+
currentUpdaterType = updaterTypes.NONE;
37+
});
2038

21-
autoUpdater.on('update-available', () => {
39+
autoUpdater.on('update-available', () => {
40+
if (currentUpdaterType === updaterTypes.MANUAL) {
2241
dialog.showMessageBox(
2342
{
2443
type: 'info',
25-
title: 'Found Updates',
26-
message: 'Found updates, do you want update now?',
27-
buttons: ['Sure', 'No']
44+
title: 'Update found',
45+
message:
46+
'A new version of Criptext is available. Do you want download it now?',
47+
buttons: ['Sure', 'No'],
48+
noLink: true
2849
},
2950
buttonIndex => {
3051
if (buttonIndex === 0) {
3152
autoUpdater.downloadUpdate();
53+
isDownloadingUpdate = true;
3254
}
3355
}
3456
);
35-
});
57+
}
58+
if (currentUpdaterType === updaterTypes.AUTO) {
59+
const title = 'A new version of Criptext is available!';
60+
const message = 'Click here to download or dismiss to update later';
61+
const notifyOptions = {
62+
appName: appId,
63+
title,
64+
message,
65+
icon: iconPath,
66+
timeout: 15,
67+
wait: true
68+
};
69+
notifier.notify(notifyOptions);
3670

37-
autoUpdater.on('update-downloaded', () => {
38-
dialog.showMessageBox(
39-
{
40-
title: 'Install Updates',
41-
message: 'Updates downloaded, application will be quit for update...'
42-
},
43-
() => {
44-
setImmediate(() => autoUpdater.quitAndInstall());
45-
}
46-
);
47-
});
71+
notifier.on('click', () => {
72+
const downloadingNotifyOptions = {
73+
appName: appId,
74+
title: 'Downloading update',
75+
message: "When it's ready we will notify you",
76+
icon: iconPath
77+
};
78+
notifier.notify(downloadingNotifyOptions);
79+
autoUpdater.downloadUpdate();
80+
isDownloadingUpdate = true;
81+
});
82+
}
83+
});
84+
85+
autoUpdater.on('download-progress', data => {
86+
const { bytesPerSecond, percent, transferred, total } = data;
87+
const downloadStatus = `Downloading: ${percent}% - [${transferred}/${total}] - (${bytesPerSecond} b/s)`;
88+
if (process.env.DEBUG) {
89+
// To do
90+
console.log(downloadStatus);
91+
}
92+
});
93+
94+
autoUpdater.on('update-downloaded', () => {
95+
dialog.showMessageBox(
96+
{
97+
title: 'Install Update',
98+
message:
99+
'Update downloaded, application will be quit for install update...',
100+
buttons: ['Ok']
101+
},
102+
() => {
103+
currentUpdaterType = updaterTypes.NONE;
104+
isDownloadingUpdate = false;
105+
setImmediate(() => autoUpdater.quitAndInstall());
106+
}
107+
);
108+
});
109+
110+
const appUpdater = () => {
111+
currentUpdaterType = updaterTypes.AUTO;
112+
autoUpdater.checkForUpdates();
48113
};
49114

50115
const checkForUpdates = () => {
51-
autoUpdater.checkForUpdates();
116+
if (!isDownloadingUpdate) {
117+
currentUpdaterType = updaterTypes.MANUAL;
118+
autoUpdater.checkForUpdates();
119+
} else {
120+
dialog.showMessageBox({
121+
title: 'Downloading update',
122+
message: 'An update is currently being downloaded',
123+
buttons: ['Ok']
124+
});
125+
}
52126
};
53127

54128
module.exports = {

electron_app/src/windows/menu.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ if (process.platform === 'darwin') {
143143
role: 'front'
144144
}
145145
);
146+
} else {
147+
// File menu.
148+
template[0].submenu.push(
149+
{
150+
type: 'separator'
151+
},
152+
{
153+
label: 'Check for Updates...',
154+
click: checkForUpdates
155+
},
156+
{
157+
type: 'separator'
158+
},
159+
{
160+
label: 'Quit',
161+
accelerator: 'Alt+F4',
162+
click: function() {
163+
quit();
164+
}
165+
}
166+
);
146167
}
147168

148169
module.exports = {

0 commit comments

Comments
 (0)