2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2021-09-16 15:52:56 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-03-14 15:55:31 +00:00
|
|
|
import type { MenuItemConstructorOptions } from 'electron';
|
|
|
|
import { contextBridge, ipcRenderer } from 'electron';
|
|
|
|
import { activeWindowService } from '../../context/activeWindowService';
|
|
|
|
import { config } from '../../context/config';
|
|
|
|
import { createNativeThemeListener } from '../../context/createNativeThemeListener';
|
|
|
|
import { createSetting } from '../../util/preload';
|
|
|
|
import { environment } from '../../context/environment';
|
|
|
|
import { getClassName } from '../../OS';
|
|
|
|
import { i18n } from '../../context/i18n';
|
|
|
|
import { waitForSettingsChange } from '../../context/waitForSettingsChange';
|
|
|
|
|
|
|
|
async function executeMenuRole(
|
|
|
|
role: MenuItemConstructorOptions['role']
|
|
|
|
): Promise<void> {
|
|
|
|
await ipcRenderer.invoke('executeMenuRole', role);
|
|
|
|
}
|
|
|
|
|
|
|
|
const environments: Array<string> = [environment];
|
|
|
|
|
|
|
|
if (config.appInstance) {
|
|
|
|
environments.push(String(config.appInstance));
|
|
|
|
}
|
|
|
|
|
|
|
|
let platform = '';
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
if (process.arch === 'arm64') {
|
2023-03-30 00:03:25 +00:00
|
|
|
platform = ` (${i18n('icu:appleSilicon')})`;
|
2023-03-14 15:55:31 +00:00
|
|
|
} else {
|
|
|
|
platform = ' (Intel)';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const environmentText = `${environments.join(' - ')}${platform}`;
|
|
|
|
const hasCustomTitleBar = ipcRenderer.sendSync('getHasCustomTitleBar');
|
|
|
|
|
|
|
|
const Signal = {
|
|
|
|
AboutWindow: {
|
|
|
|
environmentText,
|
|
|
|
executeMenuRole,
|
|
|
|
hasCustomTitleBar,
|
|
|
|
i18n,
|
|
|
|
version: String(config.version),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
contextBridge.exposeInMainWorld('Signal', Signal);
|
|
|
|
|
|
|
|
// TODO DESKTOP-5054
|
|
|
|
const SignalContext = {
|
|
|
|
activeWindowService,
|
|
|
|
OS: {
|
|
|
|
getClassName,
|
|
|
|
hasCustomTitleBar: () => hasCustomTitleBar,
|
|
|
|
},
|
|
|
|
Settings: {
|
|
|
|
themeSetting: createSetting('themeSetting', { setter: false }),
|
|
|
|
waitForChange: waitForSettingsChange,
|
2021-09-16 15:52:56 +00:00
|
|
|
},
|
2023-03-14 15:55:31 +00:00
|
|
|
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
|
|
|
};
|
|
|
|
contextBridge.exposeInMainWorld('SignalContext', SignalContext);
|