2019-05-16 22:14:06 +00:00
|
|
|
/* global Whisper, window */
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
/* eslint-disable global-require, no-inner-declarations */
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
try {
|
|
|
|
const electron = require('electron');
|
|
|
|
const semver = require('semver');
|
|
|
|
const curve = require('curve25519-n');
|
2020-03-05 21:14:58 +00:00
|
|
|
const _ = require('lodash');
|
2020-02-27 01:53:39 +00:00
|
|
|
const { installGetter, installSetter } = require('./preload_utils');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
const { remote } = electron;
|
|
|
|
const { app } = remote;
|
2020-03-19 17:57:50 +00:00
|
|
|
const { nativeTheme } = remote.require('electron');
|
2018-06-02 00:55:35 +00:00
|
|
|
|
2020-04-15 23:12:28 +00:00
|
|
|
// Derive profile key versions, then use those to fetch versioned profiles from server
|
|
|
|
window.VERSIONED_PROFILE_FETCH = false;
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.PROTO_ROOT = 'protos';
|
|
|
|
const config = require('url').parse(window.location.toString(), true).query;
|
2019-05-16 22:32:38 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
let title = config.name;
|
|
|
|
if (config.environment !== 'production') {
|
|
|
|
title += ` - ${config.environment}`;
|
|
|
|
}
|
|
|
|
if (config.appInstance) {
|
|
|
|
title += ` - ${config.appInstance}`;
|
|
|
|
}
|
2019-05-16 22:32:38 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.platform = process.platform;
|
|
|
|
window.getTitle = () => title;
|
|
|
|
window.getEnvironment = () => config.environment;
|
|
|
|
window.getAppInstance = () => config.appInstance;
|
|
|
|
window.getVersion = () => config.version;
|
|
|
|
window.getExpiration = () => config.buildExpiration;
|
|
|
|
window.getNodeVersion = () => config.node_version;
|
|
|
|
window.getHostName = () => config.hostname;
|
|
|
|
window.getServerTrustRoot = () => config.serverTrustRoot;
|
2020-04-15 23:12:28 +00:00
|
|
|
window.getServerPublicParams = () => config.serverPublicParams;
|
2020-02-27 01:53:39 +00:00
|
|
|
window.isBehindProxy = () => Boolean(config.proxyUrl);
|
|
|
|
|
|
|
|
function setSystemTheme() {
|
2020-03-19 17:57:50 +00:00
|
|
|
window.systemTheme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
|
2019-05-16 22:32:38 +00:00
|
|
|
}
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
setSystemTheme();
|
|
|
|
|
|
|
|
window.subscribeToSystemThemeChange = fn => {
|
2020-03-19 17:57:50 +00:00
|
|
|
nativeTheme.on('updated', () => {
|
|
|
|
setSystemTheme();
|
|
|
|
fn();
|
|
|
|
});
|
2020-02-27 01:53:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
window.isBeforeVersion = (toCheck, baseVersion) => {
|
|
|
|
try {
|
|
|
|
return semver.lt(toCheck, baseVersion);
|
|
|
|
} catch (error) {
|
|
|
|
window.log.error(
|
|
|
|
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-07-20 21:52:52 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
const ipc = electron.ipcRenderer;
|
|
|
|
const localeMessages = ipc.sendSync('locale-data');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// We never do these in our code, so we'll prevent it everywhere
|
|
|
|
window.open = () => null;
|
|
|
|
// eslint-disable-next-line no-eval, no-multi-assign
|
|
|
|
window.eval = global.eval = () => null;
|
2018-05-19 01:21:02 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.drawAttention = () => {
|
|
|
|
window.log.info('draw attention');
|
|
|
|
ipc.send('draw-attention');
|
|
|
|
};
|
|
|
|
window.showWindow = () => {
|
|
|
|
window.log.info('show window');
|
|
|
|
ipc.send('show-window');
|
|
|
|
};
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setAutoHideMenuBar = autoHide =>
|
|
|
|
ipc.send('set-auto-hide-menu-bar', autoHide);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.setMenuBarVisibility = visibility =>
|
|
|
|
ipc.send('set-menu-bar-visibility', visibility);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.restart = () => {
|
|
|
|
window.log.info('restart');
|
|
|
|
ipc.send('restart');
|
|
|
|
};
|
2020-04-28 21:18:41 +00:00
|
|
|
window.shutdown = () => {
|
|
|
|
window.log.info('shutdown');
|
|
|
|
ipc.send('shutdown');
|
|
|
|
};
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.closeAbout = () => ipc.send('close-about');
|
|
|
|
window.readyForUpdates = () => ipc.send('ready-for-updates');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.updateTrayIcon = unreadCount =>
|
|
|
|
ipc.send('update-tray-icon', unreadCount);
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('set-up-as-new-device', () => {
|
|
|
|
Whisper.events.trigger('setupAsNewDevice');
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('set-up-as-standalone', () => {
|
|
|
|
Whisper.events.trigger('setupAsStandalone');
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// Settings-related events
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.showSettings = () => ipc.send('show-settings');
|
|
|
|
window.showPermissionsPopup = () => ipc.send('show-permissions-popup');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('show-keyboard-shortcuts', () => {
|
|
|
|
window.Events.showKeyboardShortcuts();
|
|
|
|
});
|
|
|
|
ipc.on('add-dark-overlay', () => {
|
|
|
|
window.Events.addDarkOverlay();
|
|
|
|
});
|
|
|
|
ipc.on('remove-dark-overlay', () => {
|
|
|
|
window.Events.removeDarkOverlay();
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('device-name', 'getDeviceName');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('theme-setting', 'getThemeSetting');
|
|
|
|
installSetter('theme-setting', 'setThemeSetting');
|
|
|
|
installGetter('hide-menu-bar', 'getHideMenuBar');
|
|
|
|
installSetter('hide-menu-bar', 'setHideMenuBar');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('notification-setting', 'getNotificationSetting');
|
|
|
|
installSetter('notification-setting', 'setNotificationSetting');
|
|
|
|
installGetter('audio-notification', 'getAudioNotification');
|
|
|
|
installSetter('audio-notification', 'setAudioNotification');
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
installGetter('spell-check', 'getSpellCheck');
|
|
|
|
installSetter('spell-check', 'setSpellCheck');
|
2018-07-19 01:46:12 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getMediaPermissions = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('get-success-media-permissions', (_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
return resolve(value);
|
|
|
|
});
|
|
|
|
ipc.send('get-media-permissions');
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.getBuiltInImages = () =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
ipc.once('get-success-built-in-images', (_event, error, value) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(new Error(error));
|
|
|
|
}
|
2019-10-04 18:06:17 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
return resolve(value);
|
|
|
|
});
|
|
|
|
ipc.send('get-built-in-images');
|
2019-10-04 18:06:17 +00:00
|
|
|
});
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
installGetter('is-primary', 'isPrimary');
|
|
|
|
installGetter('sync-request', 'getSyncRequest');
|
|
|
|
installGetter('sync-time', 'getLastSyncTime');
|
|
|
|
installSetter('sync-time', 'setLastSyncTime');
|
|
|
|
|
|
|
|
ipc.on('delete-all-data', () => {
|
|
|
|
const { deleteAllData } = window.Events;
|
|
|
|
if (deleteAllData) {
|
|
|
|
deleteAllData();
|
|
|
|
}
|
2019-10-04 18:06:17 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('show-sticker-pack', (_event, info) => {
|
|
|
|
const { packId, packKey } = info;
|
|
|
|
const { showStickerPack } = window.Events;
|
|
|
|
if (showStickerPack) {
|
|
|
|
showStickerPack(packId, packKey);
|
|
|
|
}
|
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('install-sticker-pack', (_event, info) => {
|
|
|
|
const { packId, packKey } = info;
|
|
|
|
const { installStickerPack } = window.Events;
|
|
|
|
if (installStickerPack) {
|
|
|
|
installStickerPack(packId, packKey);
|
|
|
|
}
|
|
|
|
});
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
ipc.on('get-ready-for-shutdown', async () => {
|
|
|
|
const { shutdown } = window.Events || {};
|
|
|
|
if (!shutdown) {
|
|
|
|
window.log.error('preload shutdown handler: shutdown method not found');
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
return;
|
|
|
|
}
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
try {
|
|
|
|
await shutdown();
|
|
|
|
ipc.send('now-ready-for-shutdown');
|
|
|
|
} catch (error) {
|
|
|
|
ipc.send(
|
|
|
|
'now-ready-for-shutdown',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.addSetupMenuItems = () => ipc.send('add-setup-menu-items');
|
|
|
|
window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// We pull these dependencies in now, from here, because they have Node.js dependencies
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
require('./js/logging');
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
if (config.proxyUrl) {
|
|
|
|
window.log.info('Using provided proxy url');
|
|
|
|
}
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.nodeSetImmediate = setImmediate;
|
2018-04-03 19:03:57 +00:00
|
|
|
|
2020-04-13 17:37:29 +00:00
|
|
|
window.textsecure = require('./ts/textsecure').default;
|
2019-08-19 22:26:45 +00:00
|
|
|
|
2020-04-13 17:37:29 +00:00
|
|
|
window.WebAPI = window.textsecure.WebAPI.initialize({
|
2020-02-27 01:53:39 +00:00
|
|
|
url: config.serverUrl,
|
2020-04-17 22:51:39 +00:00
|
|
|
cdnUrlObject: {
|
|
|
|
'0': config.cdnUrl0,
|
|
|
|
'2': config.cdnUrl2,
|
|
|
|
},
|
2020-02-27 01:53:39 +00:00
|
|
|
certificateAuthority: config.certificateAuthority,
|
|
|
|
contentProxyUrl: config.contentProxyUrl,
|
|
|
|
proxyUrl: config.proxyUrl,
|
|
|
|
version: config.version,
|
|
|
|
});
|
2019-08-19 22:26:45 +00:00
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
|
|
|
setInterval(() => {
|
|
|
|
window.nodeSetImmediate(() => {});
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
const { autoOrientImage } = require('./js/modules/auto_orient_image');
|
|
|
|
|
|
|
|
window.autoOrientImage = autoOrientImage;
|
|
|
|
window.dataURLToBlobSync = require('blueimp-canvas-to-blob');
|
|
|
|
window.emojiData = require('emoji-datasource');
|
|
|
|
window.filesize = require('filesize');
|
|
|
|
window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
|
|
|
window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat;
|
|
|
|
window.loadImage = require('blueimp-load-image');
|
|
|
|
window.getGuid = require('uuid/v4');
|
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
window.isValidGuid = maybeGuid =>
|
|
|
|
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(
|
|
|
|
maybeGuid
|
|
|
|
);
|
|
|
|
// https://stackoverflow.com/a/23299989
|
|
|
|
window.isValidE164 = maybeE164 => /^\+?[1-9]\d{1,14}$/.test(maybeE164);
|
|
|
|
|
|
|
|
window.normalizeUuids = (obj, paths, context) => {
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
paths.forEach(path => {
|
|
|
|
const val = _.get(obj, path);
|
|
|
|
if (val) {
|
|
|
|
if (!window.isValidGuid(val)) {
|
|
|
|
window.log.warn(
|
|
|
|
`Normalizing invalid uuid: ${val} at path ${path} in context "${context}"`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_.set(obj, path, val.toLowerCase());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
window.React = require('react');
|
|
|
|
window.ReactDOM = require('react-dom');
|
|
|
|
window.moment = require('moment');
|
|
|
|
window.PQueue = require('p-queue').default;
|
|
|
|
|
|
|
|
const Signal = require('./js/modules/signal');
|
|
|
|
const i18n = require('./js/modules/i18n');
|
|
|
|
const Attachments = require('./app/attachments');
|
|
|
|
|
|
|
|
const { locale } = config;
|
|
|
|
window.i18n = i18n.setup(locale, localeMessages);
|
|
|
|
window.moment.updateLocale(locale, {
|
|
|
|
relativeTime: {
|
|
|
|
s: window.i18n('timestamp_s'),
|
|
|
|
m: window.i18n('timestamp_m'),
|
|
|
|
h: window.i18n('timestamp_h'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
window.moment.locale(locale);
|
|
|
|
|
|
|
|
const userDataPath = app.getPath('userData');
|
|
|
|
window.baseAttachmentsPath = Attachments.getPath(userDataPath);
|
|
|
|
window.baseStickersPath = Attachments.getStickersPath(userDataPath);
|
|
|
|
window.baseTempPath = Attachments.getTempPath(userDataPath);
|
|
|
|
window.baseDraftPath = Attachments.getDraftPath(userDataPath);
|
|
|
|
window.Signal = Signal.setup({
|
|
|
|
Attachments,
|
|
|
|
userDataPath,
|
|
|
|
getRegionCode: () => window.storage.get('regionCode'),
|
|
|
|
logger: window.log,
|
|
|
|
});
|
|
|
|
|
|
|
|
function wrapWithPromise(fn) {
|
|
|
|
return (...args) => Promise.resolve(fn(...args));
|
|
|
|
}
|
|
|
|
const externalCurve = {
|
|
|
|
generateKeyPair: () => {
|
|
|
|
const { privKey, pubKey } = curve.generateKeyPair();
|
|
|
|
|
|
|
|
return {
|
2020-03-31 20:03:38 +00:00
|
|
|
privKey: window.Signal.Crypto.typedArrayToArrayBuffer(privKey),
|
|
|
|
pubKey: window.Signal.Crypto.typedArrayToArrayBuffer(pubKey),
|
2020-02-27 01:53:39 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
createKeyPair: incomingKey => {
|
|
|
|
const incomingKeyBuffer = Buffer.from(incomingKey);
|
|
|
|
const { privKey, pubKey } = curve.createKeyPair(incomingKeyBuffer);
|
|
|
|
|
|
|
|
return {
|
2020-03-31 20:03:38 +00:00
|
|
|
privKey: window.Signal.Crypto.typedArrayToArrayBuffer(privKey),
|
|
|
|
pubKey: window.Signal.Crypto.typedArrayToArrayBuffer(pubKey),
|
2020-02-27 01:53:39 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
calculateAgreement: (pubKey, privKey) => {
|
|
|
|
const pubKeyBuffer = Buffer.from(pubKey);
|
|
|
|
const privKeyBuffer = Buffer.from(privKey);
|
|
|
|
|
|
|
|
const buffer = curve.calculateAgreement(pubKeyBuffer, privKeyBuffer);
|
|
|
|
|
2020-03-31 20:03:38 +00:00
|
|
|
return window.Signal.Crypto.typedArrayToArrayBuffer(buffer);
|
2020-02-27 01:53:39 +00:00
|
|
|
},
|
|
|
|
verifySignature: (pubKey, message, signature) => {
|
|
|
|
const pubKeyBuffer = Buffer.from(pubKey);
|
|
|
|
const messageBuffer = Buffer.from(message);
|
|
|
|
const signatureBuffer = Buffer.from(signature);
|
|
|
|
|
|
|
|
const result = curve.verifySignature(
|
|
|
|
pubKeyBuffer,
|
|
|
|
messageBuffer,
|
|
|
|
signatureBuffer
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
calculateSignature: (privKey, message) => {
|
|
|
|
const privKeyBuffer = Buffer.from(privKey);
|
|
|
|
const messageBuffer = Buffer.from(message);
|
|
|
|
|
|
|
|
const buffer = curve.calculateSignature(privKeyBuffer, messageBuffer);
|
|
|
|
|
2020-03-31 20:03:38 +00:00
|
|
|
return window.Signal.Crypto.typedArrayToArrayBuffer(buffer);
|
2020-02-27 01:53:39 +00:00
|
|
|
},
|
|
|
|
validatePubKeyFormat: pubKey => {
|
|
|
|
const pubKeyBuffer = Buffer.from(pubKey);
|
|
|
|
|
|
|
|
return curve.validatePubKeyFormat(pubKeyBuffer);
|
|
|
|
},
|
2018-12-13 21:41:42 +00:00
|
|
|
};
|
2020-02-27 01:53:39 +00:00
|
|
|
externalCurve.ECDHE = externalCurve.calculateAgreement;
|
|
|
|
externalCurve.Ed25519Sign = externalCurve.calculateSignature;
|
|
|
|
externalCurve.Ed25519Verify = externalCurve.verifySignature;
|
|
|
|
const externalCurveAsync = {
|
|
|
|
generateKeyPair: wrapWithPromise(externalCurve.generateKeyPair),
|
|
|
|
createKeyPair: wrapWithPromise(externalCurve.createKeyPair),
|
|
|
|
calculateAgreement: wrapWithPromise(externalCurve.calculateAgreement),
|
|
|
|
verifySignature: async (...args) => {
|
|
|
|
// The async verifySignature function has a different signature than the
|
|
|
|
// sync function
|
|
|
|
const verifyFailed = externalCurve.verifySignature(...args);
|
|
|
|
if (verifyFailed) {
|
|
|
|
throw new Error('Invalid signature');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
calculateSignature: wrapWithPromise(externalCurve.calculateSignature),
|
|
|
|
validatePubKeyFormat: wrapWithPromise(externalCurve.validatePubKeyFormat),
|
|
|
|
ECDHE: wrapWithPromise(externalCurve.ECDHE),
|
|
|
|
Ed25519Sign: wrapWithPromise(externalCurve.Ed25519Sign),
|
|
|
|
Ed25519Verify: wrapWithPromise(externalCurve.Ed25519Verify),
|
|
|
|
};
|
|
|
|
window.libsignal = window.libsignal || {};
|
|
|
|
window.libsignal.externalCurve = externalCurve;
|
|
|
|
window.libsignal.externalCurveAsync = externalCurveAsync;
|
|
|
|
|
|
|
|
// Pulling these in separately since they access filesystem, electron
|
|
|
|
window.Signal.Backup = require('./js/modules/backup');
|
|
|
|
window.Signal.Debug = require('./js/modules/debug');
|
|
|
|
window.Signal.Logs = require('./js/modules/logs');
|
|
|
|
|
2020-03-20 21:00:11 +00:00
|
|
|
window.addEventListener('contextmenu', e => {
|
|
|
|
const editable = e.target.closest(
|
|
|
|
'textarea, input, [contenteditable="true"]'
|
|
|
|
);
|
|
|
|
const link = e.target.closest('a');
|
|
|
|
const selection = Boolean(window.getSelection().toString());
|
|
|
|
if (!editable && !selection && !link) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2020-02-27 01:53:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (config.environment === 'test') {
|
|
|
|
/* eslint-disable global-require, import/no-extraneous-dependencies */
|
|
|
|
window.test = {
|
|
|
|
fastGlob: require('fast-glob'),
|
|
|
|
normalizePath: require('normalize-path'),
|
|
|
|
fse: require('fs-extra'),
|
|
|
|
tmp: require('tmp'),
|
|
|
|
path: require('path'),
|
|
|
|
basePath: __dirname,
|
|
|
|
attachmentsPath: window.Signal.Migrations.attachmentsPath,
|
|
|
|
};
|
|
|
|
/* eslint-enable global-require, import/no-extraneous-dependencies */
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-03-03 00:09:46 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
if (console._log) {
|
|
|
|
console._log('preload error!', error.stack);
|
|
|
|
} else {
|
|
|
|
console.log('preload error!', error.stack);
|
|
|
|
}
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
2020-02-27 01:53:39 +00:00
|
|
|
throw error;
|
2018-12-13 21:41:42 +00:00
|
|
|
}
|
2020-02-27 01:53:39 +00:00
|
|
|
|
|
|
|
window.log.info('preload complete');
|