2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2017 Signal Messenger, LLC
|
2022-06-13 21:39:35 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-01-19 00:02:03 +00:00
|
|
|
import { clone, has } from 'lodash';
|
2023-01-13 00:24:59 +00:00
|
|
|
import { contextBridge } from 'electron';
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
import * as log from '../../logging/log';
|
|
|
|
|
|
|
|
import './phase1-ipc';
|
|
|
|
import '../preload';
|
|
|
|
import './phase2-dependencies';
|
|
|
|
import './phase3-post-signal';
|
|
|
|
import './phase4-test';
|
2023-01-13 00:24:59 +00:00
|
|
|
import '../../backbone/reliable_trigger';
|
|
|
|
|
2024-05-03 16:01:59 +00:00
|
|
|
import type {
|
|
|
|
CdsLookupOptionsType,
|
|
|
|
GetIceServersResultType,
|
|
|
|
} from '../../textsecure/WebAPI';
|
2023-01-19 00:02:03 +00:00
|
|
|
import type { FeatureFlagType } from '../../window.d';
|
|
|
|
import type { StorageAccessType } from '../../types/Storage.d';
|
2023-01-13 00:24:59 +00:00
|
|
|
import { start as startConversationController } from '../../ConversationController';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { initMessageCleanup } from '../../services/messageStateCleanup';
|
2023-01-19 00:02:03 +00:00
|
|
|
import { Environment, getEnvironment } from '../../environment';
|
2023-01-19 20:41:53 +00:00
|
|
|
import { isProduction } from '../../util/version';
|
2023-07-20 22:37:56 +00:00
|
|
|
import { benchmarkConversationOpen } from '../../CI/benchmarkConversationOpen';
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
window.addEventListener('contextmenu', e => {
|
|
|
|
const node = e.target as Element | null;
|
|
|
|
|
|
|
|
const isEditable = Boolean(
|
2023-10-24 17:18:58 +00:00
|
|
|
node?.closest('textarea, input, [contenteditable="plaintext-only"]')
|
2022-06-13 21:39:35 +00:00
|
|
|
);
|
|
|
|
const isLink = Boolean(node?.closest('a'));
|
|
|
|
const isImage = Boolean(node?.closest('.Lightbox img'));
|
|
|
|
const hasSelection = Boolean(window.getSelection()?.toString());
|
|
|
|
|
|
|
|
if (!isEditable && !hasSelection && !isLink && !isImage) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (window.SignalContext.config.proxyUrl) {
|
|
|
|
log.info('Using provided proxy url');
|
|
|
|
}
|
2023-01-13 00:24:59 +00:00
|
|
|
|
|
|
|
window.Whisper.events = clone(window.Backbone.Events);
|
2023-10-04 00:12:57 +00:00
|
|
|
initMessageCleanup();
|
2023-01-13 00:24:59 +00:00
|
|
|
startConversationController();
|
|
|
|
|
2023-01-19 20:41:53 +00:00
|
|
|
if (!isProduction(window.SignalContext.getVersion())) {
|
2023-01-19 00:02:03 +00:00
|
|
|
const SignalDebug = {
|
2023-02-23 21:32:19 +00:00
|
|
|
cdsLookup: (options: CdsLookupOptionsType) =>
|
|
|
|
window.textsecure.server?.cdsLookup(options),
|
2023-01-19 00:02:03 +00:00
|
|
|
getConversation: (id: string) => window.ConversationController.get(id),
|
2023-10-04 00:12:57 +00:00
|
|
|
getMessageById: (id: string) =>
|
|
|
|
window.MessageCache.__DEPRECATED$getById(id),
|
2023-01-19 00:02:03 +00:00
|
|
|
getReduxState: () => window.reduxStore.getState(),
|
|
|
|
getSfuUrl: () => window.Signal.Services.calling._sfuUrl,
|
2024-04-09 00:41:57 +00:00
|
|
|
getIceServerOverride: () =>
|
|
|
|
window.Signal.Services.calling._iceServerOverride,
|
2023-01-19 00:02:03 +00:00
|
|
|
getStorageItem: (name: keyof StorageAccessType) => window.storage.get(name),
|
|
|
|
putStorageItem: <K extends keyof StorageAccessType>(
|
|
|
|
name: K,
|
|
|
|
value: StorageAccessType[K]
|
|
|
|
) => window.storage.put(name, value),
|
|
|
|
setFlag: (name: keyof FeatureFlagType, value: boolean) => {
|
|
|
|
if (!has(window.Flags, name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.Flags[name] = value;
|
|
|
|
},
|
|
|
|
setSfuUrl: (url: string) => {
|
|
|
|
window.Signal.Services.calling._sfuUrl = url;
|
|
|
|
},
|
2024-05-03 16:01:59 +00:00
|
|
|
setIceServerOverride: (
|
|
|
|
override: GetIceServersResultType | string | undefined
|
|
|
|
) => {
|
|
|
|
if (typeof override === 'string') {
|
|
|
|
if (!/(turn|turns|stun):.*/.test(override)) {
|
|
|
|
log.warn(
|
|
|
|
'Override url should be prefixed with `turn:`, `turns:`, or `stun:` else override may not work'
|
|
|
|
);
|
|
|
|
}
|
2024-04-09 00:41:57 +00:00
|
|
|
}
|
2024-05-03 16:01:59 +00:00
|
|
|
|
|
|
|
window.Signal.Services.calling._iceServerOverride = override;
|
2024-04-09 00:41:57 +00:00
|
|
|
},
|
2024-05-23 00:28:01 +00:00
|
|
|
setRtcStatsInterval: (intervalMillis: number) =>
|
|
|
|
window.Signal.Services.calling.setAllRtcStatsInterval(intervalMillis),
|
2023-07-20 22:37:56 +00:00
|
|
|
...(window.SignalContext.config.ciMode === 'benchmark'
|
|
|
|
? {
|
|
|
|
benchmarkConversationOpen,
|
|
|
|
}
|
|
|
|
: {}),
|
2023-01-19 00:02:03 +00:00
|
|
|
};
|
2023-01-13 00:24:59 +00:00
|
|
|
|
2023-01-19 00:02:03 +00:00
|
|
|
contextBridge.exposeInMainWorld('SignalDebug', SignalDebug);
|
|
|
|
}
|
2023-01-13 00:24:59 +00:00
|
|
|
|
2023-01-19 00:02:03 +00:00
|
|
|
if (getEnvironment() === Environment.Test) {
|
2023-01-13 00:24:59 +00:00
|
|
|
contextBridge.exposeInMainWorld('RETRY_DELAY', window.RETRY_DELAY);
|
2023-01-19 00:02:03 +00:00
|
|
|
contextBridge.exposeInMainWorld('assert', window.assert);
|
2023-01-13 00:24:59 +00:00
|
|
|
contextBridge.exposeInMainWorld('testUtilities', window.testUtilities);
|
|
|
|
}
|
2023-01-19 00:02:03 +00:00
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
if (window.SignalContext.config.ciMode === 'full') {
|
2023-01-19 00:02:03 +00:00
|
|
|
contextBridge.exposeInMainWorld('SignalCI', window.SignalCI);
|
|
|
|
}
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld('showDebugLog', window.IPC.showDebugLog);
|
|
|
|
contextBridge.exposeInMainWorld('startApp', window.startApp);
|