Skip to content

Commit 89128d4

Browse files
Erika Perugachinot-gabriel
authored andcommitted
Updater (#306)
* Fix copy/paste. Fix #188 * Add Menu and shorcut to add emojie. Close #187 * Update assets * Add updater
1 parent dedc2b5 commit 89128d4

File tree

9 files changed

+264
-41
lines changed

9 files changed

+264
-41
lines changed

electron_app/build/background.png

45 Bytes
Loading

electron_app/build/icon.icns

37.6 KB
Binary file not shown.

electron_app/electron-starter.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
const { app, ipcMain, dialog } = require('electron');
1+
const { app, ipcMain, dialog, Menu } = require('electron');
22
const dbManager = require('./src/DBManager');
33
const myAccount = require('./src/Account');
4-
const wsClient = require('./src/socketClient')
4+
const wsClient = require('./src/socketClient');
55
const globalManager = require('./src/globalManager');
66

77
const loginWindow = require('./src/windows/login');
88
const dialogWindow = require('./src/windows/dialog');
99
const mailboxWindow = require('./src/windows/mailbox');
1010
const loadingWindow = require('./src/windows/loading');
1111
const composerWindowManager = require('./src/windows/composer');
12+
const { template } = require('./src/windows/menu');
1213

1314
async function initApp() {
1415
try {
@@ -102,20 +103,19 @@ async function initApp() {
102103
})
103104
}
104105

105-
106106
// App
107107
app.disableHardwareAcceleration();
108108

109-
app.on('ready', initApp);
109+
app.on('ready', () => {
110+
const menu = Menu.buildFromTemplate(template);
111+
Menu.setApplicationMenu(menu);
112+
initApp();
113+
});
110114

111115
app.on('window-all-closed', () => {
112116
if (process.platform !== 'darwin') {
113117
app.quit();
114118
}
115119
});
116120

117-
app.on('activate', () => {
118-
if (loginWindow === undefined) {
119-
initApp();
120-
}
121-
});
121+
app.on('activate', initApp);

electron_app/package.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
"productName": "Criptext",
1212
"main": "./electron-starter.js",
1313
"description": "Email service encrypted with signal",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/Criptext/Criptext-Email-React-Client.git"
17+
},
1418
"scripts": {
1519
"electron": "electron .",
16-
"set-env": "NODE_ENV=development MAILBOX_URL=http://localhost:3000 DIALOG_URL=http://localhost:3006 LOGIN_URL=http://localhost:3005 LOADING_URL=http://localhost:3003 COMPOSER_URL=http://localhost:3004 REACT_APP_KEYSERVER_URL=http://localhost:8000 REACT_APP_SOCKETSERVER_URL=ws://localhost:3001",
20+
"set-env": "NODE_ENV=development DEBUG=electron-builder MAILBOX_URL=http://localhost:3000 DIALOG_URL=http://localhost:3006 LOGIN_URL=http://localhost:3005 LOADING_URL=http://localhost:3003 COMPOSER_URL=http://localhost:3004 REACT_APP_KEYSERVER_URL=http://localhost:8000 REACT_APP_SOCKETSERVER_URL=ws://localhost:3001",
1721
"start": "npm run set-env electron .",
1822
"postinstall": "install-app-deps",
1923
"test": "criptext-js-tools test",
@@ -26,11 +30,21 @@
2630
"installer-mac": "electron-installer-dmg ./release-builds/Criptext-darwin-x64/Criptext.app Criptext --out=release-builds --overwrite",
2731
"installer-windows": "electron-installer-windows --src ./release-builds/Criptext-win32-x64/ --dest ./release-builds/ --config ./installerResources/windows.json",
2832
"pack": "build --dir",
29-
"dist": "build",
30-
"clear-build": "bash ./installerResources/clearBuild.sh"
33+
"dist": "electron-builder --publish onTag",
34+
"clear-build": "bash ./installerResources/clearBuild.sh",
35+
"release": "build",
36+
"publish": "build --mac --win -p onTag"
3137
},
3238
"build": {
33-
"appId": "com.criptext.criptextmac",
39+
"appId": "com.criptext.criptextmail",
40+
"mac": {
41+
"target": [
42+
"mas",
43+
"dmg",
44+
"zip"
45+
],
46+
"category": "public.app-category.productivity"
47+
},
3448
"dmg": {
3549
"background": "build/background.png",
3650
"icon": "build/volume.icns",
@@ -64,7 +78,13 @@
6478
"oneClick": true,
6579
"installerIcon": "build/icon.ico",
6680
"deleteAppDataOnUninstall": true
67-
}
81+
},
82+
"publish": [
83+
{
84+
"provider": "generic",
85+
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
86+
}
87+
]
6888
},
6989
"devDependencies": {
7090
"criptext-js-tools": "0.5.0",
@@ -78,6 +98,7 @@
7898
"dependencies": {
7999
"@criptext/email-http-client": "^0.11.1",
80100
"crypto-js": "^3.1.9-1",
101+
"electron-updater": "^3.0.3",
81102
"electron-window-state": "^4.1.1",
82103
"knex": "^0.14.2",
83104
"sqlite3": "^3.1.13",

electron_app/src/updater.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const { dialog } = require('electron');
2+
const { autoUpdater } = require('electron-updater');
3+
4+
const appUpdater = () => {
5+
autoUpdater.checkForUpdatesAndNotify();
6+
7+
autoUpdater.on('error', error => {
8+
dialog.showErrorBox(
9+
'Error: ',
10+
error == null ? 'unknown' : (error.stack || error).toString()
11+
);
12+
});
13+
14+
autoUpdater.on('update-not-available', () => {
15+
dialog.showMessageBox({
16+
title: 'No Updates',
17+
message: 'Current version is up-to-date.'
18+
});
19+
});
20+
21+
autoUpdater.on('update-available', () => {
22+
dialog.showMessageBox(
23+
{
24+
type: 'info',
25+
title: 'Found Updates',
26+
message: 'Found updates, do you want update now?',
27+
buttons: ['Sure', 'No']
28+
},
29+
buttonIndex => {
30+
if (buttonIndex === 0) {
31+
autoUpdater.downloadUpdate();
32+
}
33+
}
34+
);
35+
});
36+
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+
});
48+
};
49+
50+
const checkForUpdates = () => {
51+
autoUpdater.checkForUpdates();
52+
};
53+
54+
module.exports = {
55+
checkForUpdates,
56+
appUpdater
57+
};

electron_app/src/windows/composer.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { BrowserWindow, Menu, dialog } = require('electron');
1+
const { BrowserWindow, dialog } = require('electron');
22
const path = require('path');
33
const { composerUrl } = require('./../window_routing');
44
const mailboxWindow = require('./mailbox');
@@ -17,28 +17,6 @@ const iconPath = path.join(
1717
'./../../resources/launch-icons/icon.png'
1818
);
1919

20-
const template = [
21-
{
22-
submenu: [
23-
{ role: 'undo', accelerator: 'CmdOrCtrl+Z', visible: false },
24-
{
25-
role: 'redo',
26-
accelerator: process.platform === 'darwin' ? 'Cmd+Shift+Z' : 'Ctrl+Y',
27-
visible: false
28-
},
29-
{ role: 'cut', accelerator: 'CmdOrCtrl+X', visible: false },
30-
{ role: 'copy', accelerator: 'CmdOrCtrl+C', visible: false },
31-
{ role: 'paste', accelerator: 'CmdOrCtrl+V', visible: false },
32-
{
33-
role: 'pasteandmatchstyle',
34-
accelerator: 'CmdOrCtrl+Shift+V',
35-
visible: false
36-
}
37-
]
38-
}
39-
];
40-
const menu = Menu.buildFromTemplate(template);
41-
4220
const RESPONSES = {
4321
DISCARD: {
4422
index: 0,
@@ -95,7 +73,6 @@ const createComposerWindow = () => {
9573
});
9674
globalManager.composerData.set(window.id, {});
9775
window.loadURL(composerUrl);
98-
window.setMenu(menu);
9976
window.setMenuBarVisibility(false);
10077
window.on('page-title-updated', event => {
10178
event.preventDefault();

electron_app/src/windows/mailbox.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const { BrowserWindow, shell, app } = require('electron');
1+
const { app, BrowserWindow, shell } = require('electron');
22
const windowStateManager = require('electron-window-state');
33
const { mailboxUrl } = require('./../window_routing');
4+
const { appUpdater } = require('./../updater');
45
const path = require('path');
56

67
let mailboxWindow;
@@ -32,7 +33,6 @@ const create = () => {
3233
title: ''
3334
});
3435
mailboxWindow.loadURL(mailboxUrl);
35-
mailboxWindow.setMenu(null);
3636
mailboxWindow.on('page-title-updated', event => {
3737
event.preventDefault();
3838
});
@@ -57,6 +57,12 @@ const create = () => {
5757
}
5858
});
5959
});
60+
mailboxWindow.webContents.once('did-frame-finish-load', () => {
61+
const checkOS = isWindowsOrmacOS();
62+
if (checkOS) {
63+
appUpdater();
64+
}
65+
});
6066
mailboxWindowState.manage(mailboxWindow);
6167
};
6268

@@ -89,6 +95,10 @@ const send = (message, data) => {
8995
mailboxWindow.webContents.send(message, data);
9096
};
9197

98+
const isWindowsOrmacOS = () => {
99+
return process.platform === 'darwin' || process.platform === 'win32';
100+
};
101+
92102
module.exports = {
93103
show,
94104
close,

electron_app/src/windows/menu.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
const { app } = require('electron');
2+
const { checkForUpdates } = require('./../updater');
3+
const composerWindowManager = require('./composer');
4+
5+
const template = [
6+
{
7+
label: 'File',
8+
submenu: [
9+
{
10+
label: 'New Email',
11+
click: function() {
12+
composerWindowManager.openNewComposer();
13+
}
14+
}
15+
]
16+
},
17+
{
18+
label: 'Edit',
19+
submenu: [
20+
{
21+
label: 'Undo',
22+
accelerator: 'CmdOrCtrl+Z',
23+
role: 'undo'
24+
},
25+
{
26+
label: 'Redo',
27+
accelerator: 'Shift+CmdOrCtrl+Z',
28+
role: 'redo'
29+
},
30+
{
31+
type: 'separator'
32+
},
33+
{
34+
label: 'Cut',
35+
accelerator: 'CmdOrCtrl+X',
36+
role: 'cut'
37+
},
38+
{
39+
label: 'Copy',
40+
accelerator: 'CmdOrCtrl+C',
41+
role: 'copy'
42+
},
43+
{
44+
label: 'Paste',
45+
accelerator: 'CmdOrCtrl+V',
46+
role: 'paste'
47+
},
48+
{
49+
label: 'Select All',
50+
accelerator: 'CmdOrCtrl+A',
51+
role: 'selectall'
52+
}
53+
]
54+
},
55+
{
56+
label: 'Window',
57+
role: 'window',
58+
submenu: [
59+
{
60+
label: 'Minimize',
61+
accelerator: 'CmdOrCtrl+M',
62+
role: 'minimize'
63+
},
64+
{
65+
label: 'Close',
66+
accelerator: 'CmdOrCtrl+W',
67+
role: 'close'
68+
}
69+
]
70+
}
71+
];
72+
73+
if (process.platform === 'darwin') {
74+
template.unshift({
75+
label: 'Criptext',
76+
submenu: [
77+
{
78+
label: 'About Criptext',
79+
role: 'about'
80+
},
81+
{
82+
label: 'Check for Updates...',
83+
click: checkForUpdates
84+
},
85+
{
86+
type: 'separator'
87+
},
88+
{
89+
label: 'Services',
90+
role: 'services',
91+
submenu: []
92+
},
93+
{
94+
type: 'separator'
95+
},
96+
{
97+
label: 'Hide Criptext',
98+
accelerator: 'Command+H',
99+
role: 'hide'
100+
},
101+
{
102+
label: 'Hide Others',
103+
accelerator: 'Command+Shift+H',
104+
role: 'hideothers'
105+
},
106+
{
107+
label: 'Show All',
108+
role: 'unhide'
109+
},
110+
{
111+
type: 'separator'
112+
},
113+
{
114+
label: 'Quit',
115+
accelerator: 'Command+Q',
116+
click: function() {
117+
app.quit();
118+
}
119+
}
120+
]
121+
});
122+
// Window menu.
123+
template[2].submenu.push(
124+
{
125+
type: 'separator'
126+
},
127+
{
128+
label: 'Bring All to Front',
129+
role: 'front'
130+
}
131+
);
132+
}
133+
134+
module.exports = {
135+
template
136+
};

0 commit comments

Comments
 (0)