2022-02-08 17:30:42 +00:00
|
|
|
// Copyright 2017-2022 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');
|
2021-08-28 13:27:38 +00:00
|
|
|
const { strictAssert } = require('./ts/util/assert');
|
2021-09-13 19:00:32 +00:00
|
|
|
const { parseIntWithFallback } = require('./ts/util/parseIntWithFallback');
|
2021-11-30 19:33:51 +00:00
|
|
|
const { UUIDKind } = require('./ts/types/UUID');
|
2021-08-18 20:08:14 +00:00
|
|
|
|
|
|
|
// It is important to call this as early as possible
|
2021-10-07 23:28:47 +00:00
|
|
|
const { SignalContext } = require('./ts/windows/context');
|
2022-02-08 17:30:42 +00:00
|
|
|
window.i18n = SignalContext.i18n;
|
2021-10-07 23:28:47 +00:00
|
|
|
|
|
|
|
const { getEnvironment, 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 config = require('url').parse(window.location.toString(), true).query;
|
2019-05-16 22:32:38 +00:00
|
|
|
|
2021-09-17 18:27:53 +00:00
|
|
|
const log = require('./ts/logging/log');
|
|
|
|
|
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;
|
2021-09-13 19:00:32 +00:00
|
|
|
window.getBuildCreation = () => parseIntWithFallback(config.buildCreation, 0);
|
2020-09-09 22:50:44 +00:00
|
|
|
window.getExpiration = () => {
|
2021-08-23 22:45:11 +00:00
|
|
|
const sixtyDays = 60 * 86400 * 1000;
|
2020-09-09 22:50:44 +00:00
|
|
|
const remoteBuildExpiration = window.storage.get('remoteBuildExpiration');
|
2021-08-23 22:45:11 +00:00
|
|
|
const localBuildExpiration = window.Events.getAutoDownloadUpdate()
|
|
|
|
? config.buildExpiration
|
|
|
|
: config.buildExpiration - sixtyDays;
|
|
|
|
|
2020-09-09 22:50:44 +00:00
|
|
|
if (remoteBuildExpiration) {
|
|
|
|
return remoteBuildExpiration < config.buildExpiration
|
|
|
|
? remoteBuildExpiration
|
2021-08-23 22:45:11 +00:00
|
|
|
: localBuildExpiration;
|
2020-09-09 22:50:44 +00:00
|
|
|
}
|
2021-08-23 22:45:11 +00:00
|
|
|
return localBuildExpiration;
|
2020-09-09 22:50:44 +00:00
|
|
|
};
|
2020-02-27 01:53:39 +00:00
|
|
|
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-10-27 17:54:16 +00:00
|
|
|
window.getAutoLaunch = () => {
|
|
|
|
return ipc.invoke('get-auto-launch');
|
|
|
|
};
|
2021-05-11 20:59:21 +00:00
|
|
|
window.setAutoLaunch = value => {
|
2021-10-27 17:54:16 +00:00
|
|
|
return ipc.invoke('set-auto-launch', value);
|
2021-05-11 20:59:21 +00:00
|
|
|
};
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
window.isBeforeVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.lt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error(
|
2020-02-27 01:53:39 +00:00
|
|
|
`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) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error(
|
2020-07-24 23:32:08 +00:00
|
|
|
`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
|
|
|
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;
|
|
|
|
|
2021-07-28 21:37:09 +00:00
|
|
|
window.logAuthenticatedConnect = () => {
|
2021-04-13 23:43:56 +00:00
|
|
|
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;
|
2021-11-08 21:43:37 +00:00
|
|
|
|
|
|
|
// Playwright uses `eval` for `.evaluate()` API
|
2021-12-09 08:06:04 +00:00
|
|
|
if (!config.enableCI && config.environment !== 'test') {
|
2021-11-08 21:43:37 +00:00
|
|
|
// 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 = () => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('draw attention');
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.send('draw-attention');
|
|
|
|
};
|
|
|
|
window.showWindow = () => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('show window');
|
2020-02-27 01:53:39 +00:00
|
|
|
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 = () => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('restart');
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.send('restart');
|
|
|
|
};
|
2020-04-28 21:18:41 +00:00
|
|
|
window.shutdown = () => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('shutdown');
|
2020-04-28 21:18:41 +00:00
|
|
|
ipc.send('shutdown');
|
|
|
|
};
|
2021-07-15 23:48:09 +00:00
|
|
|
window.showDebugLog = () => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('showDebugLog');
|
2021-07-15 23:48:09 +00:00
|
|
|
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
|
|
|
|
2021-07-30 16:43:16 +00:00
|
|
|
ipc.on('additional-log-data-request', async event => {
|
|
|
|
const ourConversation = window.ConversationController.getOurConversation();
|
|
|
|
const ourCapabilities = ourConversation
|
|
|
|
? ourConversation.get('capabilities')
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
const remoteConfig = window.storage.get('remoteConfig') || {};
|
|
|
|
|
|
|
|
let statistics;
|
|
|
|
try {
|
|
|
|
statistics = await window.Signal.Data.getStatisticsForLogging();
|
|
|
|
} catch (error) {
|
|
|
|
statistics = {};
|
|
|
|
}
|
|
|
|
|
2021-09-10 02:38:11 +00:00
|
|
|
const ourUuid = window.textsecure.storage.user.getUuid();
|
2021-11-30 19:33:51 +00:00
|
|
|
const ourPni = window.textsecure.storage.user.getUuid(UUIDKind.PNI);
|
2021-09-10 02:38:11 +00:00
|
|
|
|
2021-07-30 16:43:16 +00:00
|
|
|
event.sender.send('additional-log-data-response', {
|
|
|
|
capabilities: ourCapabilities || {},
|
2021-08-07 00:34:48 +00:00
|
|
|
remoteConfig: _.mapValues(remoteConfig, ({ value, enabled }) => {
|
|
|
|
const enableString = enabled ? 'enabled' : 'disabled';
|
|
|
|
const valueString = value && value !== 'TRUE' ? ` ${value}` : '';
|
|
|
|
return `${enableString}${valueString}`;
|
|
|
|
}),
|
2021-07-30 16:43:16 +00:00
|
|
|
statistics,
|
|
|
|
user: {
|
|
|
|
deviceId: window.textsecure.storage.user.getDeviceId(),
|
|
|
|
e164: window.textsecure.storage.user.getNumber(),
|
2021-09-10 02:38:11 +00:00
|
|
|
uuid: ourUuid && ourUuid.toString(),
|
2021-11-19 17:34:50 +00:00
|
|
|
pni: ourPni && ourPni.toString(),
|
2021-07-30 16:43:16 +00:00
|
|
|
conversationId: ourConversation && ourConversation.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2022-01-24 20:32:09 +00:00
|
|
|
ipc.on('power-channel:lock-screen', () => {
|
|
|
|
Whisper.events.trigger('powerMonitorLockScreen');
|
|
|
|
});
|
|
|
|
|
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');
|
2021-10-27 16:16:09 +00:00
|
|
|
window.showPermissionsPopup = () => ipc.invoke('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
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
require('./ts/windows/preload');
|
2020-06-04 18:16:19 +00:00
|
|
|
|
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
|
|
|
|
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) {
|
2021-09-17 18:27:53 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-28 13:27:38 +00:00
|
|
|
ipc.on('show-conversation-via-signal.me', (_event, info) => {
|
|
|
|
const { hash } = info;
|
|
|
|
strictAssert(typeof hash === 'string', 'Got an invalid hash over IPC');
|
|
|
|
|
|
|
|
const { showConversationViaSignalDotMe } = window.Events;
|
|
|
|
if (showConversationViaSignalDotMe) {
|
|
|
|
showConversationViaSignalDotMe(hash);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
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) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error('preload shutdown handler: shutdown method not found');
|
2020-02-27 01:53:39 +00:00
|
|
|
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
|
|
|
|
2021-10-23 00:41:45 +00:00
|
|
|
ipc.on('show-release-notes', () => {
|
|
|
|
const { showReleaseNotes } = window.Events;
|
|
|
|
if (showReleaseNotes) {
|
|
|
|
showReleaseNotes();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
if (config.proxyUrl) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('Using provided proxy url');
|
2020-02-27 01:53:39 +00:00
|
|
|
}
|
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;
|
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,
|
2021-11-02 23:01:13 +00:00
|
|
|
updatesUrl: config.updatesUrl,
|
2022-03-09 19:28:40 +00:00
|
|
|
directoryVersion: parseInt(config.directoryVersion, 10),
|
2020-09-04 01:25:19 +00:00
|
|
|
directoryUrl: config.directoryUrl,
|
|
|
|
directoryEnclaveId: config.directoryEnclaveId,
|
|
|
|
directoryTrustAnchor: config.directoryTrustAnchor,
|
2021-11-08 23:32:31 +00:00
|
|
|
directoryV2Url: config.directoryV2Url,
|
|
|
|
directoryV2PublicKey: config.directoryV2PublicKey,
|
2022-03-09 19:28:40 +00:00
|
|
|
directoryV2CodeHashes: (config.directoryV2CodeHashes || '').split(','),
|
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-05-27 21:37:06 +00:00
|
|
|
const { imageToBlurHash } = require('./ts/util/imageToBlurHash');
|
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;
|
2021-11-11 22:43:05 +00:00
|
|
|
window.libphonenumber =
|
|
|
|
require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
|
|
|
window.libphonenumber.PhoneNumberFormat =
|
|
|
|
require('google-libphonenumber').PhoneNumberFormat;
|
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);
|
2021-11-11 22:43:05 +00:00
|
|
|
window.registerForActive =
|
|
|
|
activeWindowService.registerForActive.bind(activeWindowService);
|
|
|
|
window.unregisterForActive =
|
|
|
|
activeWindowService.unregisterForActive.bind(activeWindowService);
|
2020-12-17 23:12:15 +00:00
|
|
|
|
2021-04-27 22:11:59 +00:00
|
|
|
window.Accessibility = {
|
|
|
|
reducedMotionSetting: Boolean(config.reducedMotionSetting),
|
|
|
|
};
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.React = require('react');
|
|
|
|
window.ReactDOM = require('react-dom');
|
2022-02-15 22:32:10 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.moment = require('moment');
|
2022-02-15 22:32:10 +00:00
|
|
|
require('moment/min/locales.min');
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.PQueue = require('p-queue').default;
|
|
|
|
|
|
|
|
const Signal = require('./js/modules/signal');
|
2021-10-27 17:54:16 +00:00
|
|
|
const Attachments = require('./ts/windows/attachments');
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
const { locale } = config;
|
|
|
|
window.moment.updateLocale(locale, {
|
|
|
|
relativeTime: {
|
|
|
|
s: window.i18n('timestamp_s'),
|
|
|
|
m: window.i18n('timestamp_m'),
|
|
|
|
h: window.i18n('timestamp_h'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
window.moment.locale(locale);
|
|
|
|
|
2021-10-27 17:54:16 +00:00
|
|
|
const userDataPath = SignalContext.getPath('userData');
|
2020-02-27 01:53:39 +00:00
|
|
|
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);
|
2022-01-20 01:50:16 +00:00
|
|
|
if (config.crashDumpsPath) {
|
|
|
|
addSensitivePath(config.crashDumpsPath);
|
|
|
|
}
|
2021-06-01 18:15:23 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.Signal = Signal.setup({
|
|
|
|
Attachments,
|
|
|
|
userDataPath,
|
|
|
|
getRegionCode: () => window.storage.get('regionCode'),
|
2021-09-17 18:27:53 +00:00
|
|
|
logger: log,
|
2020-02-27 01:53:39 +00:00
|
|
|
});
|
2021-08-11 19:29:07 +00:00
|
|
|
|
|
|
|
if (config.enableCI) {
|
2021-11-08 21:43:37 +00:00
|
|
|
const { CI } = require('./ts/CI');
|
2021-08-11 19:29:07 +00:00
|
|
|
window.CI = new CI(title);
|
|
|
|
}
|
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/views/conversation_view');
|
2021-09-17 18:27:53 +00:00
|
|
|
require('./ts/views/inbox_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');
|
|
|
|
|
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());
|
2021-09-07 16:12:26 +00:00
|
|
|
const image = e.target.closest('.Lightbox img');
|
2020-11-03 00:47:46 +00:00
|
|
|
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-08-11 19:29:07 +00:00
|
|
|
require('./preload_test');
|
2020-02-27 01:53:39 +00:00
|
|
|
}
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('preload complete');
|
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();
|