Ensure that both window and SignalWindow are defined

This commit is contained in:
Josh Perez 2021-09-20 13:29:37 -04:00 committed by GitHub
parent e86a6119cd
commit 1b9d8dcb11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 8 deletions

View file

@ -17,8 +17,7 @@ export function setupI18n(
const getMessage: LocalizerType = (key, substitutions) => {
// eslint-disable-next-line no-console
const log =
typeof window !== 'undefined' ? window.SignalWindow.log : console;
const log = window?.SignalWindow?.log || console;
const entry = messages[key];
if (!entry) {

View file

@ -12,6 +12,7 @@ import {
} from '../environment';
import { strictAssert } from '../util/assert';
import { createSetting } from '../util/preload';
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
@ -23,6 +24,8 @@ setEnvironment(parseEnvironment(config.environment));
strictAssert(Boolean(window.SignalContext), 'context must be defined');
initializeLogging();
export const SignalWindow = {
Settings: {
themeSetting: createSetting('themeSetting', { setter: false }),
@ -34,4 +37,5 @@ export const SignalWindow = {
getEnvironment,
getVersion: (): string => String(config.version),
i18n: setupI18n(locale, localeMessages),
log: window.SignalWindow.log,
};

View file

@ -11,7 +11,6 @@ import '../context';
import { createSetting } from '../../util/preload';
import { SignalWindow } from '../configure';
import { PermissionsPopup } from '../../components/PermissionsPopup';
import { initialize as initializeLogging } from '../../logging/set_up_renderer_logging';
const mediaCameraPermissions = createSetting('mediaCameraPermissions', {
getter: false,
@ -64,5 +63,3 @@ contextBridge.exposeInMainWorld('SignalWindow', {
);
},
});
initializeLogging();

View file

@ -4,7 +4,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { contextBridge, ipcRenderer } from 'electron';
import { initialize as initializeLogging } from '../../logging/set_up_renderer_logging';
// It is important to call this as early as possible
import '../context';
@ -367,5 +366,3 @@ contextBridge.exposeInMainWorld('SignalWindow', {
...SignalWindow,
renderWindow: renderPreferences,
});
initializeLogging();