Skip to content
Merged

Fix #1163

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
12 changes: 9 additions & 3 deletions electron_app/electron-starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
isFromStore,
getSystemLanguage
} = require('./src/windows/windowUtils');
const {initNucleus} = require('./src/nucleusManager');
require('./src/ipc/composer.js');
require('./src/ipc/loading.js');
require('./src/ipc/login.js');
Expand All @@ -25,6 +26,7 @@ require('./src/ipc/database.js');
require('./src/ipc/manager.js');
require('./src/ipc/dataTransfer.js');
require('./src/ipc/backup.js');
require('./src/ipc/nucleus.js');
const ipcUtils = require('./src/ipc/utils.js');

globalManager.forcequit.set(false);
Expand All @@ -36,24 +38,27 @@ async function initApp() {
} catch (ex) {
console.log(ex);
}

const [existingAccount] = await dbManager.getAccount();
if (existingAccount) {
if (!!existingAccount.deviceId) {
const appSettings = await dbManager.getSettings();
const settings = Object.assign(appSettings, { isFromStore });
myAccount.initialize(existingAccount);
mySettings.initialize(settings);
initNucleus({language: mySettings.language});
wsClient.start(myAccount);
createAppMenu();
mailboxWindow.show({ firstOpenApp: true });
} else {
await getUserLanguage();
const language = await getUserLanguage();
initNucleus({language});
createAppMenu();
loginWindow.show();
}
} else {
await getUserLanguage();
const language = await getUserLanguage();
initNucleus({language});
createAppMenu();
loginWindow.show({});
}
Expand Down Expand Up @@ -97,6 +102,7 @@ if ((isWindows || isLinux) && !isDev) {
const getUserLanguage = async () => {
const osLanguage = await getSystemLanguage();
await dbManager.updateSettings({ language: osLanguage });
return osLanguage;
};

app.on('ready', () => {
Expand Down
4 changes: 2 additions & 2 deletions electron_app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "criptext",
"version": "0.23.4",
"version": "0.23.5",
"author": {
"name": "Criptext Inc",
"email": "support@criptext.com",
Expand Down Expand Up @@ -141,7 +141,7 @@
"dotenv": "^6.2.0",
"electron-context-menu": "^0.10.1",
"electron-dl": "^1.12.0",
"electron-nucleus": "^2.2.1",
"electron-nucleus": "^2.3.0",
"electron-updater": "^3.0.3",
"electron-window-state": "^4.1.1",
"getos": "^3.1.1",
Expand Down
6 changes: 3 additions & 3 deletions electron_app/src/ipc/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ipc.answerRenderer('close-create-keys-loading', () => {
globalManager.loadingData.set({});
});

ipc.answerRenderer('open-create-keys-loading', arg => {
globalManager.loadingData.set(arg);
loadingWindow.show();
ipc.answerRenderer('open-create-keys-loading', params => {
globalManager.loadingData.set(params);
loadingWindow.show({ type: params.loadingType });
});
6 changes: 6 additions & 0 deletions electron_app/src/ipc/nucleus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ipc = require('@criptext/electron-better-ipc');
const { addEventError, NUCLEUS_EVENTS } = require('./../nucleusManager');

ipc.answerRenderer('nucleups-report-content-unencrypted', error =>
addEventError(NUCLEUS_EVENTS.REPORT_CONTENT_UNENCRYPTED, { error })
);
42 changes: 42 additions & 0 deletions electron_app/src/nucleusManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { APP_VERSION, NUCLEUS_ID } = require('./utils/const');
const myAccount = require('./Account');
let Nucleus;

const initNucleus = ({ userId }) => {
const data = {
onlyMainProcess: true,
userId: userId || 'unknown',
version: APP_VERSION
};
Nucleus = require('electron-nucleus')(NUCLEUS_ID, data);
};

const addEventError = (event, data) => {
Nucleus.trackError(event, data);
};

const addEventTrack = (event, data) => {
Nucleus.track(event, data);
};

const updateUserData = () => {
Nucleus.setUserId(myAccount.recipientId);
};

const NUCLEUS_EVENTS = {
LOGIN_OPENED: 'LOGIN_OPENED',
LOGIN_NEW_USER: 'LOGIN_NEW_USER',
LOGIN_NEW_DEVICE: 'LOGIN_NEW_DEVICE',
LOGIN_NEW_ENTERPRISE: 'LOGIN_NEW_ENTERPRISE',
MAILBOX_OPENED: 'MAILBOX_OPENED',
NEW_USER: 'NEW_USER',
REPORT_CONTENT_UNENCRYPTED: 'REPORT_CONTENT_UNENCRYPTED'
};

module.exports = {
initNucleus,
addEventError,
addEventTrack,
updateUserData,
NUCLEUS_EVENTS
};
2 changes: 2 additions & 0 deletions electron_app/src/socketClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const disconnect = () => {

const start = ({ jwt }) => {
client = new WebSocketClient();
pingFailedCounter = 0;
checkDelay = normalPingDelayMs;
client.connect(
`${SOCKET_URL}?token=${jwt}`,
'criptext-protocol'
Expand Down
14 changes: 8 additions & 6 deletions electron_app/src/windows/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ const destroy = async ({
const { type, key } = emailToEdit;
if (type === composerEvents.EDIT_DRAFT) {
const [oldDraftEmail] = await dbManager.getEmailByKey(key);
const oldEmailId = oldDraftEmail.id;
await dbManager.deleteEmailLabelAndContactByEmailId(
oldEmailId,
undefined
);
if (oldDraftEmail) {
const oldEmailId = oldDraftEmail.id;
await dbManager.deleteEmailLabelAndContactByEmailId(
oldEmailId,
undefined
);
}
event = 'composer-email-delete';
params = { threadId, oldEmailId };
params = { threadId };
} else if (
type === composerEvents.REPLY ||
type === composerEvents.REPLY_ALL
Expand Down
30 changes: 28 additions & 2 deletions electron_app/src/windows/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const { BrowserWindow } = require('electron');
const path = require('path');
const { loadingUrl } = require('./../window_routing');
const globalManager = require('./../globalManager');
const {
updateUserData,
addEventTrack,
NUCLEUS_EVENTS
} = require('./../nucleusManager');
let loadingWindow;

const LINK_DEVICE_LOADING_TYPES = {
Expand All @@ -23,7 +28,6 @@ const create = () => {
show: false,
frame: false,
transparent: true,
alwaysOnTop: true,
center: true
});
loadingWindow.loadURL(loadingUrl);
Expand Down Expand Up @@ -53,6 +57,7 @@ const create = () => {
};

const close = () => {
updateUserData();
if (loadingWindow) {
loadingWindow.close();
}
Expand All @@ -66,15 +71,36 @@ const send = (message, data) => {
loadingWindow.webContents.send(message, data);
};

const show = async () => {
const show = async ({ type }) => {
if (!loadingWindow) {
await create();
}
loadingWindow.once('ready-to-show', () => {
loadingWindow.show();
sendTrack(type);
});
};

const sendTrack = type => {
let event;
switch (type) {
case 'signin-new-password':
event = NUCLEUS_EVENTS.LOGIN_NEW_ENTERPRISE;
break;
case 'signup':
event = NUCLEUS_EVENTS.LOGIN_NEW_USER;
break;
case 'signin':
case 'link-new-device':
event = NUCLEUS_EVENTS.LOGIN_NEW_DEVICE;
break;
default:
event = '';
break;
}
addEventTrack(event);
};

module.exports = {
close,
send,
Expand Down
5 changes: 4 additions & 1 deletion electron_app/src/windows/login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { BrowserWindow, shell } = require('electron');
const path = require('path');
const { loginUrl } = require('./../window_routing');
const globalManager = require('./../globalManager');
const path = require('path');
const { addEventTrack, NUCLEUS_EVENTS } = require('./../nucleusManager');
let loginWindow;

const loginSize = {
Expand Down Expand Up @@ -52,10 +53,12 @@ const create = () => {
const show = async () => {
if (loginWindow) {
loginWindow.show();
addEventTrack(NUCLEUS_EVENTS.LOGIN_OPENED);
} else {
await create();
loginWindow.once('ready-to-show', () => {
loginWindow.show();
addEventTrack(NUCLEUS_EVENTS.LOGIN_OPENED);
});
}
};
Expand Down
22 changes: 15 additions & 7 deletions electron_app/src/windows/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const { appUpdater } = require('./../updater');
const globalManager = require('./../globalManager');
const { mailtoProtocolRegex } = require('./../utils/RegexUtils');
const { removeProtocolFromUrl } = require('./../utils/stringUtils');
const { isFromStore, isDev } = require('./windowUtils');
const {
isFromStore,
isDev,
nucleusTrack,
updateUserData,
addEventTrack,
NUCLEUS_EVENTS
} = require('./windowUtils');
} = require('./../nucleusManager');
const { createTrayIcon, destroyTrayIcon } = require('./tray');
const { isWindows } = require('./../utils/osUtils');

Expand Down Expand Up @@ -101,17 +101,25 @@ const show = async ({ firstOpenApp = false }) => {
if (mailboxWindow) {
mailboxWindow.show();
createTrayIcon();
if (firstOpenApp) nucleusTrack(NUCLEUS_EVENTS.MAILBOX_TRACK);
if (firstOpenApp) {
updateUserData();
addEventTrack(NUCLEUS_EVENTS.MAILBOX_OPENED);
}
} else if (!existVisibleWindow.length || !mailboxWindow) {
await create();
mailboxWindow.on('ready-to-show', () => {
mailboxWindow.show();
createTrayIcon();
if (firstOpenApp) nucleusTrack(NUCLEUS_EVENTS.MAILBOX_TRACK);
if (firstOpenApp) {
updateUserData();
addEventTrack(NUCLEUS_EVENTS.MAILBOX_OPENED);
}
});
mailboxWindow.on('focus', () => {
if (!globalManager.windowsEvents.checkDisabled()) {
ipc.callRenderer(mailboxWindow, 'get-events');
if (mailboxWindow) {
ipc.callRenderer(mailboxWindow, 'get-events');
}
}
});
}
Expand Down
24 changes: 1 addition & 23 deletions electron_app/src/windows/windowUtils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const { app, BrowserWindow } = require('electron');
const osLocale = require('os-locale');
const globalManager = require('./../globalManager');
const myAccount = require('./../Account');
const mySettings = require('./../Settings');
const { APP_VERSION, NUCLEUS_ID } = require('./../utils/const');

const showWindows = () => {
const visibleWindows = BrowserWindow.getAllWindows();
Expand Down Expand Up @@ -42,23 +39,6 @@ const sendEventToAllWindows = (eventName, params) => {
});
};

const getNucleusPayload = () => ({
onlyMainProcess: true,
userId: myAccount.recipientId,
version: APP_VERSION,
language: mySettings.language
});

const nucleusTrack = eventName => {
const data = getNucleusPayload();
const Nucleus = require('electron-nucleus')(NUCLEUS_ID, data);
Nucleus.track(eventName);
};

const NUCLEUS_EVENTS = {
MAILBOX_TRACK: 'MAILBOX_TRACK'
};

module.exports = {
quit,
isDev,
Expand All @@ -68,7 +48,5 @@ module.exports = {
isFromStore,
showWindows,
getSystemLanguage,
sendEventToAllWindows,
NUCLEUS_EVENTS,
nucleusTrack
sendEventToAllWindows
};
8 changes: 4 additions & 4 deletions electron_app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,10 @@ electron-is-dev@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.0.1.tgz#6e0a184736fe7aea77d18210b0b0f6a02402c4bc"

electron-nucleus@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/electron-nucleus/-/electron-nucleus-2.2.1.tgz#c747dc1beb2af5251b33cd21f64e962a8c908821"
integrity sha512-Jglvm3dB4cFBIjZ6fLlPtX2xDpabeJhnOhbBFdCEIF3b14P2o68rRGj3+07r6V6uoovPz2vJwXizALPAySzVjg==
electron-nucleus@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/electron-nucleus/-/electron-nucleus-2.3.0.tgz#f8a81f4326dcfc43001f21aa5281fe63042308e4"
integrity sha512-lv10mhhhkScwsjLGca1706rYy4Lj6bljNa7p2qNVVvJrrAavDPsGwco/53b1eEwisEv9E0hCCWuuX/2rN38g1g==
dependencies:
electron-store "^4.0.0"
node-machine-id "^1.1.12"
Expand Down
2 changes: 1 addition & 1 deletion email_composer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_composer",
"version": "0.23.4",
"version": "0.23.5",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.1.2-rc5",
Expand Down
2 changes: 1 addition & 1 deletion email_loading/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_loading",
"version": "0.23.4",
"version": "0.23.5",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.1.2-rc5",
Expand Down
2 changes: 1 addition & 1 deletion email_login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_login",
"version": "0.23.4",
"version": "0.23.5",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.1.2-rc5",
Expand Down
2 changes: 1 addition & 1 deletion email_mailbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_mailbox",
"version": "0.23.4",
"version": "0.23.5",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.1.2-rc5",
Expand Down
Loading