2022-06-13 21:39:35 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { ipcRenderer as ipc } from 'electron';
|
|
|
|
import * as semver from 'semver';
|
2023-01-13 00:24:59 +00:00
|
|
|
import { mapValues } from 'lodash';
|
2022-06-13 21:39:35 +00:00
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
import type { IPCType } from '../../window.d';
|
2022-06-13 21:39:35 +00:00
|
|
|
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
|
2023-03-22 19:25:52 +00:00
|
|
|
import { getSignalConnections } from '../../util/getSignalConnections';
|
2022-06-13 21:39:35 +00:00
|
|
|
import { ThemeType } from '../../types/Util';
|
|
|
|
import { getEnvironment, Environment } from '../../environment';
|
|
|
|
import { SignalContext } from '../context';
|
|
|
|
import * as log from '../../logging/log';
|
2023-03-22 19:25:52 +00:00
|
|
|
import { formatCountForLogging } from '../../logging/formatCountForLogging';
|
2022-11-22 18:43:43 +00:00
|
|
|
import * as Errors from '../../types/errors';
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
import { strictAssert } from '../../util/assert';
|
2023-02-27 22:34:43 +00:00
|
|
|
import { drop } from '../../util/drop';
|
2023-08-01 16:06:29 +00:00
|
|
|
import type {
|
|
|
|
NotificationClickData,
|
|
|
|
WindowsNotificationData,
|
|
|
|
} from '../../services/notifications';
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
// It is important to call this as early as possible
|
|
|
|
window.i18n = SignalContext.i18n;
|
|
|
|
|
|
|
|
// We are comfortable doing this because we verified the type on the other side!
|
|
|
|
const { config } = window.SignalContext;
|
|
|
|
|
|
|
|
// Flags for testing
|
2023-01-13 00:24:59 +00:00
|
|
|
const Flags = {
|
|
|
|
GV2_ENABLE_CHANGE_PROCESSING: true,
|
|
|
|
GV2_ENABLE_PRE_JOIN_FETCH: true,
|
|
|
|
GV2_ENABLE_SINGLE_CHANGE_PROCESSING: true,
|
|
|
|
GV2_ENABLE_STATE_PROCESSING: true,
|
|
|
|
GV2_MIGRATION_DISABLE_ADD: false,
|
|
|
|
GV2_MIGRATION_DISABLE_INVITE: false,
|
|
|
|
};
|
2022-06-13 21:39:35 +00:00
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
window.Flags = Flags;
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
window.RETRY_DELAY = false;
|
|
|
|
|
|
|
|
window.platform = process.platform;
|
|
|
|
window.getTitle = () => title;
|
|
|
|
window.getEnvironment = getEnvironment;
|
|
|
|
window.getAppInstance = () => config.appInstance;
|
|
|
|
window.getVersion = () => config.version;
|
|
|
|
window.getBuildCreation = () => parseIntWithFallback(config.buildCreation, 0);
|
2023-01-18 23:31:10 +00:00
|
|
|
window.getBuildExpiration = () => config.buildExpiration;
|
2022-06-13 21:39:35 +00:00
|
|
|
window.getHostName = () => config.hostname;
|
|
|
|
window.getServerTrustRoot = () => config.serverTrustRoot;
|
|
|
|
window.getServerPublicParams = () => config.serverPublicParams;
|
|
|
|
window.getSfuUrl = () => config.sfuUrl;
|
|
|
|
window.isBehindProxy = () => Boolean(config.proxyUrl);
|
|
|
|
|
|
|
|
let title = config.name;
|
|
|
|
if (getEnvironment() !== Environment.Production) {
|
|
|
|
title += ` - ${getEnvironment()}`;
|
|
|
|
}
|
|
|
|
if (config.appInstance) {
|
|
|
|
title += ` - ${config.appInstance}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.theme === 'light') {
|
|
|
|
window.initialTheme = ThemeType.light;
|
|
|
|
} else if (config.theme === 'dark') {
|
|
|
|
window.initialTheme = ThemeType.dark;
|
|
|
|
}
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
const IPC: IPCType = {
|
|
|
|
addSetupMenuItems: () => ipc.send('add-setup-menu-items'),
|
2023-08-01 16:06:29 +00:00
|
|
|
clearAllWindowsNotifications: async () => {
|
|
|
|
log.info('show window');
|
|
|
|
return ipc.invoke('windows-notifications:clear-all');
|
|
|
|
},
|
2023-01-13 00:24:59 +00:00
|
|
|
closeAbout: () => ipc.send('close-about'),
|
|
|
|
crashReports: {
|
|
|
|
getCount: () => ipc.invoke('crash-reports:get-count'),
|
2024-02-13 21:41:48 +00:00
|
|
|
writeToLog: () => ipc.invoke('crash-reports:write-to-log'),
|
2023-01-13 00:24:59 +00:00
|
|
|
erase: () => ipc.invoke('crash-reports:erase'),
|
|
|
|
},
|
|
|
|
drawAttention: () => {
|
|
|
|
log.info('draw attention');
|
|
|
|
ipc.send('draw-attention');
|
|
|
|
},
|
|
|
|
getAutoLaunch: () => ipc.invoke('get-auto-launch'),
|
2023-11-01 18:03:08 +00:00
|
|
|
getMediaAccessStatus: mediaType =>
|
|
|
|
ipc.invoke('get-media-access-status', mediaType),
|
2023-01-13 00:24:59 +00:00
|
|
|
getMediaPermissions: () => ipc.invoke('settings:get:mediaPermissions'),
|
|
|
|
getMediaCameraPermissions: () =>
|
|
|
|
ipc.invoke('settings:get:mediaCameraPermissions'),
|
|
|
|
logAppLoadedEvent: ({ processedCount }) =>
|
|
|
|
ipc.send('signal-app-loaded', {
|
|
|
|
preloadTime: window.preloadEndTime - window.preloadStartTime,
|
|
|
|
connectTime: preloadConnectTime - window.preloadEndTime,
|
|
|
|
processedCount,
|
|
|
|
}),
|
|
|
|
readyForUpdates: () => ipc.send('ready-for-updates'),
|
|
|
|
removeSetupMenuItems: () => ipc.send('remove-setup-menu-items'),
|
|
|
|
setAutoHideMenuBar: autoHide => ipc.send('set-auto-hide-menu-bar', autoHide),
|
|
|
|
setAutoLaunch: value => ipc.invoke('set-auto-launch', value),
|
2023-08-14 23:28:47 +00:00
|
|
|
setBadge: badge => ipc.send('set-badge', badge),
|
2023-01-13 00:24:59 +00:00
|
|
|
setMenuBarVisibility: visibility =>
|
|
|
|
ipc.send('set-menu-bar-visibility', visibility),
|
|
|
|
showDebugLog: () => {
|
|
|
|
log.info('showDebugLog');
|
|
|
|
ipc.send('show-debug-log');
|
|
|
|
},
|
|
|
|
showPermissionsPopup: (forCalling, forCamera) =>
|
|
|
|
ipc.invoke('show-permissions-popup', forCalling, forCamera),
|
|
|
|
showSettings: () => ipc.send('show-settings'),
|
|
|
|
showWindow: () => {
|
|
|
|
log.info('show window');
|
|
|
|
ipc.send('show-window');
|
|
|
|
},
|
2023-08-01 16:06:29 +00:00
|
|
|
showWindowsNotification: async (data: WindowsNotificationData) => {
|
|
|
|
return ipc.invoke('windows-notifications:show', data);
|
|
|
|
},
|
2023-01-13 00:24:59 +00:00
|
|
|
shutdown: () => {
|
|
|
|
log.info('shutdown');
|
|
|
|
ipc.send('shutdown');
|
|
|
|
},
|
|
|
|
titleBarDoubleClick: () => {
|
|
|
|
ipc.send('title-bar-double-click');
|
|
|
|
},
|
|
|
|
updateSystemTraySetting: (
|
|
|
|
systemTraySetting /* : Readonly<SystemTraySetting> */
|
|
|
|
) => {
|
|
|
|
void ipc.invoke('update-system-tray-setting', systemTraySetting);
|
|
|
|
},
|
|
|
|
updateTrayIcon: unreadCount => ipc.send('update-tray-icon', unreadCount),
|
2022-06-13 21:39:35 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
window.IPC = IPC;
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
window.isBeforeVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.lt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(error)
|
2022-06-13 21:39:35 +00:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.isAfterVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.gt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(error)
|
2022-06-13 21:39:35 +00:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-15 01:15:33 +00:00
|
|
|
let preloadConnectTime = 0;
|
2022-06-13 21:39:35 +00:00
|
|
|
window.logAuthenticatedConnect = () => {
|
2022-06-15 01:15:33 +00:00
|
|
|
if (preloadConnectTime === 0) {
|
|
|
|
preloadConnectTime = Date.now();
|
2022-06-13 21:39:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// We never do these in our code, so we'll prevent it everywhere
|
|
|
|
window.open = () => null;
|
|
|
|
|
|
|
|
// Playwright uses `eval` for `.evaluate()` API
|
2023-07-20 22:37:56 +00:00
|
|
|
if (config.ciMode !== 'full' && config.environment !== 'test') {
|
2022-06-13 21:39:35 +00:00
|
|
|
// eslint-disable-next-line no-eval, no-multi-assign
|
|
|
|
window.eval = global.eval = () => null;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = {};
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const ourAci = window.textsecure.storage.user.getAci();
|
|
|
|
const ourPni = window.textsecure.storage.user.getPni();
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
event.sender.send('additional-log-data-response', {
|
|
|
|
capabilities: ourCapabilities || {},
|
|
|
|
remoteConfig: mapValues(remoteConfig, ({ value, enabled }) => {
|
|
|
|
const enableString = enabled ? 'enabled' : 'disabled';
|
|
|
|
const valueString = value && value !== 'TRUE' ? ` ${value}` : '';
|
|
|
|
return `${enableString}${valueString}`;
|
|
|
|
}),
|
2023-03-22 19:25:52 +00:00
|
|
|
statistics: {
|
|
|
|
...statistics,
|
|
|
|
signalConnectionCount: formatCountForLogging(
|
|
|
|
getSignalConnections().length
|
|
|
|
),
|
|
|
|
},
|
2022-06-13 21:39:35 +00:00
|
|
|
user: {
|
|
|
|
deviceId: window.textsecure.storage.user.getDeviceId(),
|
|
|
|
e164: window.textsecure.storage.user.getNumber(),
|
2023-08-10 16:43:33 +00:00
|
|
|
uuid: ourAci,
|
|
|
|
pni: ourPni,
|
2022-06-13 21:39:35 +00:00
|
|
|
conversationId: ourConversation && ourConversation.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('set-up-as-new-device', () => {
|
|
|
|
window.Whisper.events.trigger('setupAsNewDevice');
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('set-up-as-standalone', () => {
|
|
|
|
window.Whisper.events.trigger('setupAsStandalone');
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('challenge:response', (_event, response) => {
|
|
|
|
window.Whisper.events.trigger('challengeResponse', response);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('power-channel:suspend', () => {
|
|
|
|
window.Whisper.events.trigger('powerMonitorSuspend');
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('power-channel:resume', () => {
|
|
|
|
window.Whisper.events.trigger('powerMonitorResume');
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('power-channel:lock-screen', () => {
|
|
|
|
window.Whisper.events.trigger('powerMonitorLockScreen');
|
|
|
|
});
|
|
|
|
|
2024-02-02 23:39:32 +00:00
|
|
|
ipc.on(
|
|
|
|
'set-media-playback-disabled',
|
|
|
|
(_event: unknown, playbackDisabled: unknown) => {
|
|
|
|
const { setMediaPlaybackDisabled } = window.Events || {};
|
|
|
|
if (setMediaPlaybackDisabled) {
|
|
|
|
setMediaPlaybackDisabled(Boolean(playbackDisabled));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
ipc.on('window:set-window-stats', (_event, stats) => {
|
2023-01-13 00:24:59 +00:00
|
|
|
if (!window.reduxActions) {
|
2022-06-13 21:39:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-01-13 00:24:59 +00:00
|
|
|
|
|
|
|
window.reduxActions.user.userChanged({
|
|
|
|
isMainWindowMaximized: stats.isMaximized,
|
|
|
|
isMainWindowFullScreen: stats.isFullScreen,
|
|
|
|
});
|
2022-06-13 21:39:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('window:set-menu-options', (_event, options) => {
|
|
|
|
if (!window.Whisper.events) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.Whisper.events.trigger('setMenuOptions', options);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.sendChallengeRequest = request => ipc.send('challenge:request', request);
|
|
|
|
|
|
|
|
// Settings-related events
|
|
|
|
|
|
|
|
ipc.on('show-keyboard-shortcuts', () => {
|
|
|
|
window.Events.showKeyboardShortcuts();
|
|
|
|
});
|
|
|
|
ipc.on('add-dark-overlay', () => {
|
|
|
|
window.Events.addDarkOverlay();
|
|
|
|
});
|
|
|
|
ipc.on('remove-dark-overlay', () => {
|
|
|
|
window.Events.removeDarkOverlay();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('delete-all-data', async () => {
|
|
|
|
const { deleteAllData } = window.Events;
|
|
|
|
if (!deleteAllData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await deleteAllData();
|
|
|
|
} catch (error) {
|
2022-11-22 18:43:43 +00:00
|
|
|
log.error('delete-all-data: error', Errors.toLogFormat(error));
|
2022-06-13 21:39:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('show-sticker-pack', (_event, info) => {
|
2023-11-02 19:42:31 +00:00
|
|
|
window.Events.showStickerPack?.(info.packId, info.packKey);
|
2022-06-13 21:39:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('show-group-via-link', (_event, info) => {
|
2023-11-02 19:42:31 +00:00
|
|
|
strictAssert(typeof info.value === 'string', 'Got an invalid value over IPC');
|
|
|
|
drop(window.Events.showGroupViaLink?.(info.value));
|
2022-06-13 21:39:35 +00:00
|
|
|
});
|
|
|
|
|
2023-02-27 22:34:43 +00:00
|
|
|
ipc.on('open-art-creator', () => {
|
|
|
|
drop(window.Events.openArtCreator());
|
|
|
|
});
|
2023-11-02 19:42:31 +00:00
|
|
|
|
2023-02-27 22:34:43 +00:00
|
|
|
window.openArtCreator = ({
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
}: {
|
|
|
|
username: string;
|
|
|
|
password: string;
|
|
|
|
}) => {
|
|
|
|
return ipc.invoke('open-art-creator', { username, password });
|
|
|
|
};
|
|
|
|
|
|
|
|
ipc.on('authorize-art-creator', (_event, info) => {
|
2023-11-02 19:42:31 +00:00
|
|
|
window.Events.authorizeArtCreator?.(info);
|
2023-02-27 22:34:43 +00:00
|
|
|
});
|
|
|
|
|
2023-08-01 16:06:29 +00:00
|
|
|
ipc.on('start-call-lobby', (_event, { conversationId }) => {
|
2023-12-05 00:52:44 +00:00
|
|
|
window.IPC.showWindow();
|
2023-08-01 16:06:29 +00:00
|
|
|
window.reduxActions?.calling?.startCallingLobby({
|
|
|
|
conversationId,
|
|
|
|
isVideoCall: true,
|
|
|
|
});
|
|
|
|
});
|
2023-11-02 19:42:31 +00:00
|
|
|
|
2023-08-01 16:06:29 +00:00
|
|
|
ipc.on('show-window', () => {
|
|
|
|
window.IPC.showWindow();
|
|
|
|
});
|
2023-11-02 19:42:31 +00:00
|
|
|
|
2023-08-01 16:06:29 +00:00
|
|
|
ipc.on('set-is-presenting', () => {
|
|
|
|
window.reduxActions?.calling?.setPresenting();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on(
|
|
|
|
'show-conversation-via-notification',
|
|
|
|
(_event, data: NotificationClickData) => {
|
|
|
|
const { showConversationViaNotification } = window.Events;
|
|
|
|
if (showConversationViaNotification) {
|
|
|
|
void showConversationViaNotification(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-06-13 21:39:35 +00:00
|
|
|
ipc.on('show-conversation-via-signal.me', (_event, info) => {
|
2023-11-02 19:42:31 +00:00
|
|
|
const { kind, value } = info;
|
|
|
|
strictAssert(typeof kind === 'string', 'Got an invalid kind over IPC');
|
|
|
|
strictAssert(typeof value === 'string', 'Got an invalid value over IPC');
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
const { showConversationViaSignalDotMe } = window.Events;
|
|
|
|
if (showConversationViaSignalDotMe) {
|
2023-11-02 19:42:31 +00:00
|
|
|
void showConversationViaSignalDotMe(kind, value);
|
2022-06-13 21:39:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('unknown-sgnl-link', () => {
|
|
|
|
const { unknownSignalLink } = window.Events;
|
|
|
|
if (unknownSignalLink) {
|
|
|
|
unknownSignalLink();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('install-sticker-pack', (_event, info) => {
|
|
|
|
const { packId, packKey } = info;
|
|
|
|
const { installStickerPack } = window.Events;
|
|
|
|
if (installStickerPack) {
|
2022-12-21 18:41:48 +00:00
|
|
|
void installStickerPack(packId, packKey);
|
2022-06-13 21:39:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('get-ready-for-shutdown', async () => {
|
|
|
|
const { shutdown } = window.Events || {};
|
|
|
|
if (!shutdown) {
|
|
|
|
log.error('preload shutdown handler: shutdown method not found');
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await shutdown();
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
} catch (error) {
|
2022-11-22 18:43:43 +00:00
|
|
|
ipc.send('now-ready-for-shutdown', Errors.toLogFormat(error));
|
2022-06-13 21:39:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-19 14:44:05 +00:00
|
|
|
ipc.on('maybe-request-close-confirmation', async () => {
|
|
|
|
const { maybeRequestCloseConfirmation } = window.Events;
|
|
|
|
if (!maybeRequestCloseConfirmation) {
|
|
|
|
ipc.send('received-close-confirmation', true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info('Requesting close confirmation.');
|
|
|
|
ipc.send('requested-close-confirmation');
|
|
|
|
const result = await maybeRequestCloseConfirmation();
|
|
|
|
ipc.send('received-close-confirmation', result);
|
|
|
|
});
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
ipc.on('show-release-notes', () => {
|
|
|
|
const { showReleaseNotes } = window.Events;
|
|
|
|
if (showReleaseNotes) {
|
|
|
|
showReleaseNotes();
|
|
|
|
}
|
|
|
|
});
|