signal-desktop/ts/windows/main/start.ts

89 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2017 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { clone, has } from 'lodash';
2023-01-13 00:24:59 +00:00
import { contextBridge } from 'electron';
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';
import type { FeatureFlagType } from '../../window.d';
import type { StorageAccessType } from '../../types/Storage.d';
2023-02-23 21:32:19 +00:00
import type { CdsLookupOptionsType } from '../../textsecure/WebAPI';
2023-01-13 00:24:59 +00:00
import { start as startConversationController } from '../../ConversationController';
import { MessageController } from '../../util/MessageController';
import { Environment, getEnvironment } from '../../environment';
import { isProduction } from '../../util/version';
2023-05-04 17:59:02 +00:00
import { ipcInvoke } from '../../sql/channels';
window.addEventListener('contextmenu', e => {
const node = e.target as Element | null;
const isEditable = Boolean(
node?.closest('textarea, input, [contenteditable="true"]')
);
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);
MessageController.install();
startConversationController();
if (!isProduction(window.SignalContext.getVersion())) {
const SignalDebug = {
2023-02-23 21:32:19 +00:00
cdsLookup: (options: CdsLookupOptionsType) =>
window.textsecure.server?.cdsLookup(options),
getConversation: (id: string) => window.ConversationController.get(id),
getMessageById: (id: string) => window.MessageController.getById(id),
getReduxState: () => window.reduxStore.getState(),
getSfuUrl: () => window.Signal.Services.calling._sfuUrl,
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;
},
2023-05-04 17:59:02 +00:00
sqlCall: (name: string, ...args: ReadonlyArray<unknown>) =>
ipcInvoke(name, args),
};
2023-01-13 00:24:59 +00:00
contextBridge.exposeInMainWorld('SignalDebug', SignalDebug);
}
2023-01-13 00:24:59 +00:00
if (getEnvironment() === Environment.Test) {
2023-01-13 00:24:59 +00:00
contextBridge.exposeInMainWorld('RETRY_DELAY', window.RETRY_DELAY);
contextBridge.exposeInMainWorld('assert', window.assert);
2023-01-13 00:24:59 +00:00
contextBridge.exposeInMainWorld('testUtilities', window.testUtilities);
}
if (process.env.SIGNAL_CI_CONFIG) {
contextBridge.exposeInMainWorld('SignalCI', window.SignalCI);
}
contextBridge.exposeInMainWorld('showDebugLog', window.IPC.showDebugLog);
contextBridge.exposeInMainWorld('startApp', window.startApp);