Use SignalContext instead of SignalWindow
This commit is contained in:
parent
a70a8a88d6
commit
75dab30367
35 changed files with 180 additions and 231 deletions
|
@ -11,7 +11,7 @@
|
|||
window.Whisper.Database.nolog = true;
|
||||
|
||||
Whisper.Database.handleDOMException = (prefix, error, reject) => {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
`${prefix}:`,
|
||||
error && error.name,
|
||||
error && error.message,
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
|
||||
async function destroyExpiredMessages() {
|
||||
try {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'destroyExpiredMessages: Loading messages...'
|
||||
);
|
||||
const messages = await window.Signal.Data.getExpiredMessages({
|
||||
MessageCollection: Whisper.MessageCollection,
|
||||
});
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
`destroyExpiredMessages: found ${messages.length} messages to expire`
|
||||
);
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
|||
await Promise.all(messageCleanup);
|
||||
|
||||
inMemoryMessages.forEach(message => {
|
||||
window.SignalWindow.log.info('Message expired', {
|
||||
window.SignalContext.log.info('Message expired', {
|
||||
sentAt: message.get('sent_at'),
|
||||
});
|
||||
|
||||
|
@ -52,25 +52,25 @@
|
|||
}
|
||||
});
|
||||
} catch (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'destroyExpiredMessages: Error deleting expired messages',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
|
||||
window.SignalWindow.log.info('destroyExpiredMessages: complete');
|
||||
window.SignalContext.log.info('destroyExpiredMessages: complete');
|
||||
checkExpiringMessages();
|
||||
}
|
||||
|
||||
let timeout;
|
||||
async function checkExpiringMessages() {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'checkExpiringMessages: checking for expiring messages'
|
||||
);
|
||||
|
||||
const soonestExpiry = await window.Signal.Data.getSoonestMessageExpiry();
|
||||
if (!soonestExpiry) {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'checkExpiringMessages: found no messages to expire'
|
||||
);
|
||||
return;
|
||||
|
@ -88,7 +88,7 @@
|
|||
wait = 2147483647;
|
||||
}
|
||||
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
`checkExpiringMessages: next message expires ${new Date(
|
||||
soonestExpiry
|
||||
).toISOString()}; waiting ${wait} ms before clearing`
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
async function eraseTapToViewMessages() {
|
||||
try {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'eraseTapToViewMessages: Loading messages...'
|
||||
);
|
||||
const messages = await window.Signal.Data.getTapToViewMessagesNeedingErase(
|
||||
|
@ -26,7 +26,7 @@
|
|||
messages.map(async fromDB => {
|
||||
const message = MessageController.register(fromDB.id, fromDB);
|
||||
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'eraseTapToViewMessages: message data erased',
|
||||
message.idForLogging()
|
||||
);
|
||||
|
@ -35,13 +35,13 @@
|
|||
})
|
||||
);
|
||||
} catch (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'eraseTapToViewMessages: Error erasing messages',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
|
||||
window.SignalWindow.log.info('eraseTapToViewMessages: complete');
|
||||
window.SignalContext.log.info('eraseTapToViewMessages: complete');
|
||||
}
|
||||
|
||||
let timeout;
|
||||
|
@ -59,7 +59,7 @@
|
|||
const nextCheck = receivedAt + THIRTY_DAYS;
|
||||
|
||||
Whisper.TapToViewMessagesListener.nextCheck = nextCheck;
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'checkTapToViewMessages: next check at',
|
||||
new Date(nextCheck).toISOString()
|
||||
);
|
||||
|
|
|
@ -58,7 +58,7 @@ exports.createConversation = async ({
|
|||
await Promise.all(
|
||||
range(0, numMessages).map(async index => {
|
||||
await sleep(index * 100);
|
||||
window.SignalWindow.log.info(`Create message ${index + 1}`);
|
||||
window.SignalContext.log.info(`Create message ${index + 1}`);
|
||||
const message = await createRandomMessage({ conversationId });
|
||||
return Signal.Data.saveMessage(message);
|
||||
})
|
||||
|
@ -110,7 +110,7 @@ const createRandomMessage = async ({ conversationId } = {}) => {
|
|||
const message = _createMessage({ commonProperties, conversationId, type });
|
||||
return Message.initializeSchemaVersion({
|
||||
message,
|
||||
logger: window.SignalWindow.log,
|
||||
logger: window.SignalContext.log,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class IdleDetector extends EventEmitter {
|
|||
}
|
||||
|
||||
start() {
|
||||
window.SignalWindow.log.info('Start idle detector');
|
||||
window.SignalContext.log.info('Start idle detector');
|
||||
this._scheduleNextCallback();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ class IdleDetector extends EventEmitter {
|
|||
return;
|
||||
}
|
||||
|
||||
window.SignalWindow.log.info('Stop idle detector');
|
||||
window.SignalContext.log.info('Stop idle detector');
|
||||
this._clearScheduledCallbacks();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
async function doesDatabaseExist() {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'Checking for the existence of IndexedDB data...'
|
||||
);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -22,7 +22,7 @@ async function doesDatabaseExist() {
|
|||
let existed = true;
|
||||
|
||||
setTimeout(() => {
|
||||
window.SignalWindow.log.warn(
|
||||
window.SignalContext.log.warn(
|
||||
'doesDatabaseExist: Timed out attempting to check IndexedDB status'
|
||||
);
|
||||
return resolve(false);
|
||||
|
@ -43,7 +43,7 @@ async function doesDatabaseExist() {
|
|||
}
|
||||
|
||||
function removeDatabase() {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
`Deleting IndexedDB database '${Whisper.Database.id}'`
|
||||
);
|
||||
window.indexedDB.deleteDatabase(Whisper.Database.id);
|
||||
|
|
|
@ -45,7 +45,7 @@ exports.processNext = async ({
|
|||
}
|
||||
);
|
||||
} catch (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'processNext error:',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
a2 = args[1],
|
||||
a3 = args[2];
|
||||
const logError = function (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'Model caught error triggering',
|
||||
name,
|
||||
'event:',
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
}
|
||||
|
||||
async function run() {
|
||||
window.SignalWindow.log.info('Rotating signed prekey...');
|
||||
window.SignalContext.log.info('Rotating signed prekey...');
|
||||
try {
|
||||
await getAccountManager().rotateSignedPreKey();
|
||||
scheduleNextRotation();
|
||||
setTimeoutForNextRun();
|
||||
} catch (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'rotateSignedPrekey() failed. Trying again in five minutes'
|
||||
);
|
||||
setTimeout(setTimeoutForNextRun, 5 * 60 * 1000);
|
||||
|
@ -38,7 +38,7 @@
|
|||
if (navigator.onLine) {
|
||||
run();
|
||||
} else {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'We are offline; keys will be rotated when we are next online'
|
||||
);
|
||||
const listener = () => {
|
||||
|
@ -53,7 +53,7 @@
|
|||
const now = Date.now();
|
||||
const time = storage.get('nextSignedKeyRotationTime', now);
|
||||
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'Next signed key rotation scheduled for',
|
||||
new Date(time).toISOString()
|
||||
);
|
||||
|
@ -71,7 +71,7 @@
|
|||
Whisper.RotateSignedPreKeyListener = {
|
||||
init(events, newVersion) {
|
||||
if (initComplete) {
|
||||
window.SignalWindow.log.info(
|
||||
window.SignalContext.log.info(
|
||||
'Rotate signed prekey listener: Already initialized'
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
try {
|
||||
cb();
|
||||
} catch (error) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'ReactWrapperView.update error:',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
|
|
|
@ -55,12 +55,12 @@ window.Whisper.events = {
|
|||
|
||||
before(async () => {
|
||||
try {
|
||||
window.SignalWindow.log.info('Initializing SQL in renderer');
|
||||
window.SignalContext.log.info('Initializing SQL in renderer');
|
||||
const isTesting = true;
|
||||
await window.Signal.Data.startInRenderer(isTesting);
|
||||
window.SignalWindow.log.info('SQL initialized in renderer');
|
||||
window.SignalContext.log.info('SQL initialized in renderer');
|
||||
} catch (err) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'SQL failed to initialize',
|
||||
err && err.stack ? err.stack : err
|
||||
);
|
||||
|
|
18
preload.js
18
preload.js
|
@ -16,14 +16,9 @@ try {
|
|||
const { parseIntWithFallback } = require('./ts/util/parseIntWithFallback');
|
||||
|
||||
// It is important to call this as early as possible
|
||||
require('./ts/windows/context');
|
||||
const { SignalContext } = require('./ts/windows/context');
|
||||
|
||||
const {
|
||||
getEnvironment,
|
||||
setEnvironment,
|
||||
parseEnvironment,
|
||||
Environment,
|
||||
} = require('./ts/environment');
|
||||
const { getEnvironment, Environment } = require('./ts/environment');
|
||||
const ipc = electron.ipcRenderer;
|
||||
|
||||
const { remote } = electron;
|
||||
|
@ -31,8 +26,6 @@ try {
|
|||
|
||||
const config = require('url').parse(window.location.toString(), true).query;
|
||||
|
||||
setEnvironment(parseEnvironment(config.environment));
|
||||
|
||||
const log = require('./ts/logging/log');
|
||||
|
||||
let title = config.name;
|
||||
|
@ -107,8 +100,6 @@ try {
|
|||
}
|
||||
};
|
||||
|
||||
const localeMessages = ipc.sendSync('locale-data');
|
||||
|
||||
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
||||
|
||||
let connectStartTime = 0;
|
||||
|
@ -354,8 +345,6 @@ try {
|
|||
|
||||
// We pull these dependencies in now, from here, because they have Node.js dependencies
|
||||
|
||||
require('./ts/logging/set_up_renderer_logging').initialize();
|
||||
|
||||
if (config.proxyUrl) {
|
||||
log.info('Using provided proxy url');
|
||||
}
|
||||
|
@ -413,11 +402,10 @@ try {
|
|||
window.PQueue = require('p-queue').default;
|
||||
|
||||
const Signal = require('./js/modules/signal');
|
||||
const { setupI18n } = require('./ts/util/setupI18n');
|
||||
const Attachments = require('./app/attachments');
|
||||
|
||||
const { locale } = config;
|
||||
window.i18n = setupI18n(locale, localeMessages);
|
||||
window.i18n = SignalContext.i18n;
|
||||
window.moment.updateLocale(locale, {
|
||||
relativeTime: {
|
||||
s: window.i18n('timestamp_s'),
|
||||
|
|
|
@ -42,7 +42,7 @@ export const UploadStage: React.ComponentType = () => {
|
|||
actions.setPackMeta(packMeta);
|
||||
history.push('/share');
|
||||
} catch (e) {
|
||||
window.SignalWindow.log.error('Error uploading image:', e);
|
||||
window.SignalContext.log.error('Error uploading image:', e);
|
||||
actions.addToast({
|
||||
key: 'StickerCreator--Toasts--errorUploading',
|
||||
subs: [e.message],
|
||||
|
|
|
@ -58,7 +58,7 @@ const InnerGrid = SortableContainer(
|
|||
const stickerImage = await processStickerImage(path);
|
||||
actions.addImageData(stickerImage);
|
||||
} catch (e) {
|
||||
window.SignalWindow.log.error('Error processing image:', e);
|
||||
window.SignalContext.log.error('Error processing image:', e);
|
||||
actions.removeSticker(path);
|
||||
actions.addToast({
|
||||
key:
|
||||
|
|
|
@ -66,12 +66,12 @@ before(async () => {
|
|||
|
||||
await deleteIndexedDB();
|
||||
try {
|
||||
window.SignalWindow.log.info('Initializing SQL in renderer');
|
||||
window.SignalContext.log.info('Initializing SQL in renderer');
|
||||
const isTesting = true;
|
||||
await window.Signal.Data.startInRenderer(isTesting);
|
||||
window.SignalWindow.log.info('SQL initialized in renderer');
|
||||
window.SignalContext.log.info('SQL initialized in renderer');
|
||||
} catch (err) {
|
||||
window.SignalWindow.log.error(
|
||||
window.SignalContext.log.error(
|
||||
'SQL failed to initialize',
|
||||
err && err.stack ? err.stack : err
|
||||
);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
const chai = require('chai');
|
||||
const chaiAsPromised = require('chai-as-promised');
|
||||
|
||||
const { Crypto } = require('../ts/context/Crypto');
|
||||
const { setEnvironment, Environment } = require('../ts/environment');
|
||||
const { Context: SignalContext } = require('../ts/context');
|
||||
const { isValidGuid } = require('../ts/util/isValidGuid');
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
|
@ -18,8 +18,8 @@ const storageMap = new Map();
|
|||
|
||||
// To replicate logic we have on the client side
|
||||
global.window = {
|
||||
SignalContext: undefined,
|
||||
SignalWindow: {
|
||||
SignalContext: {
|
||||
crypto: new Crypto(),
|
||||
log: {
|
||||
info: (...args) => console.log(...args),
|
||||
warn: (...args) => console.warn(...args),
|
||||
|
@ -34,21 +34,6 @@ global.window = {
|
|||
isValidGuid,
|
||||
};
|
||||
|
||||
const fakeIPC = {
|
||||
sendSync(channel) {
|
||||
// See `ts/context/NativeThemeListener.ts`
|
||||
if (channel === 'native-theme:init') {
|
||||
return { shouldUseDarkColors: true };
|
||||
}
|
||||
|
||||
throw new Error(`Unsupported sendSync channel: ${channel}`);
|
||||
},
|
||||
|
||||
on() {},
|
||||
};
|
||||
|
||||
global.window.SignalContext = new SignalContext(fakeIPC);
|
||||
|
||||
// For ducks/network.getEmptyState()
|
||||
global.navigator = {};
|
||||
global.WebSocket = {};
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
const { bytes } = window.SignalContext;
|
||||
import { Bytes } from './context/Bytes';
|
||||
|
||||
const bytes = window.SignalContext?.bytes || new Bytes();
|
||||
|
||||
export function fromBase64(value: string): Uint8Array {
|
||||
return bytes.fromBase64(value);
|
||||
|
|
|
@ -24,7 +24,7 @@ type SystemThemeType = 'dark' | 'light';
|
|||
|
||||
export type SystemThemeHolder = { systemTheme: SystemThemeType };
|
||||
|
||||
type NativeThemeType = {
|
||||
export type NativeThemeType = {
|
||||
getSystemTheme: () => SystemThemeType;
|
||||
subscribe: (fn: Callback) => void;
|
||||
update: () => SystemThemeType;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { Bytes } from './Bytes';
|
||||
import { Crypto } from './Crypto';
|
||||
import { Timers } from './Timers';
|
||||
import {
|
||||
createNativeThemeListener,
|
||||
MinimalIPC,
|
||||
} from './createNativeThemeListener';
|
||||
|
||||
export class Context {
|
||||
public readonly bytes = new Bytes();
|
||||
|
||||
public readonly crypto = new Crypto();
|
||||
|
||||
public readonly timers = new Timers();
|
||||
|
||||
public readonly nativeThemeListener;
|
||||
|
||||
constructor(private readonly ipc: MinimalIPC) {
|
||||
this.nativeThemeListener = createNativeThemeListener(ipc, window);
|
||||
}
|
||||
|
||||
setIsCallActive(isCallActive: boolean): void {
|
||||
this.ipc.send('set-is-call-active', isCallActive);
|
||||
}
|
||||
}
|
|
@ -100,8 +100,8 @@ function logAtLevel(level: LogLevel, ...args: ReadonlyArray<unknown>): void {
|
|||
|
||||
log.setLogAtLevel(logAtLevel);
|
||||
|
||||
window.SignalWindow = window.SignalWindow || {};
|
||||
window.SignalWindow.log = {
|
||||
window.SignalContext = window.SignalContext || {};
|
||||
window.SignalContext.log = {
|
||||
fatal: log.fatal,
|
||||
error: log.error,
|
||||
warn: log.warn,
|
||||
|
|
|
@ -322,7 +322,7 @@ class NotificationService extends EventEmitter {
|
|||
}
|
||||
|
||||
public clear(): void {
|
||||
window.SignalWindow.log.info('Removing notification');
|
||||
window.SignalContext.log.info('Removing notification');
|
||||
this.notificationData = null;
|
||||
this.update();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ function buildAvatarUpdater({ field }: { field: 'avatar' | 'profileAvatar' }) {
|
|||
const { hash, path } = avatar;
|
||||
const exists = await doesAttachmentExist(path);
|
||||
if (!exists) {
|
||||
window.SignalWindow.log.warn(
|
||||
window.SignalContext.log.warn(
|
||||
`Conversation.buildAvatarUpdater: attachment ${path} did not exist`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -14058,14 +14058,14 @@
|
|||
{
|
||||
"rule": "DOM-innerHTML",
|
||||
"path": "ts/windows/loading/start.js",
|
||||
"line": " message.innerHTML = window.SignalWindow.i18n('optimizingApplication');",
|
||||
"line": " message.innerHTML = window.SignalContext.i18n('optimizingApplication');",
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2021-09-17T21:02:59.414Z"
|
||||
},
|
||||
{
|
||||
"rule": "DOM-innerHTML",
|
||||
"path": "ts/windows/loading/start.ts",
|
||||
"line": " message.innerHTML = window.SignalWindow.i18n('optimizingApplication');",
|
||||
"line": " message.innerHTML = window.SignalContext.i18n('optimizingApplication');",
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2021-09-17T21:02:59.414Z"
|
||||
}
|
||||
|
|
22
ts/window.d.ts
vendored
22
ts/window.d.ts
vendored
|
@ -10,6 +10,7 @@ import moment from 'moment';
|
|||
import PQueue from 'p-queue/dist';
|
||||
import { Ref } from 'react';
|
||||
import { imageToBlurHash } from './util/imageToBlurHash';
|
||||
import type { ParsedUrlQuery } from 'querystring';
|
||||
import * as Util from './util';
|
||||
import {
|
||||
ConversationModelCollectionType,
|
||||
|
@ -96,7 +97,6 @@ import { MIMEType } from './types/MIME';
|
|||
import { DownloadedAttachmentType } from './types/Attachment';
|
||||
import { ElectronLocaleType } from './util/mapToSupportLocale';
|
||||
import { SignalProtocolStore } from './SignalProtocolStore';
|
||||
import { Context as SignalContext } from './context';
|
||||
import { StartupQueue } from './util/StartupQueue';
|
||||
import { SocketStatus } from './types/SocketStatus';
|
||||
import SyncRequest from './textsecure/SyncRequest';
|
||||
|
@ -111,8 +111,7 @@ import { QualifiedAddress } from './types/QualifiedAddress';
|
|||
import { CI } from './CI';
|
||||
import { IPCEventsType, IPCEventsValuesType } from './util/createIPCEvents';
|
||||
import { ConversationView } from './views/conversation_view';
|
||||
import { LoggerType } from './types/Logging';
|
||||
import { SettingType } from './util/preload';
|
||||
import type { SignalContextType } from './windows/context';
|
||||
|
||||
export { Long } from 'long';
|
||||
|
||||
|
@ -462,7 +461,6 @@ declare global {
|
|||
};
|
||||
challengeHandler: ChallengeHandler;
|
||||
};
|
||||
SignalContext: SignalContext;
|
||||
|
||||
ConversationController: ConversationController;
|
||||
Events: IPCEventsType;
|
||||
|
@ -489,21 +487,7 @@ declare global {
|
|||
RETRY_DELAY: boolean;
|
||||
|
||||
// Context Isolation
|
||||
SignalWindow: {
|
||||
Settings: {
|
||||
themeSetting: SettingType<IPCEventsValuesType['themeSetting']>;
|
||||
waitForChange: () => Promise<void>;
|
||||
};
|
||||
config: string;
|
||||
context: SignalContext;
|
||||
getAppInstance: () => string | undefined;
|
||||
getEnvironment: () => string;
|
||||
getNodeVersion: () => string;
|
||||
getVersion: () => string;
|
||||
i18n: LocalizerType;
|
||||
log: LoggerType;
|
||||
renderWindow: () => void;
|
||||
};
|
||||
SignalContext: SignalContextType;
|
||||
}
|
||||
|
||||
// We want to extend `Error`, so we need an interface.
|
||||
|
|
|
@ -5,18 +5,15 @@ import React from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
|
||||
import { SignalWindow } from '../configure';
|
||||
import { SignalContext } from '../context';
|
||||
import { About } from '../../components/About';
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', {
|
||||
...SignalWindow,
|
||||
contextBridge.exposeInMainWorld('SignalContext', {
|
||||
...SignalContext,
|
||||
renderWindow: () => {
|
||||
const environmentText: Array<string> = [SignalWindow.getEnvironment()];
|
||||
const environmentText: Array<string> = [SignalContext.getEnvironment()];
|
||||
|
||||
const appInstance = SignalWindow.getAppInstance();
|
||||
const appInstance = SignalContext.getAppInstance();
|
||||
if (appInstance) {
|
||||
environmentText.push(appInstance);
|
||||
}
|
||||
|
@ -25,8 +22,8 @@ contextBridge.exposeInMainWorld('SignalWindow', {
|
|||
React.createElement(About, {
|
||||
closeAbout: () => ipcRenderer.send('close-about'),
|
||||
environment: environmentText.join(' - '),
|
||||
i18n: SignalWindow.i18n,
|
||||
version: SignalWindow.getVersion(),
|
||||
i18n: SignalContext.i18n,
|
||||
version: SignalContext.getVersion(),
|
||||
}),
|
||||
document.getElementById('app')
|
||||
);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
async function applyTheme() {
|
||||
const theme = await window.SignalWindow.Settings.themeSetting.getValue();
|
||||
const theme = await window.SignalContext.Settings.themeSetting.getValue();
|
||||
document.body.classList.remove('light-theme');
|
||||
document.body.classList.remove('dark-theme');
|
||||
document.body.classList.add(
|
||||
`${
|
||||
theme === 'system'
|
||||
? window.SignalWindow.context.nativeThemeListener.getSystemTheme()
|
||||
? window.SignalContext.nativeThemeListener.getSystemTheme()
|
||||
: theme
|
||||
}-theme`
|
||||
);
|
||||
|
@ -18,7 +18,7 @@ async function applyThemeLoop() {
|
|||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await window.SignalWindow.Settings.waitForChange();
|
||||
await window.SignalContext.Settings.waitForChange();
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await applyTheme();
|
||||
|
@ -28,6 +28,6 @@ async function applyThemeLoop() {
|
|||
applyTheme();
|
||||
applyThemeLoop();
|
||||
|
||||
window.SignalWindow.context.nativeThemeListener.subscribe(() => {
|
||||
window.SignalContext.nativeThemeListener.subscribe(() => {
|
||||
applyTheme();
|
||||
});
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2018-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import url from 'url';
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import {
|
||||
getEnvironment,
|
||||
parseEnvironment,
|
||||
setEnvironment,
|
||||
} from '../environment';
|
||||
import { strictAssert } from '../util/assert';
|
||||
import { createSetting } from '../util/preload';
|
||||
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
|
||||
import { waitForSettingsChange } from './waitForSettingsChange';
|
||||
|
||||
const config = url.parse(window.location.toString(), true).query;
|
||||
const { locale } = config;
|
||||
strictAssert(locale, 'locale could not be parsed from config');
|
||||
strictAssert(typeof locale === 'string', 'locale is not a string');
|
||||
|
||||
const localeMessages = ipcRenderer.sendSync('locale-data');
|
||||
setEnvironment(parseEnvironment(config.environment));
|
||||
|
||||
strictAssert(Boolean(window.SignalContext), 'context must be defined');
|
||||
|
||||
initializeLogging();
|
||||
|
||||
export const SignalWindow = {
|
||||
Settings: {
|
||||
themeSetting: createSetting('themeSetting', { setter: false }),
|
||||
waitForChange: waitForSettingsChange,
|
||||
},
|
||||
config,
|
||||
context: window.SignalContext,
|
||||
getAppInstance: (): string | undefined =>
|
||||
config.appInstance ? String(config.appInstance) : undefined,
|
||||
getEnvironment,
|
||||
getNodeVersion: (): string => String(config.node_version),
|
||||
getVersion: (): string => String(config.version),
|
||||
i18n: setupI18n(locale, localeMessages),
|
||||
log: window.SignalWindow.log,
|
||||
};
|
|
@ -1,8 +1,83 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import url from 'url';
|
||||
import type { ParsedUrlQuery } from 'querystring';
|
||||
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';
|
||||
import { Bytes } from '../context/Bytes';
|
||||
import { Crypto } from '../context/Crypto';
|
||||
import { Timers } from '../context/Timers';
|
||||
|
||||
import { Context } from '../context';
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import {
|
||||
getEnvironment,
|
||||
parseEnvironment,
|
||||
setEnvironment,
|
||||
} from '../environment';
|
||||
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 { createNativeThemeListener } from '../context/createNativeThemeListener';
|
||||
|
||||
window.SignalContext = new Context(ipc);
|
||||
const config = url.parse(window.location.toString(), true).query;
|
||||
const { locale } = config;
|
||||
strictAssert(locale, 'locale could not be parsed from config');
|
||||
strictAssert(typeof locale === 'string', 'locale is not a string');
|
||||
|
||||
const localeMessages = ipcRenderer.sendSync('locale-data');
|
||||
setEnvironment(parseEnvironment(config.environment));
|
||||
|
||||
strictAssert(Boolean(window.SignalContext), 'context must be defined');
|
||||
|
||||
initializeLogging();
|
||||
|
||||
export type SignalContextType = {
|
||||
bytes: Bytes;
|
||||
crypto: Crypto;
|
||||
timers: Timers;
|
||||
nativeThemeListener: NativeThemeType;
|
||||
setIsCallActive: (isCallActive: boolean) => unknown;
|
||||
|
||||
Settings: {
|
||||
themeSetting: SettingType<IPCEventsValuesType['themeSetting']>;
|
||||
waitForChange: () => Promise<void>;
|
||||
};
|
||||
config: ParsedUrlQuery;
|
||||
getAppInstance: () => string | undefined;
|
||||
getEnvironment: () => string;
|
||||
getNodeVersion: () => string;
|
||||
getVersion: () => string;
|
||||
i18n: LocalizerType;
|
||||
log: LoggerType;
|
||||
renderWindow?: () => void;
|
||||
};
|
||||
|
||||
export const SignalContext: SignalContextType = {
|
||||
Settings: {
|
||||
themeSetting: createSetting('themeSetting', { setter: false }),
|
||||
waitForChange: waitForSettingsChange,
|
||||
},
|
||||
bytes: new Bytes(),
|
||||
config,
|
||||
crypto: new Crypto(),
|
||||
getAppInstance: (): string | undefined =>
|
||||
config.appInstance ? String(config.appInstance) : undefined,
|
||||
getEnvironment,
|
||||
getNodeVersion: (): string => String(config.node_version),
|
||||
getVersion: (): string => String(config.version),
|
||||
i18n: setupI18n(locale, localeMessages),
|
||||
log: window.SignalContext.log,
|
||||
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
||||
setIsCallActive(isCallActive: boolean): void {
|
||||
ipcRenderer.send('set-is-call-active', isCallActive);
|
||||
},
|
||||
timers: new Timers(),
|
||||
};
|
||||
|
||||
window.SignalContext = SignalContext;
|
||||
|
|
|
@ -5,19 +5,16 @@ import React from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
|
||||
import { SignalWindow } from '../configure';
|
||||
import { SignalContext } from '../context';
|
||||
import { DebugLogWindow } from '../../components/DebugLogWindow';
|
||||
import * as debugLog from '../../logging/debuglogs';
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', {
|
||||
...SignalWindow,
|
||||
contextBridge.exposeInMainWorld('SignalContext', {
|
||||
...SignalContext,
|
||||
renderWindow: () => {
|
||||
const environmentText: Array<string> = [SignalWindow.getEnvironment()];
|
||||
const environmentText: Array<string> = [SignalContext.getEnvironment()];
|
||||
|
||||
const appInstance = SignalWindow.getAppInstance();
|
||||
const appInstance = SignalContext.getAppInstance();
|
||||
if (appInstance) {
|
||||
environmentText.push(appInstance);
|
||||
}
|
||||
|
@ -27,15 +24,15 @@ contextBridge.exposeInMainWorld('SignalWindow', {
|
|||
closeWindow: () => ipcRenderer.send('close-debug-log'),
|
||||
downloadLog: (logText: string) =>
|
||||
ipcRenderer.send('show-debug-log-save-dialog', logText),
|
||||
i18n: SignalWindow.i18n,
|
||||
i18n: SignalContext.i18n,
|
||||
fetchLogs() {
|
||||
return debugLog.fetch(
|
||||
SignalWindow.getNodeVersion(),
|
||||
SignalWindow.getVersion()
|
||||
SignalContext.getNodeVersion(),
|
||||
SignalContext.getVersion()
|
||||
);
|
||||
},
|
||||
uploadLogs(logs: string) {
|
||||
return debugLog.upload(logs, SignalWindow.getVersion());
|
||||
return debugLog.upload(logs, SignalContext.getVersion());
|
||||
},
|
||||
}),
|
||||
document.getElementById('app')
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
window.SignalWindow.renderWindow();
|
||||
if (window.SignalContext.renderWindow) {
|
||||
window.SignalContext.renderWindow();
|
||||
} else {
|
||||
window.SignalContext.log.error('renderWindow is undefined!');
|
||||
}
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
import { SignalContext } from '../context';
|
||||
|
||||
import { SignalWindow } from '../configure';
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', SignalWindow);
|
||||
contextBridge.exposeInMainWorld('SignalContext', SignalContext);
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
|
||||
const message = document.getElementById('message');
|
||||
if (message) {
|
||||
message.innerHTML = window.SignalWindow.i18n('optimizingApplication');
|
||||
message.innerHTML = window.SignalContext.i18n('optimizingApplication');
|
||||
}
|
||||
|
|
|
@ -5,11 +5,9 @@ import React from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
import { SignalContext } from '../context';
|
||||
|
||||
import { createSetting } from '../../util/preload';
|
||||
import { SignalWindow } from '../configure';
|
||||
import { PermissionsPopup } from '../../components/PermissionsPopup';
|
||||
|
||||
const mediaCameraPermissions = createSetting('mediaCameraPermissions', {
|
||||
|
@ -24,21 +22,21 @@ contextBridge.exposeInMainWorld(
|
|||
window.SignalContext.nativeThemeListener
|
||||
);
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', {
|
||||
...SignalWindow,
|
||||
contextBridge.exposeInMainWorld('SignalContext', {
|
||||
...SignalContext,
|
||||
renderWindow: () => {
|
||||
const forCalling = SignalWindow.config.forCalling === 'true';
|
||||
const forCamera = SignalWindow.config.forCamera === 'true';
|
||||
const forCalling = SignalContext.config.forCalling === 'true';
|
||||
const forCamera = SignalContext.config.forCamera === 'true';
|
||||
|
||||
let message;
|
||||
if (forCalling) {
|
||||
if (forCamera) {
|
||||
message = SignalWindow.i18n('videoCallingPermissionNeeded');
|
||||
message = SignalContext.i18n('videoCallingPermissionNeeded');
|
||||
} else {
|
||||
message = SignalWindow.i18n('audioCallingPermissionNeeded');
|
||||
message = SignalContext.i18n('audioCallingPermissionNeeded');
|
||||
}
|
||||
} else {
|
||||
message = SignalWindow.i18n('audioPermissionNeeded');
|
||||
message = SignalContext.i18n('audioPermissionNeeded');
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
|
@ -47,7 +45,7 @@ contextBridge.exposeInMainWorld('SignalWindow', {
|
|||
|
||||
ReactDOM.render(
|
||||
React.createElement(PermissionsPopup, {
|
||||
i18n: SignalWindow.i18n,
|
||||
i18n: SignalContext.i18n,
|
||||
message,
|
||||
onAccept: () => {
|
||||
if (!forCamera) {
|
||||
|
|
|
@ -5,18 +5,15 @@ import React from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
|
||||
import { SignalWindow } from '../configure';
|
||||
import { SignalContext } from '../context';
|
||||
import { CallingScreenSharingController } from '../../components/CallingScreenSharingController';
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', SignalWindow);
|
||||
contextBridge.exposeInMainWorld('SignalContext', SignalContext);
|
||||
|
||||
function renderScreenSharingController(presentedSourceName: string): void {
|
||||
ReactDOM.render(
|
||||
React.createElement(CallingScreenSharingController, {
|
||||
i18n: SignalWindow.i18n,
|
||||
i18n: SignalContext.i18n,
|
||||
onCloseController: () =>
|
||||
ipcRenderer.send('close-screen-share-controller'),
|
||||
onStopSharing: () => ipcRenderer.send('stop-screen-share'),
|
||||
|
|
|
@ -5,10 +5,7 @@ import React from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// It is important to call this as early as possible
|
||||
import '../context';
|
||||
|
||||
import { SignalWindow } from '../configure';
|
||||
import { SignalContext } from '../context';
|
||||
import * as Settings from '../../types/Settings';
|
||||
import { Preferences } from '../../components/Preferences';
|
||||
import {
|
||||
|
@ -260,7 +257,7 @@ const renderPreferences = async () => {
|
|||
editCustomColor: ipcEditCustomColor,
|
||||
getConversationsWithCustomColor: ipcGetConversationsWithCustomColor,
|
||||
initialSpellCheckSetting:
|
||||
SignalWindow.config.appStartInitialSpellcheckSetting === 'true',
|
||||
SignalContext.config.appStartInitialSpellcheckSetting === 'true',
|
||||
makeSyncRequest: ipcMakeSyncRequest,
|
||||
removeCustomColor: ipcRemoveCustomColor,
|
||||
removeCustomColorOnConversations: ipcRemoveCustomColorOnConversations,
|
||||
|
@ -277,7 +274,7 @@ const renderPreferences = async () => {
|
|||
isPhoneNumberSharingSupported,
|
||||
isSyncSupported: !isSyncNotSupported,
|
||||
isSystemTraySupported: Settings.isSystemTraySupported(
|
||||
SignalWindow.getVersion()
|
||||
SignalContext.getVersion()
|
||||
),
|
||||
|
||||
// Change handlers
|
||||
|
@ -343,7 +340,7 @@ const renderPreferences = async () => {
|
|||
// rerender.
|
||||
onZoomFactorChange: settingZoomFactor.setValue,
|
||||
|
||||
i18n: SignalWindow.i18n,
|
||||
i18n: SignalContext.i18n,
|
||||
};
|
||||
|
||||
function reRender<Value>(f: (value: Value) => Promise<Value>) {
|
||||
|
@ -361,7 +358,7 @@ const renderPreferences = async () => {
|
|||
|
||||
ipcRenderer.on('preferences-changed', () => renderPreferences());
|
||||
|
||||
contextBridge.exposeInMainWorld('SignalWindow', {
|
||||
...SignalWindow,
|
||||
contextBridge.exposeInMainWorld('SignalContext', {
|
||||
...SignalContext,
|
||||
renderWindow: renderPreferences,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue