2021-08-18 16:08:14 -04:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-07 19:28:47 -04:00
|
|
|
import { ipcRenderer } from 'electron';
|
2022-06-08 15:00:32 -07:00
|
|
|
import type { MenuItemConstructorOptions } from 'electron';
|
2022-06-13 14:39:35 -07:00
|
|
|
|
2024-01-16 22:32:38 +01:00
|
|
|
import type { MenuOptionsType } from '../types/menu';
|
2021-10-07 19:28:47 -04:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import type { LoggerType } from '../types/Logging';
|
|
|
|
import type { NativeThemeType } from '../context/createNativeThemeListener';
|
2024-03-07 09:36:08 -08:00
|
|
|
import type { SettingType, SettingsValuesType } from '../util/preload';
|
2022-06-13 14:39:35 -07:00
|
|
|
import type { RendererConfigType } from '../types/RendererConfig';
|
|
|
|
|
2021-10-07 19:28:47 -04:00
|
|
|
import { Bytes } from '../context/Bytes';
|
|
|
|
import { Crypto } from '../context/Crypto';
|
|
|
|
import { Timers } from '../context/Timers';
|
2021-08-18 16:08:14 -04:00
|
|
|
|
2023-03-14 11:55:31 -04:00
|
|
|
import type { ActiveWindowServiceType } from '../services/ActiveWindowService';
|
|
|
|
import { i18n } from '../context/i18n';
|
2021-10-07 19:28:47 -04:00
|
|
|
import { strictAssert } from '../util/assert';
|
|
|
|
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
|
2023-04-20 17:23:19 -04:00
|
|
|
import { MinimalSignalContext } from './minimalContext';
|
2023-08-07 13:28:09 -07:00
|
|
|
import type { LocaleDirection } from '../../app/locale';
|
|
|
|
import type { HourCyclePreference } from '../types/I18N';
|
2024-03-21 09:35:54 -07:00
|
|
|
import type { LocaleEmojiListType } from '../types/emoji';
|
2021-10-07 19:28:47 -04:00
|
|
|
|
|
|
|
strictAssert(Boolean(window.SignalContext), 'context must be defined');
|
|
|
|
|
|
|
|
initializeLogging();
|
|
|
|
|
2022-06-08 15:00:32 -07:00
|
|
|
export type MainWindowStatsType = Readonly<{
|
|
|
|
isMaximized: boolean;
|
|
|
|
isFullScreen: boolean;
|
|
|
|
}>;
|
|
|
|
|
2023-04-20 17:23:19 -04:00
|
|
|
export type MinimalSignalContextType = {
|
2023-03-14 11:55:31 -04:00
|
|
|
activeWindowService: ActiveWindowServiceType;
|
2023-04-20 17:23:19 -04:00
|
|
|
config: RendererConfigType;
|
|
|
|
executeMenuRole: (role: MenuItemConstructorOptions['role']) => Promise<void>;
|
|
|
|
getAppInstance: () => string | undefined;
|
|
|
|
getEnvironment: () => string;
|
2023-11-06 13:19:23 -08:00
|
|
|
getI18nAvailableLocales: () => ReadonlyArray<string>;
|
2023-04-20 17:23:19 -04:00
|
|
|
getI18nLocale: LocalizerType['getLocale'];
|
|
|
|
getI18nLocaleMessages: LocalizerType['getLocaleMessages'];
|
2023-11-08 12:39:56 -08:00
|
|
|
getLocaleDisplayNames: () => Record<string, Record<string, string>>;
|
2024-02-08 15:19:03 -08:00
|
|
|
getCountryDisplayNames: () => Record<string, Record<string, string>>;
|
2023-08-07 13:28:09 -07:00
|
|
|
getResolvedMessagesLocaleDirection: () => LocaleDirection;
|
|
|
|
getHourCyclePreference: () => HourCyclePreference;
|
|
|
|
getResolvedMessagesLocale: () => string;
|
|
|
|
getPreferredSystemLocales: () => Array<string>;
|
2023-11-06 17:02:13 -08:00
|
|
|
getLocaleOverride: () => string | null;
|
2024-03-21 09:35:54 -07:00
|
|
|
getLocalizedEmojiList: (
|
|
|
|
locale: string
|
|
|
|
) => Promise<LocaleEmojiListType | undefined>;
|
2023-04-20 17:23:19 -04:00
|
|
|
getMainWindowStats: () => Promise<MainWindowStatsType>;
|
|
|
|
getMenuOptions: () => Promise<MenuOptionsType>;
|
|
|
|
getNodeVersion: () => string;
|
2023-08-01 09:06:29 -07:00
|
|
|
getPath: (name: 'userData' | 'home' | 'install') => string;
|
2023-04-20 17:23:19 -04:00
|
|
|
getVersion: () => string;
|
2024-03-01 16:52:17 -05:00
|
|
|
isTestOrMockEnvironment: () => boolean;
|
2023-04-20 17:23:19 -04:00
|
|
|
nativeThemeListener: NativeThemeType;
|
2023-11-06 13:19:23 -08:00
|
|
|
restartApp: () => void;
|
2021-10-07 19:28:47 -04:00
|
|
|
Settings: {
|
2024-03-07 09:36:08 -08:00
|
|
|
themeSetting: SettingType<SettingsValuesType['themeSetting']>;
|
2021-10-07 19:28:47 -04:00
|
|
|
waitForChange: () => Promise<void>;
|
|
|
|
};
|
2022-06-09 09:21:17 -07:00
|
|
|
OS: {
|
2023-04-20 17:23:19 -04:00
|
|
|
getClassName: () => string;
|
2022-06-15 11:21:03 -07:00
|
|
|
platform: string;
|
2023-04-20 17:23:19 -04:00
|
|
|
release: string;
|
2022-06-09 09:21:17 -07:00
|
|
|
};
|
2023-04-20 17:23:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export type SignalContextType = {
|
|
|
|
bytes: Bytes;
|
|
|
|
crypto: Crypto;
|
2021-10-07 19:28:47 -04:00
|
|
|
i18n: LocalizerType;
|
|
|
|
log: LoggerType;
|
|
|
|
renderWindow?: () => void;
|
2023-04-20 17:23:19 -04:00
|
|
|
setIsCallActive: (isCallActive: boolean) => unknown;
|
|
|
|
timers: Timers;
|
|
|
|
} & MinimalSignalContextType;
|
2021-10-07 19:28:47 -04:00
|
|
|
|
|
|
|
export const SignalContext: SignalContextType = {
|
2023-04-20 17:23:19 -04:00
|
|
|
...MinimalSignalContext,
|
2021-10-07 19:28:47 -04:00
|
|
|
bytes: new Bytes(),
|
|
|
|
crypto: new Crypto(),
|
2023-03-14 11:55:31 -04:00
|
|
|
i18n,
|
2021-10-07 19:28:47 -04:00
|
|
|
log: window.SignalContext.log,
|
|
|
|
setIsCallActive(isCallActive: boolean): void {
|
|
|
|
ipcRenderer.send('set-is-call-active', isCallActive);
|
|
|
|
},
|
|
|
|
timers: new Timers(),
|
|
|
|
};
|
|
|
|
|
|
|
|
window.SignalContext = SignalContext;
|
2022-06-13 18:48:07 -07:00
|
|
|
window.i18n = SignalContext.i18n;
|