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