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';
|
2023-07-20 03:14:08 +00:00
|
|
|
import { usernames } from '@signalapp/libsignal-client';
|
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 { IPCEventsValuesType } from '../util/createIPCEvents';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import type { LoggerType } from '../types/Logging';
|
|
|
|
import type { NativeThemeType } from '../context/createNativeThemeListener';
|
|
|
|
import type { SettingType } 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';
|
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>>;
|
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;
|
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;
|
|
|
|
nativeThemeListener: NativeThemeType;
|
2023-11-06 21:19:23 +00:00
|
|
|
restartApp: () => void;
|
2021-10-07 23:28:47 +00:00
|
|
|
Settings: {
|
|
|
|
themeSetting: SettingType<IPCEventsValuesType['themeSetting']>;
|
|
|
|
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;
|
2023-07-20 03:14:08 +00:00
|
|
|
usernames: typeof usernames;
|
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-07-20 03:14:08 +00:00
|
|
|
usernames,
|
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;
|