session-desktop/preload.js

164 lines
4.8 KiB
JavaScript
Raw Normal View History

2018-04-03 21:03:57 +02:00
/* global Whisper: false */
/* global window: false */
console.log('preload');
const electron = require('electron');
const { deferredToPromise } = require('./js/modules/deferred_to_promise');
const { app } = electron.remote;
window.PROTO_ROOT = 'protos';
window.config = require('url').parse(window.location.toString(), true).query;
window.wrapDeferred = deferredToPromise;
const ipc = electron.ipcRenderer;
window.config.localeMessages = ipc.sendSync('locale-data');
2018-04-27 23:25:04 +02:00
window.setBadgeCount = count => ipc.send('set-badge-count', count);
2018-04-03 21:03:57 +02:00
2018-05-24 18:32:18 +02:00
// We never do these in our code, so we'll prevent it everywhere
window.open = () => null;
2018-05-24 18:32:18 +02:00
// eslint-disable-next-line no-eval, no-multi-assign
window.eval = global.eval = () => null;
2018-04-03 21:03:57 +02:00
window.drawAttention = () => {
console.log('draw attention');
ipc.send('draw-attention');
};
window.showWindow = () => {
console.log('show window');
ipc.send('show-window');
};
window.setAutoHideMenuBar = autoHide =>
ipc.send('set-auto-hide-menu-bar', autoHide);
window.setMenuBarVisibility = visibility =>
ipc.send('set-menu-bar-visibility', visibility);
window.restart = () => {
console.log('restart');
ipc.send('restart');
};
2018-04-27 23:25:04 +02:00
window.closeAbout = () => ipc.send('close-about');
2018-04-03 21:03:57 +02:00
window.updateTrayIcon = unreadCount =>
ipc.send('update-tray-icon', unreadCount);
ipc.on('debug-log', () => {
Whisper.events.trigger('showDebugLog');
});
ipc.on('set-up-with-import', () => {
Whisper.events.trigger('setupWithImport');
});
ipc.on('set-up-as-new-device', () => {
Whisper.events.trigger('setupAsNewDevice');
});
ipc.on('set-up-as-standalone', () => {
Whisper.events.trigger('setupAsStandalone');
});
ipc.on('show-settings', () => {
Whisper.events.trigger('showSettings');
});
2018-04-27 23:25:04 +02:00
window.addSetupMenuItems = () => ipc.send('add-setup-menu-items');
2018-04-03 21:03:57 +02:00
2018-04-27 23:25:04 +02:00
window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
2018-04-03 21:03:57 +02:00
// We pull these dependencies in now, from here, because they have Node.js dependencies
require('./js/logging');
if (window.config.proxyUrl) {
console.log('using proxy url', window.config.proxyUrl);
}
window.nodeSetImmediate = setImmediate;
const { initialize: initializeWebAPI } = require('./js/modules/web_api');
window.WebAPI = initializeWebAPI({
url: window.config.serverUrl,
cdnUrl: window.config.cdnUrl,
certificateAuthority: window.config.certificateAuthority,
proxyUrl: window.config.proxyUrl,
});
2018-04-03 21:03:57 +02: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.EmojiPanel = require('emoji-panel');
2018-04-24 17:19:39 +02:00
window.filesize = require('filesize');
2018-04-03 21:03:57 +02:00
window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance();
2018-04-27 23:25:04 +02:00
window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat;
2018-04-03 21:03:57 +02:00
window.loadImage = require('blueimp-load-image');
// Note: when modifying this file, consider whether our React Components or Backbone Views
// will need these things to render in the Style Guide. If so, go update one of these
// two locations:
//
// 1) test/styleguide/legacy_bridge.js
2018-04-11 22:31:35 +02:00
// 2) ts/styleguide/StyleGuideUtil.js
window.React = require('react');
window.ReactDOM = require('react-dom');
window.moment = require('moment');
2018-04-03 21:03:57 +02:00
const Signal = require('./js/modules/signal');
const i18n = require('./js/modules/i18n');
const Attachments = require('./app/attachments');
const { locale, localeMessages } = window.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);
window.Signal = Signal.setup({
Attachments,
userDataPath: app.getPath('userData'),
getRegionCode: () => window.storage.get('regionCode'),
});
2018-04-03 21:03:57 +02:00
// Pulling these in separately since they access filesystem, electron
2018-04-03 21:03:57 +02:00
window.Signal.Backup = require('./js/modules/backup');
window.Signal.Debug = require('./js/modules/debug');
window.Signal.Logs = require('./js/modules/logs');
// We pull this in last, because the native module involved appears to be sensitive to
// /tmp mounted as noexec on Linux.
require('./js/spell_check');
2018-04-20 23:55:33 +02:00
if (window.config.environment === 'test') {
/* eslint-disable global-require, import/no-extraneous-dependencies */
window.test = {
glob: require('glob'),
fse: require('fs-extra'),
tmp: require('tmp'),
path: require('path'),
basePath: __dirname,
attachmentsPath: window.Signal.Migrations.attachmentsPath,
2018-04-20 23:55:33 +02:00
};
/* eslint-enable global-require, import/no-extraneous-dependencies */
}