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);
|
||||
|
||||
console.log('background page reloaded');
|
||||
console.log('environment:', window.config.environment);
|
||||
console.log('environment:', window.getEnvironment());
|
||||
|
||||
let initialLoadComplete = false;
|
||||
window.owsDesktopApp = {};
|
||||
|
||||
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;
|
||||
window.document.title = window.getTitle();
|
||||
|
||||
// start a background worker for ecc
|
||||
textsecure.startWorker('js/libsignal-protocol-worker.js');
|
||||
|
@ -51,8 +42,6 @@
|
|||
getAccountManager().refreshPreKeys();
|
||||
});
|
||||
|
||||
const SERVER_URL = window.config.serverUrl;
|
||||
const CDN_URL = window.config.cdnUrl;
|
||||
let messageReceiver;
|
||||
window.getSocketStatus = () => {
|
||||
if (messageReceiver) {
|
||||
|
@ -66,11 +55,7 @@
|
|||
if (!accountManager) {
|
||||
const USERNAME = storage.get('number_id');
|
||||
const PASSWORD = storage.get('password');
|
||||
accountManager = new textsecure.AccountManager(
|
||||
SERVER_URL,
|
||||
USERNAME,
|
||||
PASSWORD
|
||||
);
|
||||
accountManager = new textsecure.AccountManager(USERNAME, PASSWORD);
|
||||
accountManager.addEventListener('registration', () => {
|
||||
Whisper.Registration.markDone();
|
||||
console.log('dispatching registration event');
|
||||
|
@ -174,13 +159,15 @@
|
|||
});
|
||||
|
||||
function start() {
|
||||
const currentVersion = window.config.version;
|
||||
const currentVersion = window.getVersion();
|
||||
const lastVersion = storage.get('version');
|
||||
const newVersion = !lastVersion || currentVersion !== lastVersion;
|
||||
storage.put('version', currentVersion);
|
||||
|
||||
if (newVersion) {
|
||||
console.log('New version detected:', currentVersion);
|
||||
console.log(
|
||||
`New version detected: ${currentVersion}; previous: ${lastVersion}`
|
||||
);
|
||||
}
|
||||
|
||||
window.dispatchEvent(new Event('storage_ready'));
|
||||
|
@ -210,7 +197,7 @@
|
|||
appView.openInbox({
|
||||
initialLoadComplete,
|
||||
});
|
||||
} else if (window.config.importMode) {
|
||||
} else if (window.isImportMode()) {
|
||||
appView.openImporter();
|
||||
} else {
|
||||
appView.openInstaller();
|
||||
|
@ -364,7 +351,6 @@
|
|||
|
||||
// initialize the socket and start listening for messages
|
||||
messageReceiver = new textsecure.MessageReceiver(
|
||||
SERVER_URL,
|
||||
USERNAME,
|
||||
PASSWORD,
|
||||
mySignalingKey,
|
||||
|
@ -384,10 +370,8 @@
|
|||
messageReceiver.addEventListener('configuration', onConfiguration);
|
||||
|
||||
window.textsecure.messaging = new textsecure.MessageSender(
|
||||
SERVER_URL,
|
||||
USERNAME,
|
||||
PASSWORD,
|
||||
CDN_URL
|
||||
PASSWORD
|
||||
);
|
||||
|
||||
// Because v0.43.2 introduced a bug that lost contact details, v0.43.4 introduces
|
||||
|
|
|
@ -62,11 +62,10 @@
|
|||
|
||||
if (newUnreadCount > 0) {
|
||||
window.setBadgeCount(newUnreadCount);
|
||||
window.document.title =
|
||||
window.config.title + ' (' + newUnreadCount + ')';
|
||||
window.document.title = window.getTitle() + ' (' + newUnreadCount + ')';
|
||||
} else {
|
||||
window.setBadgeCount(0);
|
||||
window.document.title = window.config.title;
|
||||
window.document.title = window.getTitle();
|
||||
}
|
||||
window.updateTrayIcon(newUnreadCount);
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
'use strict';
|
||||
var BUILD_EXPIRATION = 0;
|
||||
try {
|
||||
BUILD_EXPIRATION = parseInt(window.config.buildExpiration);
|
||||
BUILD_EXPIRATION = parseInt(window.getExpiration());
|
||||
if (BUILD_EXPIRATION) {
|
||||
console.log('Build expires: ', new Date(BUILD_EXPIRATION).toISOString());
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ if (window.console) {
|
|||
function getHeader() {
|
||||
let header = window.navigator.userAgent;
|
||||
|
||||
header += ` node/${window.config.node_version}`;
|
||||
header += ` env/${window.config.environment}`;
|
||||
header += ` node/${window.getNodeVersion()}`;
|
||||
header += ` env/${window.getEnvironment()}`;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
}
|
||||
},
|
||||
openStandalone: function() {
|
||||
if (window.config.environment !== 'production') {
|
||||
if (window.getEnvironment() !== 'production') {
|
||||
window.addSetupMenuItems();
|
||||
this.resetViews();
|
||||
this.standaloneView = new Whisper.StandaloneRegistrationView();
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
setDeviceNameDefault: function() {
|
||||
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();
|
||||
},
|
||||
finishLinking: function() {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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.pending = Promise.resolve();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,9 @@
|
|||
|
||||
/* eslint-disable more/no-then */
|
||||
|
||||
function MessageReceiver(url, username, password, signalingKey, options = {}) {
|
||||
function MessageReceiver(username, password, signalingKey, options = {}) {
|
||||
this.count = 0;
|
||||
|
||||
this.url = url;
|
||||
this.signalingKey = signalingKey;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
@ -1121,14 +1120,12 @@ MessageReceiver.prototype.extend({
|
|||
window.textsecure = window.textsecure || {};
|
||||
|
||||
textsecure.MessageReceiver = function MessageReceiverWrapper(
|
||||
url,
|
||||
username,
|
||||
password,
|
||||
signalingKey,
|
||||
options
|
||||
) {
|
||||
const messageReceiver = new MessageReceiver(
|
||||
url,
|
||||
username,
|
||||
password,
|
||||
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.pendingMessages = {};
|
||||
}
|
||||
|
|
36
preload.js
36
preload.js
|
@ -10,12 +10,28 @@ 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;
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -77,8 +93,8 @@ window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
|
|||
|
||||
require('./js/logging');
|
||||
|
||||
if (window.config.proxyUrl) {
|
||||
console.log('using proxy url', window.config.proxyUrl);
|
||||
if (config.proxyUrl) {
|
||||
console.log('using proxy url', config.proxyUrl);
|
||||
}
|
||||
|
||||
window.nodeSetImmediate = setImmediate;
|
||||
|
@ -86,10 +102,10 @@ 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,
|
||||
url: config.serverUrl,
|
||||
cdnUrl: config.cdnUrl,
|
||||
certificateAuthority: config.certificateAuthority,
|
||||
proxyUrl: config.proxyUrl,
|
||||
});
|
||||
|
||||
// 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 Attachments = require('./app/attachments');
|
||||
|
||||
const { locale, localeMessages } = window.config;
|
||||
const { locale } = config;
|
||||
window.i18n = i18n.setup(locale, localeMessages);
|
||||
window.moment.updateLocale(locale, {
|
||||
relativeTime: {
|
||||
|
@ -149,7 +165,7 @@ window.Signal.Logs = require('./js/modules/logs');
|
|||
// /tmp mounted as noexec on Linux.
|
||||
require('./js/spell_check');
|
||||
|
||||
if (window.config.environment === 'test') {
|
||||
if (config.environment === 'test') {
|
||||
/* eslint-disable global-require, import/no-extraneous-dependencies */
|
||||
window.test = {
|
||||
glob: require('glob'),
|
||||
|
|
Loading…
Add table
Reference in a new issue