diff --git a/test/setup-test-node.js b/test/setup-test-node.js index 53f8703fe..e7ecb30d6 100644 --- a/test/setup-test-node.js +++ b/test/setup-test-node.js @@ -29,14 +29,16 @@ global.window = { warn: (...args) => console.warn(...args), error: (...args) => console.error(...args), }, + getResolvedMessagesLocale: () => 'en', + getResolvedMessagesLocaleDirection: () => 'ltr', + getHourCyclePreference: () => HourCyclePreference.UnknownPreference, + getPreferredSystemLocales: () => ['en'], }, i18n: key => `i18n(${key})`, storage: { get: key => storageMap.get(key), put: async (key, value) => storageMap.set(key, value), }, - getPreferredSystemLocales: () => ['en'], - getHourCyclePreference: () => HourCyclePreference.UnknownPreference, }; // For ducks/network.getEmptyState() diff --git a/ts/background.ts b/ts/background.ts index 8b5ccead7..b778bbacf 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -573,12 +573,12 @@ export async function startApp(): Promise { document.documentElement.setAttribute( 'lang', - window.getResolvedMessagesLocale().split(/[-_]/)[0] + window.SignalContext.getResolvedMessagesLocale().split(/[-_]/)[0] ); document.documentElement.setAttribute( 'dir', - window.getResolvedMessagesLocaleDirection() + window.SignalContext.getResolvedMessagesLocaleDirection() ); KeyChangeListener.init(window.textsecure.storage.protocol); diff --git a/ts/components/conversation/ChatSessionRefreshedNotification.tsx b/ts/components/conversation/ChatSessionRefreshedNotification.tsx index 72cb620d2..fb79253b5 100644 --- a/ts/components/conversation/ChatSessionRefreshedNotification.tsx +++ b/ts/components/conversation/ChatSessionRefreshedNotification.tsx @@ -36,7 +36,7 @@ export function ChatSessionRefreshedNotification( const baseUrl = 'https://support.signal.org/hc/LOCALE/requests/new?desktop&chat_refreshed'; - const locale = window.getResolvedMessagesLocale(); + const locale = window.SignalContext.getResolvedMessagesLocale(); const supportLocale = mapToSupportLocale(locale); const url = baseUrl.replace('LOCALE', supportLocale); diff --git a/ts/models/messages.ts b/ts/models/messages.ts index eab500cb8..e57fdb9dd 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -2806,8 +2806,8 @@ export class MessageModel extends window.Backbone.Model { 'getProfile: expected updatesUrl to be a defined string' ); const userLanguages = getUserLanguages( - window.getPreferredSystemLocales(), - window.getResolvedMessagesLocale() + window.SignalContext.getPreferredSystemLocales(), + window.SignalContext.getResolvedMessagesLocale() ); const { messaging } = window.textsecure; if (!messaging) { diff --git a/ts/services/profiles.ts b/ts/services/profiles.ts index a97b9c227..fae110ae5 100644 --- a/ts/services/profiles.ts +++ b/ts/services/profiles.ts @@ -224,8 +224,8 @@ async function doGetProfile(c: ConversationModel): Promise { ); const userLanguages = getUserLanguages( - window.getPreferredSystemLocales(), - window.getResolvedMessagesLocale() + window.SignalContext.getPreferredSystemLocales(), + window.SignalContext.getResolvedMessagesLocale() ); let profile; diff --git a/ts/test-node/util/formatTimestamp_test.ts b/ts/test-node/util/formatTimestamp_test.ts index 7fb87c320..aace95c78 100644 --- a/ts/test-node/util/formatTimestamp_test.ts +++ b/ts/test-node/util/formatTimestamp_test.ts @@ -16,8 +16,14 @@ describe('formatTimestamp', () => { beforeEach(() => { sandbox = sinon.createSandbox(); - localesStub = sandbox.stub(window, 'getPreferredSystemLocales'); - hourCycleStub = sandbox.stub(window, 'getHourCyclePreference'); + localesStub = sandbox.stub( + window.SignalContext, + 'getPreferredSystemLocales' + ); + hourCycleStub = sandbox.stub( + window.SignalContext, + 'getHourCyclePreference' + ); }); afterEach(() => { diff --git a/ts/util/formatTimestamp.ts b/ts/util/formatTimestamp.ts index c0606977a..b46dd3caf 100644 --- a/ts/util/formatTimestamp.ts +++ b/ts/util/formatTimestamp.ts @@ -7,7 +7,7 @@ import { assertDev } from './assert'; function getOptionsWithPreferences( options: Intl.DateTimeFormatOptions ): Intl.DateTimeFormatOptions { - const hourCyclePreference = window.getHourCyclePreference(); + const hourCyclePreference = window.SignalContext.getHourCyclePreference(); if (options.hour12 != null) { return options; } @@ -67,7 +67,7 @@ const formatterCache = new Map(); export function getDateTimeFormatter( options: Intl.DateTimeFormatOptions ): Intl.DateTimeFormat { - const locales = window.getPreferredSystemLocales(); + const locales = window.SignalContext.getPreferredSystemLocales(); const optionsWithPreferences = getOptionsWithPreferences(options); const cacheKey = getCacheKey(locales, optionsWithPreferences); const cachedFormatter = formatterCache.get(cacheKey); diff --git a/ts/util/keyboard.ts b/ts/util/keyboard.ts index b90f21048..0451cffe9 100644 --- a/ts/util/keyboard.ts +++ b/ts/util/keyboard.ts @@ -15,6 +15,7 @@ const logicalArrows: Record< }; export function arrow(logicalDirection: LogicalDirection): HorizontalArrowKey { - const localeDirection = window.getResolvedMessagesLocaleDirection(); + const localeDirection = + window.SignalContext.getResolvedMessagesLocaleDirection(); return logicalArrows[logicalDirection][localeDirection]; } diff --git a/ts/util/setupI18n.tsx b/ts/util/setupI18n.tsx index ab3f50eb9..9d786212d 100644 --- a/ts/util/setupI18n.tsx +++ b/ts/util/setupI18n.tsx @@ -121,10 +121,10 @@ export function setupI18n( localizer.getLocale = () => locale; localizer.getLocaleMessages = () => messages; localizer.getLocaleDirection = () => { - return window.getResolvedMessagesLocaleDirection(); + return window.SignalContext.getResolvedMessagesLocaleDirection(); }; localizer.getHourCyclePreference = () => { - return window.getHourCyclePreference(); + return window.SignalContext.getHourCyclePreference(); }; return localizer; diff --git a/ts/window.d.ts b/ts/window.d.ts index 0f376d8c1..cc454a576 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -56,9 +56,7 @@ import type * as Message2 from './types/Message2'; import type { initializeMigrations } from './signal'; import type { RetryPlaceholders } from './util/retryPlaceholders'; import type { PropsPreloadType as PreferencesPropsType } from './components/Preferences'; -import type { LocaleDirection } from '../app/locale'; import type { WindowsNotificationData } from './services/notifications'; -import type { HourCyclePreference } from './types/I18N'; export { Long } from 'long'; @@ -199,10 +197,6 @@ declare global { getEnvironment: typeof getEnvironment; getHostName: () => string; getInteractionMode: () => 'mouse' | 'keyboard'; - getResolvedMessagesLocaleDirection: () => LocaleDirection; - getHourCyclePreference: () => HourCyclePreference; - getResolvedMessagesLocale: () => string; - getPreferredSystemLocales: () => Array; getServerPublicParams: () => string; getSfuUrl: () => string; getSocketStatus: () => SocketStatus; diff --git a/ts/windows/context.ts b/ts/windows/context.ts index 6c4e6fd0a..857093051 100644 --- a/ts/windows/context.ts +++ b/ts/windows/context.ts @@ -22,6 +22,8 @@ import { i18n } from '../context/i18n'; import { strictAssert } from '../util/assert'; import { initialize as initializeLogging } from '../logging/set_up_renderer_logging'; import { MinimalSignalContext } from './minimalContext'; +import type { LocaleDirection } from '../../app/locale'; +import type { HourCyclePreference } from '../types/I18N'; strictAssert(Boolean(window.SignalContext), 'context must be defined'); @@ -41,6 +43,10 @@ export type MinimalSignalContextType = { getEnvironment: () => string; getI18nLocale: LocalizerType['getLocale']; getI18nLocaleMessages: LocalizerType['getLocaleMessages']; + getResolvedMessagesLocaleDirection: () => LocaleDirection; + getHourCyclePreference: () => HourCyclePreference; + getResolvedMessagesLocale: () => string; + getPreferredSystemLocales: () => Array; getMainWindowStats: () => Promise; getMenuOptions: () => Promise; getNodeVersion: () => string; diff --git a/ts/windows/main/phase1-ipc.ts b/ts/windows/main/phase1-ipc.ts index 3dd50b5e0..4197dc9bf 100644 --- a/ts/windows/main/phase1-ipc.ts +++ b/ts/windows/main/phase1-ipc.ts @@ -45,11 +45,6 @@ window.RETRY_DELAY = false; window.platform = process.platform; window.getTitle = () => title; -window.getResolvedMessagesLocale = () => config.resolvedTranslationsLocale; -window.getResolvedMessagesLocaleDirection = () => - config.resolvedTranslationsLocaleDirection; -window.getHourCyclePreference = () => config.hourCyclePreference; -window.getPreferredSystemLocales = () => config.preferredSystemLocales; window.getEnvironment = getEnvironment; window.getAppInstance = () => config.appInstance; window.getVersion = () => config.version; diff --git a/ts/windows/minimalContext.ts b/ts/windows/minimalContext.ts index cd0e32f51..12c46318c 100644 --- a/ts/windows/minimalContext.ts +++ b/ts/windows/minimalContext.ts @@ -42,6 +42,13 @@ export const MinimalSignalContext: MinimalSignalContextType = { }, getI18nLocale: () => config.resolvedTranslationsLocale, getI18nLocaleMessages: () => localeMessages, + + getResolvedMessagesLocale: () => config.resolvedTranslationsLocale, + getResolvedMessagesLocaleDirection: () => + config.resolvedTranslationsLocaleDirection, + getHourCyclePreference: () => config.hourCyclePreference, + getPreferredSystemLocales: () => config.preferredSystemLocales, + nativeThemeListener: createNativeThemeListener(ipcRenderer, window), OS: { getClassName: () => ipcRenderer.sendSync('OS.getClassName'),