Remove window.config in favor of window.getXXX() accessors
This commit is contained in:
parent
d5ead799ce
commit
1c23c6a9d7
10 changed files with 45 additions and 49 deletions
|
@ -29,20 +29,11 @@
|
||||||
window.onInvalidStateError = e => console.log(e);
|
window.onInvalidStateError = e => console.log(e);
|
||||||
|
|
||||||
console.log('background page reloaded');
|
console.log('background page reloaded');
|
||||||
console.log('environment:', window.config.environment);
|
console.log('environment:', window.getEnvironment());
|
||||||
|
|
||||||
let initialLoadComplete = false;
|
let initialLoadComplete = false;
|
||||||
window.owsDesktopApp = {};
|
window.owsDesktopApp = {};
|
||||||
|
window.document.title = window.getTitle();
|
||||||
let title = window.config.name;
|
|
||||||
if (window.config.environment !== 'production') {
|
|
||||||
title += ` - ${window.config.environment}`;
|
|
||||||
}
|
|
||||||
if (window.config.appInstance) {
|
|
||||||
title += ` - ${window.config.appInstance}`;
|
|
||||||
}
|
|
||||||
window.config.title = title;
|
|
||||||
window.document.title = title;
|
|
||||||
|
|
||||||
// start a background worker for ecc
|
// start a background worker for ecc
|
||||||
textsecure.startWorker('js/libsignal-protocol-worker.js');
|
textsecure.startWorker('js/libsignal-protocol-worker.js');
|
||||||
|
@ -51,8 +42,6 @@
|
||||||
getAccountManager().refreshPreKeys();
|
getAccountManager().refreshPreKeys();
|
||||||
});
|
});
|
||||||
|
|
||||||
const SERVER_URL = window.config.serverUrl;
|
|
||||||
const CDN_URL = window.config.cdnUrl;
|
|
||||||
let messageReceiver;
|
let messageReceiver;
|
||||||
window.getSocketStatus = () => {
|
window.getSocketStatus = () => {
|
||||||
if (messageReceiver) {
|
if (messageReceiver) {
|
||||||
|
@ -66,11 +55,7 @@
|
||||||
if (!accountManager) {
|
if (!accountManager) {
|
||||||
const USERNAME = storage.get('number_id');
|
const USERNAME = storage.get('number_id');
|
||||||
const PASSWORD = storage.get('password');
|
const PASSWORD = storage.get('password');
|
||||||
accountManager = new textsecure.AccountManager(
|
accountManager = new textsecure.AccountManager(USERNAME, PASSWORD);
|
||||||
SERVER_URL,
|
|
||||||
USERNAME,
|
|
||||||
PASSWORD
|
|
||||||
);
|
|
||||||
accountManager.addEventListener('registration', () => {
|
accountManager.addEventListener('registration', () => {
|
||||||
Whisper.Registration.markDone();
|
Whisper.Registration.markDone();
|
||||||
console.log('dispatching registration event');
|
console.log('dispatching registration event');
|
||||||
|
@ -174,13 +159,15 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
const currentVersion = window.config.version;
|
const currentVersion = window.getVersion();
|
||||||
const lastVersion = storage.get('version');
|
const lastVersion = storage.get('version');
|
||||||
const newVersion = !lastVersion || currentVersion !== lastVersion;
|
const newVersion = !lastVersion || currentVersion !== lastVersion;
|
||||||
storage.put('version', currentVersion);
|
storage.put('version', currentVersion);
|
||||||
|
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
console.log('New version detected:', currentVersion);
|
console.log(
|
||||||
|
`New version detected: ${currentVersion}; previous: ${lastVersion}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.dispatchEvent(new Event('storage_ready'));
|
window.dispatchEvent(new Event('storage_ready'));
|
||||||
|
@ -210,7 +197,7 @@
|
||||||
appView.openInbox({
|
appView.openInbox({
|
||||||
initialLoadComplete,
|
initialLoadComplete,
|
||||||
});
|
});
|
||||||
} else if (window.config.importMode) {
|
} else if (window.isImportMode()) {
|
||||||
appView.openImporter();
|
appView.openImporter();
|
||||||
} else {
|
} else {
|
||||||
appView.openInstaller();
|
appView.openInstaller();
|
||||||
|
@ -364,7 +351,6 @@
|
||||||
|
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
messageReceiver = new textsecure.MessageReceiver(
|
messageReceiver = new textsecure.MessageReceiver(
|
||||||
SERVER_URL,
|
|
||||||
USERNAME,
|
USERNAME,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
mySignalingKey,
|
mySignalingKey,
|
||||||
|
@ -384,10 +370,8 @@
|
||||||
messageReceiver.addEventListener('configuration', onConfiguration);
|
messageReceiver.addEventListener('configuration', onConfiguration);
|
||||||
|
|
||||||
window.textsecure.messaging = new textsecure.MessageSender(
|
window.textsecure.messaging = new textsecure.MessageSender(
|
||||||
SERVER_URL,
|
|
||||||
USERNAME,
|
USERNAME,
|
||||||
PASSWORD,
|
PASSWORD
|
||||||
CDN_URL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Because v0.43.2 introduced a bug that lost contact details, v0.43.4 introduces
|
// Because v0.43.2 introduced a bug that lost contact details, v0.43.4 introduces
|
||||||
|
|
|
@ -62,11 +62,10 @@
|
||||||
|
|
||||||
if (newUnreadCount > 0) {
|
if (newUnreadCount > 0) {
|
||||||
window.setBadgeCount(newUnreadCount);
|
window.setBadgeCount(newUnreadCount);
|
||||||
window.document.title =
|
window.document.title = window.getTitle() + ' (' + newUnreadCount + ')';
|
||||||
window.config.title + ' (' + newUnreadCount + ')';
|
|
||||||
} else {
|
} else {
|
||||||
window.setBadgeCount(0);
|
window.setBadgeCount(0);
|
||||||
window.document.title = window.config.title;
|
window.document.title = window.getTitle();
|
||||||
}
|
}
|
||||||
window.updateTrayIcon(newUnreadCount);
|
window.updateTrayIcon(newUnreadCount);
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var BUILD_EXPIRATION = 0;
|
var BUILD_EXPIRATION = 0;
|
||||||
try {
|
try {
|
||||||
BUILD_EXPIRATION = parseInt(window.config.buildExpiration);
|
BUILD_EXPIRATION = parseInt(window.getExpiration());
|
||||||
if (BUILD_EXPIRATION) {
|
if (BUILD_EXPIRATION) {
|
||||||
console.log('Build expires: ', new Date(BUILD_EXPIRATION).toISOString());
|
console.log('Build expires: ', new Date(BUILD_EXPIRATION).toISOString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@ if (window.console) {
|
||||||
function getHeader() {
|
function getHeader() {
|
||||||
let header = window.navigator.userAgent;
|
let header = window.navigator.userAgent;
|
||||||
|
|
||||||
header += ` node/${window.config.node_version}`;
|
header += ` node/${window.getNodeVersion()}`;
|
||||||
header += ` env/${window.config.environment}`;
|
header += ` env/${window.getEnvironment()}`;
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
openStandalone: function() {
|
openStandalone: function() {
|
||||||
if (window.config.environment !== 'production') {
|
if (window.getEnvironment() !== 'production') {
|
||||||
window.addSetupMenuItems();
|
window.addSetupMenuItems();
|
||||||
this.resetViews();
|
this.resetViews();
|
||||||
this.standaloneView = new Whisper.StandaloneRegistrationView();
|
this.standaloneView = new Whisper.StandaloneRegistrationView();
|
||||||
|
|
|
@ -142,7 +142,7 @@
|
||||||
setDeviceNameDefault: function() {
|
setDeviceNameDefault: function() {
|
||||||
var deviceName = textsecure.storage.user.getDeviceName();
|
var deviceName = textsecure.storage.user.getDeviceName();
|
||||||
|
|
||||||
this.$(DEVICE_NAME_SELECTOR).val(deviceName || window.config.hostname);
|
this.$(DEVICE_NAME_SELECTOR).val(deviceName || window.getHostName());
|
||||||
this.$(DEVICE_NAME_SELECTOR).focus();
|
this.$(DEVICE_NAME_SELECTOR).focus();
|
||||||
},
|
},
|
||||||
finishLinking: function() {
|
finishLinking: function() {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
var ARCHIVE_AGE = 7 * 24 * 60 * 60 * 1000;
|
var ARCHIVE_AGE = 7 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
function AccountManager(url, username, password) {
|
function AccountManager(username, password) {
|
||||||
this.server = window.WebAPI.connect({ username, password });
|
this.server = window.WebAPI.connect({ username, password });
|
||||||
this.pending = Promise.resolve();
|
this.pending = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,9 @@
|
||||||
|
|
||||||
/* eslint-disable more/no-then */
|
/* eslint-disable more/no-then */
|
||||||
|
|
||||||
function MessageReceiver(url, username, password, signalingKey, options = {}) {
|
function MessageReceiver(username, password, signalingKey, options = {}) {
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
|
||||||
this.url = url;
|
|
||||||
this.signalingKey = signalingKey;
|
this.signalingKey = signalingKey;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
@ -1121,14 +1120,12 @@ MessageReceiver.prototype.extend({
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
textsecure.MessageReceiver = function MessageReceiverWrapper(
|
textsecure.MessageReceiver = function MessageReceiverWrapper(
|
||||||
url,
|
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
signalingKey,
|
signalingKey,
|
||||||
options
|
options
|
||||||
) {
|
) {
|
||||||
const messageReceiver = new MessageReceiver(
|
const messageReceiver = new MessageReceiver(
|
||||||
url,
|
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
signalingKey,
|
signalingKey,
|
||||||
|
|
|
@ -139,7 +139,7 @@ Message.prototype = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageSender(url, username, password, cdn_url) {
|
function MessageSender(username, password) {
|
||||||
this.server = WebAPI.connect({ username, password });
|
this.server = WebAPI.connect({ username, password });
|
||||||
this.pendingMessages = {};
|
this.pendingMessages = {};
|
||||||
}
|
}
|
||||||
|
|
36
preload.js
36
preload.js
|
@ -10,12 +10,28 @@ const { deferredToPromise } = require('./js/modules/deferred_to_promise');
|
||||||
const { app } = electron.remote;
|
const { app } = electron.remote;
|
||||||
|
|
||||||
window.PROTO_ROOT = 'protos';
|
window.PROTO_ROOT = 'protos';
|
||||||
window.config = require('url').parse(window.location.toString(), true).query;
|
const config = require('url').parse(window.location.toString(), true).query;
|
||||||
|
|
||||||
|
let title = config.name;
|
||||||
|
if (config.environment !== 'production') {
|
||||||
|
title += ` - ${config.environment}`;
|
||||||
|
}
|
||||||
|
if (config.appInstance) {
|
||||||
|
title += ` - ${config.appInstance}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.getTitle = () => title;
|
||||||
|
window.getEnvironment = () => config.environment;
|
||||||
|
window.getVersion = () => config.version;
|
||||||
|
window.isImportMode = () => config.importMode;
|
||||||
|
window.getExpiration = () => config.buildExpiration;
|
||||||
|
window.getNodeVersion = () => config.node_version;
|
||||||
|
window.getHostName = () => config.hostname;
|
||||||
|
|
||||||
window.wrapDeferred = deferredToPromise;
|
window.wrapDeferred = deferredToPromise;
|
||||||
|
|
||||||
const ipc = electron.ipcRenderer;
|
const ipc = electron.ipcRenderer;
|
||||||
window.config.localeMessages = ipc.sendSync('locale-data');
|
const localeMessages = ipc.sendSync('locale-data');
|
||||||
|
|
||||||
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
||||||
|
|
||||||
|
@ -77,8 +93,8 @@ window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
|
||||||
|
|
||||||
require('./js/logging');
|
require('./js/logging');
|
||||||
|
|
||||||
if (window.config.proxyUrl) {
|
if (config.proxyUrl) {
|
||||||
console.log('using proxy url', window.config.proxyUrl);
|
console.log('using proxy url', config.proxyUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.nodeSetImmediate = setImmediate;
|
window.nodeSetImmediate = setImmediate;
|
||||||
|
@ -86,10 +102,10 @@ window.nodeSetImmediate = setImmediate;
|
||||||
const { initialize: initializeWebAPI } = require('./js/modules/web_api');
|
const { initialize: initializeWebAPI } = require('./js/modules/web_api');
|
||||||
|
|
||||||
window.WebAPI = initializeWebAPI({
|
window.WebAPI = initializeWebAPI({
|
||||||
url: window.config.serverUrl,
|
url: config.serverUrl,
|
||||||
cdnUrl: window.config.cdnUrl,
|
cdnUrl: config.cdnUrl,
|
||||||
certificateAuthority: window.config.certificateAuthority,
|
certificateAuthority: config.certificateAuthority,
|
||||||
proxyUrl: window.config.proxyUrl,
|
proxyUrl: config.proxyUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
||||||
|
@ -123,7 +139,7 @@ const Signal = require('./js/modules/signal');
|
||||||
const i18n = require('./js/modules/i18n');
|
const i18n = require('./js/modules/i18n');
|
||||||
const Attachments = require('./app/attachments');
|
const Attachments = require('./app/attachments');
|
||||||
|
|
||||||
const { locale, localeMessages } = window.config;
|
const { locale } = config;
|
||||||
window.i18n = i18n.setup(locale, localeMessages);
|
window.i18n = i18n.setup(locale, localeMessages);
|
||||||
window.moment.updateLocale(locale, {
|
window.moment.updateLocale(locale, {
|
||||||
relativeTime: {
|
relativeTime: {
|
||||||
|
@ -149,7 +165,7 @@ window.Signal.Logs = require('./js/modules/logs');
|
||||||
// /tmp mounted as noexec on Linux.
|
// /tmp mounted as noexec on Linux.
|
||||||
require('./js/spell_check');
|
require('./js/spell_check');
|
||||||
|
|
||||||
if (window.config.environment === 'test') {
|
if (config.environment === 'test') {
|
||||||
/* eslint-disable global-require, import/no-extraneous-dependencies */
|
/* eslint-disable global-require, import/no-extraneous-dependencies */
|
||||||
window.test = {
|
window.test = {
|
||||||
glob: require('glob'),
|
glob: require('glob'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue