Enables sandbox on about window
This commit is contained in:
parent
58691b2f5e
commit
4591b56f7f
27 changed files with 262 additions and 93 deletions
24
ts/windows/about/app.tsx
Normal file
24
ts/windows/about/app.tsx
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { About } from '../../components/About';
|
||||
import { strictAssert } from '../../util/assert';
|
||||
|
||||
const { AboutWindow } = window.Signal;
|
||||
|
||||
strictAssert(AboutWindow, 'window values not provided');
|
||||
|
||||
ReactDOM.render(
|
||||
<About
|
||||
closeAbout={() => AboutWindow.executeMenuRole('close')}
|
||||
environment={AboutWindow.environmentText}
|
||||
executeMenuRole={AboutWindow.executeMenuRole}
|
||||
hasCustomTitleBar={AboutWindow.hasCustomTitleBar}
|
||||
i18n={AboutWindow.i18n}
|
||||
version={AboutWindow.version}
|
||||
/>,
|
||||
document.getElementById('app')
|
||||
);
|
|
@ -1,42 +1,63 @@
|
|||
// Copyright 2018 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge } from 'electron';
|
||||
import type { MenuItemConstructorOptions } from 'electron';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import { activeWindowService } from '../../context/activeWindowService';
|
||||
import { config } from '../../context/config';
|
||||
import { createNativeThemeListener } from '../../context/createNativeThemeListener';
|
||||
import { createSetting } from '../../util/preload';
|
||||
import { environment } from '../../context/environment';
|
||||
import { getClassName } from '../../OS';
|
||||
import { i18n } from '../../context/i18n';
|
||||
import { waitForSettingsChange } from '../../context/waitForSettingsChange';
|
||||
|
||||
import { SignalContext } from '../context';
|
||||
import { About } from '../../components/About';
|
||||
async function executeMenuRole(
|
||||
role: MenuItemConstructorOptions['role']
|
||||
): Promise<void> {
|
||||
await ipcRenderer.invoke('executeMenuRole', role);
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalContext', {
|
||||
...SignalContext,
|
||||
renderWindow: () => {
|
||||
const environmentText: Array<string> = [SignalContext.getEnvironment()];
|
||||
const environments: Array<string> = [environment];
|
||||
|
||||
const appInstance = SignalContext.getAppInstance();
|
||||
if (appInstance) {
|
||||
environmentText.push(appInstance);
|
||||
}
|
||||
if (config.appInstance) {
|
||||
environments.push(String(config.appInstance));
|
||||
}
|
||||
|
||||
let platform = '';
|
||||
if (process.platform === 'darwin') {
|
||||
if (process.arch === 'arm64') {
|
||||
platform = ` (${SignalContext.i18n('appleSilicon')})`;
|
||||
} else {
|
||||
platform = ' (Intel)';
|
||||
}
|
||||
}
|
||||
let platform = '';
|
||||
if (process.platform === 'darwin') {
|
||||
if (process.arch === 'arm64') {
|
||||
platform = ` (${i18n('appleSilicon')})`;
|
||||
} else {
|
||||
platform = ' (Intel)';
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
React.createElement(About, {
|
||||
closeAbout: () => SignalContext.executeMenuRole('close'),
|
||||
environment: `${environmentText.join(' - ')}${platform}`,
|
||||
i18n: SignalContext.i18n,
|
||||
version: SignalContext.getVersion(),
|
||||
hasCustomTitleBar: SignalContext.OS.hasCustomTitleBar(),
|
||||
executeMenuRole: SignalContext.executeMenuRole,
|
||||
}),
|
||||
document.getElementById('app')
|
||||
);
|
||||
const environmentText = `${environments.join(' - ')}${platform}`;
|
||||
const hasCustomTitleBar = ipcRenderer.sendSync('getHasCustomTitleBar');
|
||||
|
||||
const Signal = {
|
||||
AboutWindow: {
|
||||
environmentText,
|
||||
executeMenuRole,
|
||||
hasCustomTitleBar,
|
||||
i18n,
|
||||
version: String(config.version),
|
||||
},
|
||||
});
|
||||
};
|
||||
contextBridge.exposeInMainWorld('Signal', Signal);
|
||||
|
||||
// TODO DESKTOP-5054
|
||||
const SignalContext = {
|
||||
activeWindowService,
|
||||
OS: {
|
||||
getClassName,
|
||||
hasCustomTitleBar: () => hasCustomTitleBar,
|
||||
},
|
||||
Settings: {
|
||||
themeSetting: createSetting('themeSetting', { setter: false }),
|
||||
waitForChange: waitForSettingsChange,
|
||||
},
|
||||
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
||||
};
|
||||
contextBridge.exposeInMainWorld('SignalContext', SignalContext);
|
||||
|
|
|
@ -12,13 +12,15 @@ import type { LocaleMessagesType } from '../types/I18N';
|
|||
import type { NativeThemeType } from '../context/createNativeThemeListener';
|
||||
import type { SettingType } from '../util/preload';
|
||||
import type { RendererConfigType } from '../types/RendererConfig';
|
||||
import { ActiveWindowService } from '../services/ActiveWindowService';
|
||||
|
||||
import { Bytes } from '../context/Bytes';
|
||||
import { Crypto } from '../context/Crypto';
|
||||
import { Timers } from '../context/Timers';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import type { ActiveWindowServiceType } from '../services/ActiveWindowService';
|
||||
import { config } from '../context/config';
|
||||
import { i18n } from '../context/i18n';
|
||||
import { activeWindowService } from '../context/activeWindowService';
|
||||
import {
|
||||
getEnvironment,
|
||||
parseEnvironment,
|
||||
|
@ -27,7 +29,7 @@ import {
|
|||
import { strictAssert } from '../util/assert';
|
||||
import { createSetting } from '../util/preload';
|
||||
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
|
||||
import { waitForSettingsChange } from './waitForSettingsChange';
|
||||
import { waitForSettingsChange } from '../context/waitForSettingsChange';
|
||||
import { createNativeThemeListener } from '../context/createNativeThemeListener';
|
||||
import {
|
||||
isWindows,
|
||||
|
@ -37,24 +39,6 @@ import {
|
|||
getClassName,
|
||||
} from '../OS';
|
||||
|
||||
const activeWindowService = new ActiveWindowService();
|
||||
activeWindowService.initialize(window.document, ipcRenderer);
|
||||
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
const configParam = params.get('config');
|
||||
strictAssert(typeof configParam === 'string', 'config is not a string');
|
||||
const config: RendererConfigType = JSON.parse(configParam);
|
||||
|
||||
const { resolvedTranslationsLocale } = config;
|
||||
strictAssert(
|
||||
resolvedTranslationsLocale,
|
||||
'locale could not be parsed from config'
|
||||
);
|
||||
strictAssert(
|
||||
typeof resolvedTranslationsLocale === 'string',
|
||||
'locale is not a string'
|
||||
);
|
||||
|
||||
const localeMessages = ipcRenderer.sendSync('locale-data');
|
||||
setEnvironment(parseEnvironment(config.environment));
|
||||
|
||||
|
@ -74,7 +58,7 @@ export type SignalContextType = {
|
|||
nativeThemeListener: NativeThemeType;
|
||||
setIsCallActive: (isCallActive: boolean) => unknown;
|
||||
|
||||
activeWindowService: typeof activeWindowService;
|
||||
activeWindowService: ActiveWindowServiceType;
|
||||
Settings: {
|
||||
themeSetting: SettingType<IPCEventsValuesType['themeSetting']>;
|
||||
waitForChange: () => Promise<void>;
|
||||
|
@ -128,7 +112,7 @@ export const SignalContext: SignalContextType = {
|
|||
getPath: (name: 'userData' | 'home'): string => {
|
||||
return String(config[`${name}Path`]);
|
||||
},
|
||||
i18n: setupI18n(resolvedTranslationsLocale, localeMessages),
|
||||
i18n,
|
||||
localeMessages,
|
||||
log: window.SignalContext.log,
|
||||
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
||||
|
|
|
@ -8,6 +8,6 @@ if (window.SignalContext.OS.hasCustomTitleBar()) {
|
|||
|
||||
if (window.SignalContext.renderWindow) {
|
||||
window.SignalContext.renderWindow();
|
||||
} else {
|
||||
} else if (window.SignalContext.log) {
|
||||
window.SignalContext.log.error('renderWindow is undefined!');
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
import { awaitObject } from '../../util/awaitObject';
|
||||
import { DurationInSeconds } from '../../util/durations';
|
||||
import { createSetting, createCallback } from '../../util/preload';
|
||||
import { startInteractionMode } from '../startInteractionMode';
|
||||
import { startInteractionMode } from '../../services/InteractionMode';
|
||||
|
||||
function doneRendering() {
|
||||
ipcRenderer.send('settings-done-rendering');
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
let initialized = false;
|
||||
let interactionMode: 'mouse' | 'keyboard' = 'mouse';
|
||||
|
||||
export function startInteractionMode(): void {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
document.body.classList.add('mouse-mode');
|
||||
|
||||
window.enterKeyboardMode = () => {
|
||||
if (interactionMode === 'keyboard') {
|
||||
return;
|
||||
}
|
||||
|
||||
interactionMode = 'keyboard';
|
||||
|
||||
document.body.classList.add('keyboard-mode');
|
||||
document.body.classList.remove('mouse-mode');
|
||||
|
||||
const clearSelectedMessage =
|
||||
window.reduxActions?.conversations?.clearSelectedMessage;
|
||||
if (clearSelectedMessage) {
|
||||
clearSelectedMessage();
|
||||
}
|
||||
|
||||
const userChanged = window.reduxActions?.user?.userChanged;
|
||||
if (userChanged) {
|
||||
userChanged({ interactionMode });
|
||||
}
|
||||
};
|
||||
window.enterMouseMode = () => {
|
||||
if (interactionMode === 'mouse') {
|
||||
return;
|
||||
}
|
||||
|
||||
interactionMode = 'mouse';
|
||||
|
||||
document.body.classList.add('mouse-mode');
|
||||
document.body.classList.remove('keyboard-mode');
|
||||
|
||||
const clearSelectedMessage =
|
||||
window.reduxActions?.conversations?.clearSelectedMessage;
|
||||
if (clearSelectedMessage) {
|
||||
clearSelectedMessage();
|
||||
}
|
||||
|
||||
const userChanged = window.reduxActions?.user?.userChanged;
|
||||
if (userChanged) {
|
||||
userChanged({ interactionMode });
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener(
|
||||
'keydown',
|
||||
event => {
|
||||
if (event.key === 'Tab') {
|
||||
window.enterKeyboardMode();
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
document.addEventListener('wheel', window.enterMouseMode, true);
|
||||
document.addEventListener('mousedown', window.enterMouseMode, true);
|
||||
|
||||
window.getInteractionMode = () => interactionMode;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
|
||||
import { explodePromise } from '../util/explodePromise';
|
||||
|
||||
let preferencesChangeResolvers = new Array<() => void>();
|
||||
|
||||
ipc.on('preferences-changed', _event => {
|
||||
const resolvers = preferencesChangeResolvers;
|
||||
preferencesChangeResolvers = [];
|
||||
|
||||
for (const resolve of resolvers) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
export function waitForSettingsChange(): Promise<void> {
|
||||
const { promise, resolve } = explodePromise<void>();
|
||||
|
||||
preferencesChangeResolvers.push(resolve);
|
||||
|
||||
return promise;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue