Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified electron_app/build/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified electron_app/build/icon.icns
Binary file not shown.
18 changes: 9 additions & 9 deletions electron_app/electron-starter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const { app, ipcMain, dialog } = require('electron');
const { app, ipcMain, dialog, Menu } = require('electron');
const dbManager = require('./src/DBManager');
const myAccount = require('./src/Account');
const wsClient = require('./src/socketClient')
const wsClient = require('./src/socketClient');
const globalManager = require('./src/globalManager');

const loginWindow = require('./src/windows/login');
const dialogWindow = require('./src/windows/dialog');
const mailboxWindow = require('./src/windows/mailbox');
const loadingWindow = require('./src/windows/loading');
const composerWindowManager = require('./src/windows/composer');
const { template } = require('./src/windows/menu');

async function initApp() {
try {
Expand Down Expand Up @@ -102,20 +103,19 @@ async function initApp() {
})
}


// App
app.disableHardwareAcceleration();

app.on('ready', initApp);
app.on('ready', () => {
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
initApp();
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', () => {
if (loginWindow === undefined) {
initApp();
}
});
app.on('activate', initApp);
31 changes: 26 additions & 5 deletions electron_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"productName": "Criptext",
"main": "./electron-starter.js",
"description": "Email service encrypted with signal",
"repository": {
"type": "git",
"url": "https://github.com/Criptext/Criptext-Email-React-Client.git"
},
"scripts": {
"electron": "electron .",
"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",
"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",
"start": "npm run set-env electron .",
"postinstall": "install-app-deps",
"test": "criptext-js-tools test",
Expand All @@ -26,11 +30,21 @@
"installer-mac": "electron-installer-dmg ./release-builds/Criptext-darwin-x64/Criptext.app Criptext --out=release-builds --overwrite",
"installer-windows": "electron-installer-windows --src ./release-builds/Criptext-win32-x64/ --dest ./release-builds/ --config ./installerResources/windows.json",
"pack": "build --dir",
"dist": "build",
"clear-build": "bash ./installerResources/clearBuild.sh"
"dist": "electron-builder --publish onTag",
"clear-build": "bash ./installerResources/clearBuild.sh",
"release": "build",
"publish": "build --mac --win -p onTag"
},
"build": {
"appId": "com.criptext.criptextmac",
"appId": "com.criptext.criptextmail",
"mac": {
"target": [
"mas",
"dmg",
"zip"
],
"category": "public.app-category.productivity"
},
"dmg": {
"background": "build/background.png",
"icon": "build/volume.icns",
Expand Down Expand Up @@ -64,7 +78,13 @@
"oneClick": true,
"installerIcon": "build/icon.ico",
"deleteAppDataOnUninstall": true
}
},
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
}
]
},
"devDependencies": {
"criptext-js-tools": "0.5.0",
Expand All @@ -78,6 +98,7 @@
"dependencies": {
"@criptext/email-http-client": "^0.11.1",
"crypto-js": "^3.1.9-1",
"electron-updater": "^3.0.3",
"electron-window-state": "^4.1.1",
"knex": "^0.14.2",
"sqlite3": "^3.1.13",
Expand Down
57 changes: 57 additions & 0 deletions electron_app/src/updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { dialog } = require('electron');
const { autoUpdater } = require('electron-updater');

const appUpdater = () => {
autoUpdater.checkForUpdatesAndNotify();

autoUpdater.on('error', error => {
dialog.showErrorBox(
'Error: ',
error == null ? 'unknown' : (error.stack || error).toString()
);
});

autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
});
});

autoUpdater.on('update-available', () => {
dialog.showMessageBox(
{
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
}
}
);
});

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox(
{
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
},
() => {
setImmediate(() => autoUpdater.quitAndInstall());
}
);
});
};

const checkForUpdates = () => {
autoUpdater.checkForUpdates();
};

module.exports = {
checkForUpdates,
appUpdater
};
25 changes: 1 addition & 24 deletions electron_app/src/windows/composer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { BrowserWindow, Menu, dialog } = require('electron');
const { BrowserWindow, dialog } = require('electron');
const path = require('path');
const { composerUrl } = require('./../window_routing');
const mailboxWindow = require('./mailbox');
Expand All @@ -17,28 +17,6 @@ const iconPath = path.join(
'./../../resources/launch-icons/icon.png'
);

const template = [
{
submenu: [
{ role: 'undo', accelerator: 'CmdOrCtrl+Z', visible: false },
{
role: 'redo',
accelerator: process.platform === 'darwin' ? 'Cmd+Shift+Z' : 'Ctrl+Y',
visible: false
},
{ role: 'cut', accelerator: 'CmdOrCtrl+X', visible: false },
{ role: 'copy', accelerator: 'CmdOrCtrl+C', visible: false },
{ role: 'paste', accelerator: 'CmdOrCtrl+V', visible: false },
{
role: 'pasteandmatchstyle',
accelerator: 'CmdOrCtrl+Shift+V',
visible: false
}
]
}
];
const menu = Menu.buildFromTemplate(template);

const RESPONSES = {
DISCARD: {
index: 0,
Expand Down Expand Up @@ -95,7 +73,6 @@ const createComposerWindow = () => {
});
globalManager.composerData.set(window.id, {});
window.loadURL(composerUrl);
window.setMenu(menu);
window.setMenuBarVisibility(false);
window.on('page-title-updated', event => {
event.preventDefault();
Expand Down
14 changes: 12 additions & 2 deletions electron_app/src/windows/mailbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { BrowserWindow, shell, app } = require('electron');
const { app, BrowserWindow, shell } = require('electron');
const windowStateManager = require('electron-window-state');
const { mailboxUrl } = require('./../window_routing');
const { appUpdater } = require('./../updater');
const path = require('path');

let mailboxWindow;
Expand Down Expand Up @@ -32,7 +33,6 @@ const create = () => {
title: ''
});
mailboxWindow.loadURL(mailboxUrl);
mailboxWindow.setMenu(null);
mailboxWindow.on('page-title-updated', event => {
event.preventDefault();
});
Expand All @@ -57,6 +57,12 @@ const create = () => {
}
});
});
mailboxWindow.webContents.once('did-frame-finish-load', () => {
const checkOS = isWindowsOrmacOS();
if (checkOS) {
appUpdater();
}
});
mailboxWindowState.manage(mailboxWindow);
};

Expand Down Expand Up @@ -89,6 +95,10 @@ const send = (message, data) => {
mailboxWindow.webContents.send(message, data);
};

const isWindowsOrmacOS = () => {
return process.platform === 'darwin' || process.platform === 'win32';
};

module.exports = {
show,
close,
Expand Down
136 changes: 136 additions & 0 deletions electron_app/src/windows/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const { app } = require('electron');
const { checkForUpdates } = require('./../updater');
const composerWindowManager = require('./composer');

const template = [
{
label: 'File',
submenu: [
{
label: 'New Email',
click: function() {
composerWindowManager.openNewComposer();
}
}
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo'
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut'
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy'
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste'
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectall'
}
]
},
{
label: 'Window',
role: 'window',
submenu: [
{
label: 'Minimize',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
},
{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
}
]
}
];

if (process.platform === 'darwin') {
template.unshift({
label: 'Criptext',
submenu: [
{
label: 'About Criptext',
role: 'about'
},
{
label: 'Check for Updates...',
click: checkForUpdates
},
{
type: 'separator'
},
{
label: 'Services',
role: 'services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide Criptext',
accelerator: 'Command+H',
role: 'hide'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
role: 'hideothers'
},
{
label: 'Show All',
role: 'unhide'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: function() {
app.quit();
}
}
]
});
// Window menu.
template[2].submenu.push(
{
type: 'separator'
},
{
label: 'Bring All to Front',
role: 'front'
}
);
}

module.exports = {
template
};
Loading