2020-03-25 01:42:53 +01:00
|
|
|
/* eslint-disable global-require */
|
2018-04-03 21:03:57 +02:00
|
|
|
/* global Whisper: false */
|
|
|
|
/* global window: false */
|
2018-12-13 06:33:54 +01:00
|
|
|
const path = require('path');
|
2021-10-04 01:56:54 +02:00
|
|
|
const { webFrame, remote, clipboard, ipcRenderer } = require('electron');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2021-10-04 01:56:54 +02:00
|
|
|
const { app } = remote;
|
2022-03-03 07:14:59 +01:00
|
|
|
const url = require('url');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2022-03-03 07:14:59 +01:00
|
|
|
const config = url.parse(window.location.toString(), true).query;
|
2018-06-02 02:55:35 +02:00
|
|
|
|
|
|
|
let title = config.name;
|
|
|
|
if (config.environment !== 'production') {
|
|
|
|
title += ` - ${config.environment}`;
|
|
|
|
}
|
|
|
|
if (config.appInstance) {
|
|
|
|
title += ` - ${config.appInstance}`;
|
|
|
|
}
|
|
|
|
|
2020-06-18 02:46:52 +02:00
|
|
|
global.dcodeIO = global.dcodeIO || {};
|
|
|
|
global.dcodeIO.ByteBuffer = require('bytebuffer');
|
|
|
|
|
2019-03-18 20:10:56 +01:00
|
|
|
window.platform = process.platform;
|
2018-06-02 02:55:35 +02:00
|
|
|
window.getTitle = () => title;
|
|
|
|
window.getEnvironment = () => config.environment;
|
2018-06-21 21:02:19 +02:00
|
|
|
window.getAppInstance = () => config.appInstance;
|
2018-06-02 02:55:35 +02:00
|
|
|
window.getVersion = () => config.version;
|
2021-07-06 06:01:02 +02:00
|
|
|
window.isDev = () => config.environment === 'development';
|
2019-03-01 07:10:20 +01:00
|
|
|
window.getCommitHash = () => config.commitHash;
|
2018-06-02 02:55:35 +02:00
|
|
|
window.getNodeVersion = () => config.node_version;
|
2021-04-15 10:14:04 +02:00
|
|
|
|
2022-02-18 03:03:47 +01:00
|
|
|
window.sessionFeatureFlags = {
|
2021-01-29 01:29:24 +01:00
|
|
|
useOnionRequests: true,
|
2022-03-22 01:18:01 +01:00
|
|
|
useCallMessage: true,
|
2018-07-20 23:52:52 +02:00
|
|
|
};
|
|
|
|
|
2020-01-22 05:57:58 +01:00
|
|
|
window.versionInfo = {
|
|
|
|
environment: window.getEnvironment(),
|
|
|
|
version: window.getVersion(),
|
|
|
|
commitHash: window.getCommitHash(),
|
|
|
|
appInstance: window.getAppInstance(),
|
|
|
|
};
|
|
|
|
|
2021-10-04 01:56:54 +02:00
|
|
|
const ipc = ipcRenderer;
|
2018-06-02 02:55:35 +02:00
|
|
|
const localeMessages = ipc.sendSync('locale-data');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2020-02-26 03:30:56 +01:00
|
|
|
window.updateZoomFactor = () => {
|
|
|
|
const zoomFactor = window.getSettingValue('zoom-factor-setting') || 100;
|
|
|
|
window.setZoomFactor(zoomFactor / 100);
|
2020-02-26 05:08:41 +01:00
|
|
|
};
|
2020-02-20 07:15:39 +01:00
|
|
|
|
2020-02-26 03:30:56 +01:00
|
|
|
window.setZoomFactor = number => {
|
|
|
|
webFrame.setZoomFactor(number);
|
|
|
|
};
|
2020-02-20 04:46:54 +01:00
|
|
|
|
2018-12-06 01:33:11 +01:00
|
|
|
// Set the password for the database
|
2019-01-16 05:44:13 +01:00
|
|
|
window.setPassword = (passPhrase, oldPhrase) =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('set-password-response', (event, error) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(error);
|
|
|
|
}
|
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
ipc.send('set-password', passPhrase, oldPhrase);
|
2018-12-06 01:33:11 +01:00
|
|
|
});
|
|
|
|
|
2021-08-10 03:57:27 +02:00
|
|
|
window.setStartInTray = startInTray =>
|
|
|
|
new Promise((resolve, reject) => {
|
2021-08-13 07:44:32 +02:00
|
|
|
ipc.once('start-in-tray-on-start-response', (_event, error) => {
|
2021-08-10 03:57:27 +02:00
|
|
|
if (error) {
|
|
|
|
return reject(error);
|
|
|
|
}
|
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
ipc.send('start-in-tray-on-start', startInTray);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.getStartInTray = () =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
ipc.once('get-start-in-tray-response', (event, value) => resolve(value));
|
|
|
|
ipc.send('get-start-in-tray');
|
|
|
|
});
|
|
|
|
|
2021-01-22 06:29:02 +01:00
|
|
|
window.libsession = require('./ts/session');
|
2022-01-18 05:21:36 +01:00
|
|
|
window._ = require('lodash');
|
2021-01-22 06:29:02 +01:00
|
|
|
|
2021-06-24 07:10:38 +02:00
|
|
|
window.getConversationController = window.libsession.Conversations.getConversationController;
|
2021-01-06 04:05:13 +01:00
|
|
|
|
2018-05-24 18:32:18 +02:00
|
|
|
// We never do these in our code, so we'll prevent it everywhere
|
2018-05-19 03:21:02 +02:00
|
|
|
window.open = () => null;
|
2018-05-24 18:32:18 +02:00
|
|
|
// eslint-disable-next-line no-eval, no-multi-assign
|
|
|
|
window.eval = global.eval = () => null;
|
2018-05-19 03:21:02 +02:00
|
|
|
|
2018-04-03 21:03:57 +02:00
|
|
|
window.drawAttention = () => {
|
2021-05-24 08:03:52 +02:00
|
|
|
// window.log.debug('draw attention');
|
2018-04-03 21:03:57 +02:00
|
|
|
ipc.send('draw-attention');
|
|
|
|
};
|
|
|
|
window.showWindow = () => {
|
2021-05-24 08:03:52 +02:00
|
|
|
window.log.info('show window');
|
2018-04-03 21:03:57 +02:00
|
|
|
ipc.send('show-window');
|
|
|
|
};
|
|
|
|
|
2021-04-22 10:03:58 +02:00
|
|
|
window.setAutoHideMenuBar = autoHide => ipc.send('set-auto-hide-menu-bar', autoHide);
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2021-04-22 10:03:58 +02:00
|
|
|
window.setMenuBarVisibility = visibility => ipc.send('set-menu-bar-visibility', visibility);
|
2018-04-03 21:03:57 +02:00
|
|
|
|
|
|
|
window.restart = () => {
|
2021-05-24 08:03:52 +02:00
|
|
|
window.log.info('restart');
|
2018-04-03 21:03:57 +02:00
|
|
|
ipc.send('restart');
|
|
|
|
};
|
|
|
|
|
2018-04-27 23:25:04 +02:00
|
|
|
window.closeAbout = () => ipc.send('close-about');
|
2019-03-28 18:09:26 +01:00
|
|
|
window.readyForUpdates = () => ipc.send('ready-for-updates');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2020-03-31 03:07:03 +02:00
|
|
|
ipc.on('get-theme-setting', () => {
|
|
|
|
const theme = window.Events.getThemeSetting();
|
|
|
|
ipc.send('get-success-theme-setting', theme);
|
|
|
|
});
|
|
|
|
|
2020-02-27 23:49:03 +01:00
|
|
|
window.getSettingValue = (settingID, comparisonValue = null) => {
|
|
|
|
// Comparison value allows you to pull boolean values from any type.
|
|
|
|
// Eg. window.getSettingValue('theme', 'light')
|
|
|
|
// returns 'false' when the value is 'dark'.
|
|
|
|
|
2020-03-09 23:55:29 +01:00
|
|
|
// We need to get specific settings from the main process
|
2020-02-27 23:49:03 +01:00
|
|
|
if (settingID === 'media-permissions') {
|
2020-03-10 00:49:07 +01:00
|
|
|
return window.getMediaPermissions();
|
2021-10-21 04:18:50 +02:00
|
|
|
} else if (settingID === 'call-media-permissions') {
|
|
|
|
return window.getCallMediaPermissions();
|
2020-03-09 23:55:29 +01:00
|
|
|
} else if (settingID === 'auto-update') {
|
|
|
|
return window.getAutoUpdateEnabled();
|
2020-02-27 23:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const settingVal = window.storage.get(settingID);
|
|
|
|
return comparisonValue ? !!settingVal === comparisonValue : settingVal;
|
|
|
|
};
|
|
|
|
|
|
|
|
window.setSettingValue = (settingID, value) => {
|
2020-03-09 23:55:29 +01:00
|
|
|
// For auto updating we need to pass the value to the main process
|
|
|
|
if (settingID === 'auto-update') {
|
|
|
|
window.setAutoUpdateEnabled(value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-27 23:49:03 +01:00
|
|
|
window.storage.put(settingID, value);
|
2020-01-15 03:49:07 +01:00
|
|
|
};
|
2020-01-14 03:28:31 +01:00
|
|
|
|
2020-03-10 01:05:26 +01:00
|
|
|
window.getMediaPermissions = () => ipc.sendSync('get-media-permissions');
|
2021-04-22 10:03:58 +02:00
|
|
|
window.setMediaPermissions = value => ipc.send('set-media-permissions', !!value);
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2021-10-21 04:18:50 +02:00
|
|
|
window.getCallMediaPermissions = () => ipc.sendSync('get-call-media-permissions');
|
|
|
|
window.setCallMediaPermissions = value => ipc.send('set-call-media-permissions', !!value);
|
|
|
|
|
2021-07-30 08:44:01 +02:00
|
|
|
window.askForMediaAccess = () => ipc.send('media-access');
|
2021-07-30 08:31:35 +02:00
|
|
|
|
2020-03-09 23:55:29 +01:00
|
|
|
// Auto update setting
|
2020-03-10 04:58:44 +01:00
|
|
|
window.getAutoUpdateEnabled = () => ipc.sendSync('get-auto-update-setting');
|
2021-04-22 10:03:58 +02:00
|
|
|
window.setAutoUpdateEnabled = value => ipc.send('set-auto-update-setting', !!value);
|
2020-03-09 23:55:29 +01:00
|
|
|
|
2018-11-05 20:06:12 +01:00
|
|
|
ipc.on('get-ready-for-shutdown', async () => {
|
2018-11-28 01:20:48 +01:00
|
|
|
const { shutdown } = window.Events || {};
|
2018-11-05 20:06:12 +01:00
|
|
|
if (!shutdown) {
|
2021-05-24 08:03:52 +02:00
|
|
|
window.log.error('preload shutdown handler: shutdown method not found');
|
2018-11-05 20:06:12 +01:00
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await shutdown();
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
} catch (error) {
|
2021-04-22 10:03:58 +02:00
|
|
|
ipc.send('now-ready-for-shutdown', error && error.stack ? error.stack : error);
|
2018-11-05 20:06:12 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-03 21:03:57 +02:00
|
|
|
// We pull these dependencies in now, from here, because they have Node.js dependencies
|
|
|
|
|
2022-03-23 06:35:29 +01:00
|
|
|
require('./ts/util/logging');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2018-06-02 02:55:35 +02:00
|
|
|
if (config.proxyUrl) {
|
2021-05-24 08:03:52 +02:00
|
|
|
window.log.info('Using provided proxy url');
|
2018-04-03 21:03:57 +02:00
|
|
|
}
|
|
|
|
window.nodeSetImmediate = setImmediate;
|
2018-05-26 03:01:56 +02:00
|
|
|
|
2021-01-29 01:29:24 +01:00
|
|
|
const Signal = require('./js/modules/signal');
|
|
|
|
const i18n = require('./js/modules/i18n');
|
2018-08-21 11:44:30 +02:00
|
|
|
|
2022-01-09 23:36:17 +01:00
|
|
|
window.Signal = Signal.setup();
|
2018-08-21 11:44:30 +02:00
|
|
|
|
2022-03-23 00:24:05 +01:00
|
|
|
window.getSwarmPollingInstance = require('./ts/session/apis/snode_api').getSwarmPollingInstance;
|
2019-09-19 08:36:19 +02:00
|
|
|
|
2019-01-31 01:14:35 +01:00
|
|
|
const WorkerInterface = require('./js/modules/util_worker_interface');
|
2018-12-13 06:33:54 +01:00
|
|
|
|
2018-12-16 23:55:51 +01:00
|
|
|
// A Worker with a 3 minute timeout
|
2018-12-14 00:03:15 +01:00
|
|
|
const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js');
|
2018-12-16 23:55:51 +01:00
|
|
|
const utilWorker = new WorkerInterface(utilWorkerPath, 3 * 60 * 1000);
|
2021-01-29 01:29:24 +01:00
|
|
|
|
2018-12-14 00:03:15 +01:00
|
|
|
window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args);
|
2018-04-03 21:03:57 +02:00
|
|
|
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
|
|
|
setInterval(() => {
|
2021-03-01 02:05:39 +01:00
|
|
|
window.nodeSetImmediate(() => {});
|
2018-04-03 21:03:57 +02:00
|
|
|
}, 1000);
|
|
|
|
|
2020-11-24 06:12:28 +01:00
|
|
|
window.loadImage = require('blueimp-load-image');
|
2018-04-24 17:19:39 +02:00
|
|
|
window.filesize = require('filesize');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2018-03-26 20:44:45 +02:00
|
|
|
window.React = require('react');
|
|
|
|
window.ReactDOM = require('react-dom');
|
2018-04-03 21:03:57 +02:00
|
|
|
|
2018-12-03 01:19:45 +01:00
|
|
|
window.clipboard = clipboard;
|
|
|
|
|
2022-03-21 06:29:07 +01:00
|
|
|
window.getSeedNodeList = () => [
|
|
|
|
{
|
|
|
|
url: 'https://storage.seed1.loki.network:4433/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: 'https://storage.seed3.loki.network:4433/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: 'https://public.loki.foundation:4433/',
|
|
|
|
},
|
|
|
|
];
|
2018-03-24 02:37:32 +01:00
|
|
|
|
2021-03-19 03:51:03 +01:00
|
|
|
const { locale: localFromEnv } = config;
|
|
|
|
window.i18n = i18n.setup(localFromEnv, localeMessages);
|
2021-02-08 06:18:36 +01:00
|
|
|
window.moment = require('moment');
|
2021-01-29 01:29:24 +01:00
|
|
|
window.libsession = require('./ts/session');
|
|
|
|
|
2021-02-15 05:16:38 +01:00
|
|
|
window.Signal.Data = require('./ts/data/data');
|
|
|
|
|
2018-04-03 21:03:57 +02:00
|
|
|
window.Signal.Logs = require('./js/modules/logs');
|
|
|
|
|
2020-03-27 06:43:19 +01:00
|
|
|
window.addEventListener('contextmenu', e => {
|
2021-04-22 10:03:58 +02:00
|
|
|
const editable = e.target.closest('textarea, input, [contenteditable="true"]');
|
2020-03-27 06:43:19 +01:00
|
|
|
const link = e.target.closest('a');
|
|
|
|
const selection = Boolean(window.getSelection().toString());
|
|
|
|
if (!editable && !selection && !link) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2019-04-10 21:06:21 +02:00
|
|
|
});
|
|
|
|
|
2020-06-12 10:08:44 +02:00
|
|
|
window.NewReceiver = require('./ts/receiver/receiver');
|
2020-02-27 02:11:08 +01:00
|
|
|
|
2020-07-07 01:13:55 +02:00
|
|
|
// Blocking
|
|
|
|
|
2021-04-22 10:03:58 +02:00
|
|
|
const { BlockedNumberController } = require('./ts/util/blockedNumberController');
|
2020-07-07 01:13:55 +02:00
|
|
|
|
|
|
|
window.BlockedNumberController = BlockedNumberController;
|