2021-01-27 21:13:33 +00:00
|
|
|
// Copyright 2017-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-05-16 22:14:06 +00:00
|
|
|
/* global Whisper, window */
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
/* eslint-disable global-require, no-inner-declarations */
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-04-07 22:40:12 +00:00
|
|
|
const preloadStartTime = Date.now();
|
|
|
|
let preloadEndTime = 0;
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
try {
|
|
|
|
const electron = require('electron');
|
|
|
|
const semver = require('semver');
|
2020-03-05 21:14:58 +00:00
|
|
|
const _ = require('lodash');
|
2020-02-27 01:53:39 +00:00
|
|
|
const { installGetter, installSetter } = require('./preload_utils');
|
2021-02-04 19:54:03 +00:00
|
|
|
const {
|
|
|
|
getEnvironment,
|
|
|
|
setEnvironment,
|
|
|
|
parseEnvironment,
|
|
|
|
Environment,
|
|
|
|
} = require('./ts/environment');
|
2021-06-30 18:57:43 +00:00
|
|
|
const ipc = electron.ipcRenderer;
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
const { remote } = electron;
|
|
|
|
const { app } = remote;
|
2018-06-02 00:55:35 +00:00
|
|
|
|
2021-06-22 14:46:42 +00:00
|
|
|
const { Context: SignalContext } = require('./ts/context');
|
|
|
|
|
2021-06-30 18:57:43 +00:00
|
|
|
window.SignalContext = new SignalContext(ipc);
|
2021-06-22 14:46:42 +00:00
|
|
|
|
2021-03-04 21:44:57 +00:00
|
|
|
window.sqlInitializer = require('./ts/sql/initialize');
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
const config = require('url').parse(window.location.toString(), true).query;
|
2019-05-16 22:32:38 +00:00
|
|
|
|
2021-02-04 19:54:03 +00:00
|
|
|
setEnvironment(parseEnvironment(config.environment));
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
let title = config.name;
|
2021-02-04 19:54:03 +00:00
|
|
|
if (getEnvironment() !== Environment.Production) {
|
|
|
|
title += ` - ${getEnvironment()}`;
|
2020-02-27 01:53:39 +00:00
|
|
|
}
|
|
|
|
if (config.appInstance) {
|
|
|
|
title += ` - ${config.appInstance}`;
|
|
|
|
}
|
2019-05-16 22:32:38 +00:00
|
|
|
|
2020-12-18 19:27:43 +00:00
|
|
|
// Flags for testing
|
|
|
|
window.GV2_ENABLE_SINGLE_CHANGE_PROCESSING = true;
|
|
|
|
window.GV2_ENABLE_CHANGE_PROCESSING = true;
|
|
|
|
window.GV2_ENABLE_STATE_PROCESSING = true;
|
|
|
|
|
2021-01-12 15:44:44 +00:00
|
|
|
window.GV2_MIGRATION_DISABLE_ADD = false;
|
|
|
|
window.GV2_MIGRATION_DISABLE_INVITE = false;
|
|
|
|
|
2021-07-15 23:48:09 +00:00
|
|
|
window.RETRY_DELAY = false;
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.platform = process.platform;
|
|
|
|
window.getTitle = () => title;
|
2021-02-18 16:40:26 +00:00
|
|
|
window.getLocale = () => config.locale;
|
2021-02-04 19:54:03 +00:00
|
|
|
window.getEnvironment = getEnvironment;
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getAppInstance = () => config.appInstance;
|
|
|
|
window.getVersion = () => config.version;
|
2020-09-09 22:50:44 +00:00
|
|
|
window.getExpiration = () => {
|
|
|
|
const remoteBuildExpiration = window.storage.get('remoteBuildExpiration');
|
|
|
|
if (remoteBuildExpiration) {
|
|
|
|
return remoteBuildExpiration < config.buildExpiration
|
|
|
|
? remoteBuildExpiration
|
|
|
|
: config.buildExpiration;
|
|
|
|
}
|
|
|
|
return config.buildExpiration;
|
|
|
|
};
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getNodeVersion = () => config.node_version;
|
|
|
|
window.getHostName = () => config.hostname;
|
|
|
|
window.getServerTrustRoot = () => config.serverTrustRoot;
|
2020-04-15 23:12:28 +00:00
|
|
|
window.getServerPublicParams = () => config.serverPublicParams;
|
2020-12-07 19:40:11 +00:00
|
|
|
window.getSfuUrl = () => config.sfuUrl;
|
2020-02-27 01:53:39 +00:00
|
|
|
window.isBehindProxy = () => Boolean(config.proxyUrl);
|
2021-05-11 20:59:21 +00:00
|
|
|
window.getAutoLaunch = () => app.getLoginItemSettings().openAtLogin;
|
|
|
|
window.setAutoLaunch = value => {
|
|
|
|
app.setLoginItemSettings({ openAtLogin: Boolean(value) });
|
|
|
|
};
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
window.isBeforeVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.lt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
|
|
|
window.log.error(
|
|
|
|
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2020-07-24 23:32:08 +00:00
|
|
|
window.isAfterVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.gt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
|
|
|
window.log.error(
|
|
|
|
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-07-20 21:52:52 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
const localeMessages = ipc.sendSync('locale-data');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-04-13 23:43:56 +00:00
|
|
|
let connectStartTime = 0;
|
|
|
|
|
|
|
|
window.logMessageReceiverConnect = () => {
|
|
|
|
if (connectStartTime === 0) {
|
|
|
|
connectStartTime = Date.now();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.logAppLoadedEvent = ({ processedCount }) =>
|
2021-04-07 22:40:12 +00:00
|
|
|
ipc.send('signal-app-loaded', {
|
|
|
|
preloadTime: preloadEndTime - preloadStartTime,
|
2021-04-13 23:43:56 +00:00
|
|
|
connectTime: connectStartTime - preloadEndTime,
|
|
|
|
processedCount,
|
2021-04-07 22:40:12 +00:00
|
|
|
});
|
2021-01-15 17:30:58 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// We never do these in our code, so we'll prevent it everywhere
|
|
|
|
window.open = () => null;
|
|
|
|
// eslint-disable-next-line no-eval, no-multi-assign
|
|
|
|
window.eval = global.eval = () => null;
|
2018-05-19 01:21:02 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.drawAttention = () => {
|
|
|
|
window.log.info('draw attention');
|
|
|
|
ipc.send('draw-attention');
|
|
|
|
};
|
|
|
|
window.showWindow = () => {
|
|
|
|
window.log.info('show window');
|
|
|
|
ipc.send('show-window');
|
|
|
|
};
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-02-01 20:01:25 +00:00
|
|
|
window.titleBarDoubleClick = () => {
|
|
|
|
ipc.send('title-bar-double-click');
|
|
|
|
};
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setAutoHideMenuBar = autoHide =>
|
|
|
|
ipc.send('set-auto-hide-menu-bar', autoHide);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setMenuBarVisibility = visibility =>
|
|
|
|
ipc.send('set-menu-bar-visibility', visibility);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-06-29 17:18:03 +00:00
|
|
|
window.updateSystemTraySetting = (
|
|
|
|
systemTraySetting /* : Readonly<SystemTraySetting> */
|
|
|
|
) => {
|
|
|
|
ipc.send('update-system-tray-setting', systemTraySetting);
|
|
|
|
};
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.restart = () => {
|
|
|
|
window.log.info('restart');
|
|
|
|
ipc.send('restart');
|
|
|
|
};
|
2020-04-28 21:18:41 +00:00
|
|
|
window.shutdown = () => {
|
|
|
|
window.log.info('shutdown');
|
|
|
|
ipc.send('shutdown');
|
|
|
|
};
|
2021-07-15 23:48:09 +00:00
|
|
|
window.showDebugLog = () => {
|
|
|
|
window.log.info('showDebugLog');
|
|
|
|
ipc.send('show-debug-log');
|
|
|
|
};
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.closeAbout = () => ipc.send('close-about');
|
|
|
|
window.readyForUpdates = () => ipc.send('ready-for-updates');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.updateTrayIcon = unreadCount =>
|
|
|
|
ipc.send('update-tray-icon', unreadCount);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('set-up-as-new-device', () => {
|
|
|
|
Whisper.events.trigger('setupAsNewDevice');
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('set-up-as-standalone', () => {
|
|
|
|
Whisper.events.trigger('setupAsStandalone');
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-05-06 00:09:29 +00:00
|
|
|
ipc.on('challenge:response', (_event, response) => {
|
|
|
|
Whisper.events.trigger('challengeResponse', response);
|
|
|
|
});
|
2021-06-09 22:28:54 +00:00
|
|
|
|
|
|
|
ipc.on('power-channel:suspend', () => {
|
|
|
|
Whisper.events.trigger('powerMonitorSuspend');
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('power-channel:resume', () => {
|
|
|
|
Whisper.events.trigger('powerMonitorResume');
|
|
|
|
});
|
|
|
|
|
2021-05-06 00:09:29 +00:00
|
|
|
window.sendChallengeRequest = request =>
|
|
|
|
ipc.send('challenge:request', request);
|
|
|
|
|
2021-02-01 20:01:25 +00:00
|
|
|
{
|
|
|
|
let isFullScreen = config.isFullScreen === 'true';
|
|
|
|
|
|
|
|
window.isFullScreen = () => isFullScreen;
|
|
|
|
// This is later overwritten.
|
|
|
|
window.onFullScreenChange = _.noop;
|
|
|
|
|
|
|
|
ipc.on('full-screen-change', (_event, isFull) => {
|
|
|
|
isFullScreen = Boolean(isFull);
|
|
|
|
window.onFullScreenChange(isFullScreen);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// Settings-related events
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.showSettings = () => ipc.send('show-settings');
|
|
|
|
window.showPermissionsPopup = () => ipc.send('show-permissions-popup');
|
2020-06-04 18:16:19 +00:00
|
|
|
window.showCallingPermissionsPopup = forCamera =>
|
|
|
|
ipc.invoke('show-calling-permissions-popup', forCamera);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('show-keyboard-shortcuts', () => {
|
|
|
|
window.Events.showKeyboardShortcuts();
|
|
|
|
});
|
|
|
|
ipc.on('add-dark-overlay', () => {
|
|
|
|
window.Events.addDarkOverlay();
|
|
|
|
});
|
|
|
|
ipc.on('remove-dark-overlay', () => {
|
|
|
|
window.Events.removeDarkOverlay();
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('device-name', 'getDeviceName');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('theme-setting', 'getThemeSetting');
|
|
|
|
installSetter('theme-setting', 'setThemeSetting');
|
|
|
|
installGetter('hide-menu-bar', 'getHideMenuBar');
|
|
|
|
installSetter('hide-menu-bar', 'setHideMenuBar');
|
2021-06-29 17:18:03 +00:00
|
|
|
installGetter('system-tray-setting', 'getSystemTraySetting');
|
|
|
|
installSetter('system-tray-setting', 'setSystemTraySetting');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('notification-setting', 'getNotificationSetting');
|
|
|
|
installSetter('notification-setting', 'setNotificationSetting');
|
2020-08-24 21:45:31 +00:00
|
|
|
installGetter('notification-draw-attention', 'getNotificationDrawAttention');
|
|
|
|
installSetter('notification-draw-attention', 'setNotificationDrawAttention');
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('audio-notification', 'getAudioNotification');
|
|
|
|
installSetter('audio-notification', 'setAudioNotification');
|
2020-09-14 22:16:57 +00:00
|
|
|
installGetter(
|
|
|
|
'badge-count-muted-conversations',
|
|
|
|
'getCountMutedConversations'
|
|
|
|
);
|
|
|
|
installSetter(
|
|
|
|
'badge-count-muted-conversations',
|
|
|
|
'setCountMutedConversations'
|
|
|
|
);
|
|
|
|
|
|
|
|
window.getCountMutedConversations = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once(
|
|
|
|
'get-success-badge-count-muted-conversations',
|
|
|
|
(_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
ipc.send('get-badge-count-muted-conversations');
|
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('spell-check', 'getSpellCheck');
|
|
|
|
installSetter('spell-check', 'setSpellCheck');
|
2018-07-19 01:46:12 +00:00
|
|
|
|
2021-05-11 20:59:21 +00:00
|
|
|
installGetter('auto-launch', 'getAutoLaunch');
|
|
|
|
installSetter('auto-launch', 'setAutoLaunch');
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
installGetter('always-relay-calls', 'getAlwaysRelayCalls');
|
|
|
|
installSetter('always-relay-calls', 'setAlwaysRelayCalls');
|
|
|
|
|
|
|
|
installGetter('call-ringtone-notification', 'getCallRingtoneNotification');
|
|
|
|
installSetter('call-ringtone-notification', 'setCallRingtoneNotification');
|
|
|
|
|
|
|
|
window.getCallRingtoneNotification = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once(
|
|
|
|
'get-success-call-ringtone-notification',
|
|
|
|
(_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
ipc.send('get-call-ringtone-notification');
|
|
|
|
});
|
|
|
|
|
|
|
|
installGetter('call-system-notification', 'getCallSystemNotification');
|
|
|
|
installSetter('call-system-notification', 'setCallSystemNotification');
|
|
|
|
|
|
|
|
window.getCallSystemNotification = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once(
|
|
|
|
'get-success-call-system-notification',
|
|
|
|
(_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
ipc.send('get-call-system-notification');
|
|
|
|
});
|
|
|
|
|
|
|
|
installGetter('incoming-call-notification', 'getIncomingCallNotification');
|
|
|
|
installSetter('incoming-call-notification', 'setIncomingCallNotification');
|
|
|
|
|
|
|
|
window.getIncomingCallNotification = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once(
|
|
|
|
'get-success-incoming-call-notification',
|
|
|
|
(_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
ipc.send('get-incoming-call-notification');
|
|
|
|
});
|
|
|
|
|
|
|
|
window.getAlwaysRelayCalls = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('get-success-always-relay-calls', (_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
});
|
|
|
|
ipc.send('get-always-relay-calls');
|
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getMediaPermissions = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('get-success-media-permissions', (_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
return resolve(value);
|
|
|
|
});
|
|
|
|
ipc.send('get-media-permissions');
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
window.getMediaCameraPermissions = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once(
|
|
|
|
'get-success-media-camera-permissions',
|
|
|
|
(_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
ipc.send('get-media-camera-permissions');
|
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getBuiltInImages = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('get-success-built-in-images', (_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
2019-10-04 18:06:17 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
return resolve(value);
|
|
|
|
});
|
|
|
|
ipc.send('get-built-in-images');
|
2019-10-04 18:06:17 +00:00
|
|
|
});
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
installGetter('is-primary', 'isPrimary');
|
|
|
|
installGetter('sync-request', 'getSyncRequest');
|
|
|
|
installGetter('sync-time', 'getLastSyncTime');
|
|
|
|
installSetter('sync-time', 'setLastSyncTime');
|
2021-06-01 20:45:43 +00:00
|
|
|
installGetter('universal-expire-timer', 'getUniversalExpireTimer');
|
|
|
|
installSetter('universal-expire-timer', 'setUniversalExpireTimer');
|
2020-02-27 01:53:39 +00:00
|
|
|
|
2021-05-13 20:54:54 +00:00
|
|
|
ipc.on('delete-all-data', async () => {
|
2020-02-27 01:53:39 +00:00
|
|
|
const { deleteAllData } = window.Events;
|
2021-05-13 20:54:54 +00:00
|
|
|
if (!deleteAllData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await deleteAllData();
|
|
|
|
} catch (error) {
|
|
|
|
window.log.error('delete-all-data: error', error && error.stack);
|
2020-02-27 01:53:39 +00:00
|
|
|
}
|
2019-10-04 18:06:17 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('show-sticker-pack', (_event, info) => {
|
|
|
|
const { packId, packKey } = info;
|
|
|
|
const { showStickerPack } = window.Events;
|
|
|
|
if (showStickerPack) {
|
|
|
|
showStickerPack(packId, packKey);
|
|
|
|
}
|
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
ipc.on('show-group-via-link', (_event, info) => {
|
|
|
|
const { hash } = info;
|
|
|
|
const { showGroupViaLink } = window.Events;
|
|
|
|
if (showGroupViaLink) {
|
|
|
|
showGroupViaLink(hash);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('unknown-sgnl-link', () => {
|
|
|
|
const { unknownSignalLink } = window.Events;
|
|
|
|
if (unknownSignalLink) {
|
|
|
|
unknownSignalLink();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('install-sticker-pack', (_event, info) => {
|
|
|
|
const { packId, packKey } = info;
|
|
|
|
const { installStickerPack } = window.Events;
|
|
|
|
if (installStickerPack) {
|
|
|
|
installStickerPack(packId, packKey);
|
|
|
|
}
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('get-ready-for-shutdown', async () => {
|
|
|
|
const { shutdown } = window.Events || {};
|
|
|
|
if (!shutdown) {
|
|
|
|
window.log.error('preload shutdown handler: shutdown method not found');
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
return;
|
|
|
|
}
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
try {
|
|
|
|
await shutdown();
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
} catch (error) {
|
|
|
|
ipc.send(
|
|
|
|
'now-ready-for-shutdown',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.addSetupMenuItems = () => ipc.send('add-setup-menu-items');
|
|
|
|
window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// We pull these dependencies in now, from here, because they have Node.js dependencies
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-03-04 21:44:57 +00:00
|
|
|
require('./ts/logging/set_up_renderer_logging').initialize();
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
if (config.proxyUrl) {
|
|
|
|
window.log.info('Using provided proxy url');
|
|
|
|
}
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.nodeSetImmediate = setImmediate;
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2021-04-16 23:13:13 +00:00
|
|
|
window.Backbone = require('backbone');
|
2020-04-13 17:37:29 +00:00
|
|
|
window.textsecure = require('./ts/textsecure').default;
|
2021-03-24 00:50:02 +00:00
|
|
|
window.synchronousCrypto = require('./ts/util/synchronousCrypto');
|
2019-08-19 22:26:45 +00:00
|
|
|
|
2020-04-13 17:37:29 +00:00
|
|
|
window.WebAPI = window.textsecure.WebAPI.initialize({
|
2020-02-27 01:53:39 +00:00
|
|
|
url: config.serverUrl,
|
2020-07-07 00:56:56 +00:00
|
|
|
storageUrl: config.storageUrl,
|
2020-09-04 01:25:19 +00:00
|
|
|
directoryUrl: config.directoryUrl,
|
|
|
|
directoryEnclaveId: config.directoryEnclaveId,
|
|
|
|
directoryTrustAnchor: config.directoryTrustAnchor,
|
2020-04-17 22:51:39 +00:00
|
|
|
cdnUrlObject: {
|
2020-11-18 15:15:42 +00:00
|
|
|
0: config.cdnUrl0,
|
|
|
|
2: config.cdnUrl2,
|
2020-04-17 22:51:39 +00:00
|
|
|
},
|
2020-02-27 01:53:39 +00:00
|
|
|
certificateAuthority: config.certificateAuthority,
|
|
|
|
contentProxyUrl: config.contentProxyUrl,
|
|
|
|
proxyUrl: config.proxyUrl,
|
|
|
|
version: config.version,
|
|
|
|
});
|
2019-08-19 22:26:45 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
|
|
|
setInterval(() => {
|
|
|
|
window.nodeSetImmediate(() => {});
|
|
|
|
}, 1000);
|
|
|
|
|
2020-05-27 21:37:06 +00:00
|
|
|
const { imageToBlurHash } = require('./ts/util/imageToBlurHash');
|
2020-12-07 20:35:14 +00:00
|
|
|
const { isGroupCallingEnabled } = require('./ts/util/isGroupCallingEnabled');
|
2021-06-22 14:46:42 +00:00
|
|
|
const { isValidGuid } = require('./ts/util/isValidGuid');
|
2020-12-17 23:12:15 +00:00
|
|
|
const { ActiveWindowService } = require('./ts/services/ActiveWindowService');
|
2020-02-27 01:53:39 +00:00
|
|
|
|
2020-05-27 21:37:06 +00:00
|
|
|
window.imageToBlurHash = imageToBlurHash;
|
2020-02-27 01:53:39 +00:00
|
|
|
window.emojiData = require('emoji-datasource');
|
|
|
|
window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
|
|
|
window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat;
|
|
|
|
window.loadImage = require('blueimp-load-image');
|
|
|
|
window.getGuid = require('uuid/v4');
|
2020-12-07 20:35:14 +00:00
|
|
|
window.isGroupCallingEnabled = isGroupCallingEnabled;
|
2020-02-27 01:53:39 +00:00
|
|
|
|
2020-12-17 23:12:15 +00:00
|
|
|
const activeWindowService = new ActiveWindowService();
|
|
|
|
activeWindowService.initialize(window.document, ipc);
|
|
|
|
window.isActive = activeWindowService.isActive.bind(activeWindowService);
|
|
|
|
window.registerForActive = activeWindowService.registerForActive.bind(
|
|
|
|
activeWindowService
|
|
|
|
);
|
|
|
|
window.unregisterForActive = activeWindowService.unregisterForActive.bind(
|
|
|
|
activeWindowService
|
|
|
|
);
|
|
|
|
|
2021-04-27 22:11:59 +00:00
|
|
|
window.Accessibility = {
|
|
|
|
reducedMotionSetting: Boolean(config.reducedMotionSetting),
|
|
|
|
};
|
|
|
|
|
2021-06-22 14:46:42 +00:00
|
|
|
window.isValidGuid = isValidGuid;
|
2020-03-05 21:14:58 +00:00
|
|
|
// https://stackoverflow.com/a/23299989
|
|
|
|
window.isValidE164 = maybeE164 => /^\+?[1-9]\d{1,14}$/.test(maybeE164);
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.React = require('react');
|
|
|
|
window.ReactDOM = require('react-dom');
|
|
|
|
window.moment = require('moment');
|
|
|
|
window.PQueue = require('p-queue').default;
|
|
|
|
|
|
|
|
const Signal = require('./js/modules/signal');
|
|
|
|
const i18n = require('./js/modules/i18n');
|
|
|
|
const Attachments = require('./app/attachments');
|
|
|
|
|
|
|
|
const { locale } = config;
|
|
|
|
window.i18n = i18n.setup(locale, localeMessages);
|
|
|
|
window.moment.updateLocale(locale, {
|
|
|
|
relativeTime: {
|
|
|
|
s: window.i18n('timestamp_s'),
|
|
|
|
m: window.i18n('timestamp_m'),
|
|
|
|
h: window.i18n('timestamp_h'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
window.moment.locale(locale);
|
|
|
|
|
|
|
|
const userDataPath = app.getPath('userData');
|
|
|
|
window.baseAttachmentsPath = Attachments.getPath(userDataPath);
|
|
|
|
window.baseStickersPath = Attachments.getStickersPath(userDataPath);
|
|
|
|
window.baseTempPath = Attachments.getTempPath(userDataPath);
|
|
|
|
window.baseDraftPath = Attachments.getDraftPath(userDataPath);
|
2021-06-01 18:15:23 +00:00
|
|
|
|
|
|
|
const { addSensitivePath } = require('./ts/util/privacy');
|
|
|
|
|
|
|
|
addSensitivePath(window.baseAttachmentsPath);
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.Signal = Signal.setup({
|
|
|
|
Attachments,
|
|
|
|
userDataPath,
|
|
|
|
getRegionCode: () => window.storage.get('regionCode'),
|
|
|
|
logger: window.log,
|
|
|
|
});
|
2021-03-29 22:18:58 +00:00
|
|
|
window.CI = config.enableCI
|
|
|
|
? {
|
|
|
|
setProvisioningURL: url => ipc.send('set-provisioning-url', url),
|
|
|
|
deviceName: title,
|
|
|
|
}
|
|
|
|
: undefined;
|
2020-02-27 01:53:39 +00:00
|
|
|
|
2020-09-24 20:57:54 +00:00
|
|
|
// these need access to window.Signal:
|
|
|
|
require('./ts/models/messages');
|
|
|
|
require('./ts/models/conversations');
|
|
|
|
|
2021-02-26 21:06:37 +00:00
|
|
|
require('./ts/backbone/views/whisper_view');
|
|
|
|
require('./ts/backbone/views/toast_view');
|
|
|
|
require('./ts/views/conversation_view');
|
2021-04-16 23:13:13 +00:00
|
|
|
require('./ts/SignalProtocolStore');
|
2021-02-26 21:06:37 +00:00
|
|
|
require('./ts/background');
|
2021-02-23 19:36:07 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// Pulling these in separately since they access filesystem, electron
|
|
|
|
window.Signal.Debug = require('./js/modules/debug');
|
|
|
|
window.Signal.Logs = require('./js/modules/logs');
|
|
|
|
|
2020-03-20 21:00:11 +00:00
|
|
|
window.addEventListener('contextmenu', e => {
|
|
|
|
const editable = e.target.closest(
|
|
|
|
'textarea, input, [contenteditable="true"]'
|
|
|
|
);
|
|
|
|
const link = e.target.closest('a');
|
|
|
|
const selection = Boolean(window.getSelection().toString());
|
2020-11-03 00:47:46 +00:00
|
|
|
const image = e.target.closest('.module-lightbox img');
|
|
|
|
if (!editable && !selection && !link && !image) {
|
2020-03-20 21:00:11 +00:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2020-02-27 01:53:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (config.environment === 'test') {
|
2021-04-14 19:43:11 +00:00
|
|
|
require('./preload_test.js');
|
2020-02-27 01:53:39 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-03-03 00:09:46 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
if (console._log) {
|
|
|
|
console._log('preload error!', error.stack);
|
|
|
|
} else {
|
|
|
|
console.log('preload error!', error.stack);
|
|
|
|
}
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
throw error;
|
2018-12-13 21:41:42 +00:00
|
|
|
}
|
2020-02-27 01:53:39 +00:00
|
|
|
|
2021-04-07 22:40:12 +00:00
|
|
|
preloadEndTime = Date.now();
|
2020-02-27 01:53:39 +00:00
|
|
|
window.log.info('preload complete');
|