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
55 changes: 35 additions & 20 deletions electron_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"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",
"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",
"package-windows": "bash ./installerResources/converge_builds.sh && electron-packager . Criptext --platform=win32 --arch=x64 --out=release-builds",
"installer-linux": "electron-installer-debian --src ./release-builds/Criptext-linux-x64/ --arch amd64 --config ./installerResources/debian.json",
"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": "electron-builder --publish onTag",
"clear-build": "bash ./installerResources/clearBuild.sh",
Expand All @@ -46,13 +43,25 @@
"category": "public.app-category.productivity",
"identity": "Criptext Inc.",
"provisioningProfile": "build/Criptext_Mail_Distribution.provisionprofile",
"type": "distribution"
"type": "distribution",
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
}
]
},
"mas": {
"category": "public.app-category.productivity",
"identity": "Criptext Inc.",
"provisioningProfile": "build/Criptext_Mail_Distribution.provisionprofile",
"type": "distribution"
"type": "distribution",
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
}
]
},
"pkg": {
"identity": "Criptext Inc.",
Expand Down Expand Up @@ -81,31 +90,36 @@
"deb"
],
"icon": "build/icon.png",
"category": "Network"
"category": "Network",
"artifactName": "${productName}-${version}.${ext}",
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/linux"
}
]
},
"win": {
"target": "nsis",
"icon": "build/icon.ico"
"icon": "build/icon.ico",
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/windows"
}
]
},
"nsis": {
"oneClick": true,
"installerIcon": "build/icon.ico",
"deleteAppDataOnUninstall": true
},
"publish": [
{
"provider": "generic",
"url": "https://cdn.criptext.com/Criptext-Email-Desktop/mac"
}
]
"menuCategory": true,
"deleteAppDataOnUninstall": true,
"artifactName": "${productName}-${version}.${ext}"
}
},
"devDependencies": {
"criptext-js-tools": "0.5.0",
"electron": "^1.7.10",
"electron-builder": "^20.18.0",
"electron-installer-debian": "^0.8.0",
"electron-installer-dmg": "^0.2.1",
"electron-installer-windows": "^1.1.0",
"electron-packager": "^10.1.2"
},
"dependencies": {
Expand All @@ -114,8 +128,9 @@
"electron-updater": "^3.0.3",
"electron-window-state": "^4.1.1",
"knex": "^0.14.2",
"node-notifier": "^5.2.1",
"opn": "^5.3.0",
"sqlite3": "^3.1.13",
"sqlite3": "^4.0.2",
"websocket": "^1.0.25"
}
}
6 changes: 3 additions & 3 deletions electron_app/src/clientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class ClientManager {
}

async getEvents() {
this.check();
const res = await client.getPendingEvents();
return this.formEvents(res.body);
await this.check();
const { status, body } = await client.getPendingEvents();
return status === 204 ? [] : this.formEvents(body);
}

formEvents(events) {
Expand Down
130 changes: 102 additions & 28 deletions electron_app/src/updater.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,128 @@
const { dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const notifier = require('node-notifier');
const path = require('path');
const appId = 'com.criptext.criptextmail';

const appUpdater = () => {
autoUpdater.checkForUpdatesAndNotify();
let currentUpdaterType;
let isDownloadingUpdate = false;
const updaterTypes = {
AUTO: 'auto',
MANUAL: 'manual',
NONE: 'none'
};
const iconPath = path.join(__dirname, './../resources/launch-icons/icon.png');
autoUpdater.autoDownload = false;

autoUpdater.on('error', error => {
dialog.showErrorBox(
'Error: ',
error == null ? 'unknown' : (error.stack || error).toString()
);
});
autoUpdater.on('error', error => {
const errorMessage = process.env.DEBUG
? error == null
? 'unknown'
: (error.stack || error).toString()
: 'An error occurred while downloading the update. Try again later.';
dialog.showErrorBox('Error: ', errorMessage);
currentUpdaterType = updaterTypes.NONE;
isDownloadingUpdate = false;
});

autoUpdater.on('update-not-available', () => {
autoUpdater.on('update-not-available', () => {
if (currentUpdaterType === updaterTypes.MANUAL) {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
message: 'Current version is up-to-date.',
buttons: ['Ok']
});
});
}
currentUpdaterType = updaterTypes.NONE;
});

autoUpdater.on('update-available', () => {
autoUpdater.on('update-available', () => {
if (currentUpdaterType === updaterTypes.MANUAL) {
dialog.showMessageBox(
{
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
title: 'Update found',
message:
'A new version of Criptext is available. Do you want download it now?',
buttons: ['Sure', 'No'],
noLink: true
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
isDownloadingUpdate = true;
}
}
);
});
}
if (currentUpdaterType === updaterTypes.AUTO) {
const title = 'A new version of Criptext is available!';
const message = 'Click here to download or dismiss to update later';
const notifyOptions = {
appName: appId,
title,
message,
icon: iconPath,
timeout: 15,
wait: true
};
notifier.notify(notifyOptions);

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox(
{
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
},
() => {
setImmediate(() => autoUpdater.quitAndInstall());
}
);
});
notifier.on('click', () => {
const downloadingNotifyOptions = {
appName: appId,
title: 'Downloading update',
message: "When it's ready we will notify you",
icon: iconPath
};
notifier.notify(downloadingNotifyOptions);
autoUpdater.downloadUpdate();
isDownloadingUpdate = true;
});
}
});

autoUpdater.on('download-progress', data => {
const { bytesPerSecond, percent, transferred, total } = data;
const downloadStatus = `Downloading: ${percent}% - [${transferred}/${total}] - (${bytesPerSecond} b/s)`;
if (process.env.DEBUG) {
// To do
console.log(downloadStatus);
}
});

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox(
{
title: 'Install Update',
message:
'Update downloaded, application will be quit for install update...',
buttons: ['Ok']
},
() => {
currentUpdaterType = updaterTypes.NONE;
isDownloadingUpdate = false;
setImmediate(() => autoUpdater.quitAndInstall());
}
);
});

const appUpdater = () => {
currentUpdaterType = updaterTypes.AUTO;
autoUpdater.checkForUpdates();
};

const checkForUpdates = () => {
autoUpdater.checkForUpdates();
if (!isDownloadingUpdate) {
currentUpdaterType = updaterTypes.MANUAL;
autoUpdater.checkForUpdates();
} else {
dialog.showMessageBox({
title: 'Downloading update',
message: 'An update is currently being downloaded',
buttons: ['Ok']
});
}
};

module.exports = {
Expand Down
21 changes: 21 additions & 0 deletions electron_app/src/windows/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ if (process.platform === 'darwin') {
role: 'front'
}
);
} else {
// File menu.
template[0].submenu.push(
{
type: 'separator'
},
{
label: 'Check for Updates...',
click: checkForUpdates
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Alt+F4',
click: function() {
quit();
}
}
);
}

module.exports = {
Expand Down
Loading