diff --git a/background.html b/background.html index cbeb81d99..d7b867b4d 100644 --- a/background.html +++ b/background.html @@ -291,18 +291,10 @@ type="text/javascript" src="js/views/key_verification_view.js" > - - - - - - diff --git a/debug_log_preload.js b/debug_log_preload.js index ed669910b..be3db5a1f 100644 --- a/debug_log_preload.js +++ b/debug_log_preload.js @@ -5,7 +5,6 @@ const { ipcRenderer } = require('electron'); const url = require('url'); -const copyText = require('copy-text-to-clipboard'); // It is important to call this as early as possible require('./ts/windows/context'); @@ -25,7 +24,6 @@ setEnvironment(parseEnvironment(config.environment)); window.getVersion = () => config.version; window.theme = config.theme; window.i18n = i18n.setup(locale, localeMessages); -window.copyText = copyText; // got.js appears to need this to successfully submit debug logs to the cloud window.nodeSetImmediate = setImmediate; @@ -37,6 +35,7 @@ window.Backbone = require('backbone'); require('./ts/backbone/views/whisper_view'); require('./ts/backbone/views/toast_view'); require('./ts/logging/set_up_renderer_logging').initialize(); +require('./ts/views/debug_log_view'); window.closeDebugLog = () => ipcRenderer.send('close-debug-log'); window.Backbone = require('backbone'); diff --git a/js/database.js b/js/database.js index d48616add..d9ecbd4bd 100644 --- a/js/database.js +++ b/js/database.js @@ -11,7 +11,7 @@ window.Whisper.Database.nolog = true; Whisper.Database.handleDOMException = (prefix, error, reject) => { - window.log.error( + window.SignalWindow.log.error( `${prefix}:`, error && error.name, error && error.message, diff --git a/js/debug_log_start.js b/js/debug_log_start.js index b9a27abf6..3a81a1d00 100644 --- a/js/debug_log_start.js +++ b/js/debug_log_start.js @@ -2,7 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-only /* global $: false */ -/* global Whisper: false */ $(document).on('keydown', e => { if (e.keyCode === 27) { @@ -16,5 +15,5 @@ $body.addClass(`${window.theme}-theme`); // got.js appears to need this to successfully submit debug logs to the cloud window.setImmediate = window.nodeSetImmediate; -window.view = new Whisper.DebugLogView(); +window.view = new window.Whisper.DebugLogView(); window.view.$el.appendTo($body); diff --git a/js/expiring_messages.js b/js/expiring_messages.js index 512fe042a..db50b8d05 100644 --- a/js/expiring_messages.js +++ b/js/expiring_messages.js @@ -13,11 +13,13 @@ async function destroyExpiredMessages() { try { - window.log.info('destroyExpiredMessages: Loading messages...'); + window.SignalWindow.log.info( + 'destroyExpiredMessages: Loading messages...' + ); const messages = await window.Signal.Data.getExpiredMessages({ MessageCollection: Whisper.MessageCollection, }); - window.log.info( + window.SignalWindow.log.info( `destroyExpiredMessages: found ${messages.length} messages to expire` ); @@ -38,7 +40,7 @@ await Promise.all(messageCleanup); inMemoryMessages.forEach(message => { - window.log.info('Message expired', { + window.SignalWindow.log.info('Message expired', { sentAt: message.get('sent_at'), }); @@ -50,23 +52,27 @@ } }); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'destroyExpiredMessages: Error deleting expired messages', error && error.stack ? error.stack : error ); } - window.log.info('destroyExpiredMessages: complete'); + window.SignalWindow.log.info('destroyExpiredMessages: complete'); checkExpiringMessages(); } let timeout; async function checkExpiringMessages() { - window.log.info('checkExpiringMessages: checking for expiring messages'); + window.SignalWindow.log.info( + 'checkExpiringMessages: checking for expiring messages' + ); const soonestExpiry = await window.Signal.Data.getSoonestMessageExpiry(); if (!soonestExpiry) { - window.log.info('checkExpiringMessages: found no messages to expire'); + window.SignalWindow.log.info( + 'checkExpiringMessages: found no messages to expire' + ); return; } @@ -82,7 +88,7 @@ wait = 2147483647; } - window.log.info( + window.SignalWindow.log.info( `checkExpiringMessages: next message expires ${new Date( soonestExpiry ).toISOString()}; waiting ${wait} ms before clearing` diff --git a/js/expiring_tap_to_view_messages.js b/js/expiring_tap_to_view_messages.js index efdb68308..3d9157d92 100644 --- a/js/expiring_tap_to_view_messages.js +++ b/js/expiring_tap_to_view_messages.js @@ -13,7 +13,9 @@ async function eraseTapToViewMessages() { try { - window.log.info('eraseTapToViewMessages: Loading messages...'); + window.SignalWindow.log.info( + 'eraseTapToViewMessages: Loading messages...' + ); const messages = await window.Signal.Data.getTapToViewMessagesNeedingErase( { MessageCollection: Whisper.MessageCollection, @@ -24,7 +26,7 @@ messages.map(async fromDB => { const message = MessageController.register(fromDB.id, fromDB); - window.log.info( + window.SignalWindow.log.info( 'eraseTapToViewMessages: message data erased', message.idForLogging() ); @@ -33,13 +35,13 @@ }) ); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'eraseTapToViewMessages: Error erasing messages', error && error.stack ? error.stack : error ); } - window.log.info('eraseTapToViewMessages: complete'); + window.SignalWindow.log.info('eraseTapToViewMessages: complete'); } let timeout; @@ -57,7 +59,7 @@ const nextCheck = receivedAt + THIRTY_DAYS; Whisper.TapToViewMessagesListener.nextCheck = nextCheck; - window.log.info( + window.SignalWindow.log.info( 'checkTapToViewMessages: next check at', new Date(nextCheck).toISOString() ); diff --git a/js/modules/debug.js b/js/modules/debug.js index 1e2fb5bb0..b5749bb3b 100644 --- a/js/modules/debug.js +++ b/js/modules/debug.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only /* eslint-env node */ -/* global log, Signal */ +/* global Signal, window */ const fs = require('fs-extra'); const path = require('path'); @@ -58,7 +58,7 @@ exports.createConversation = async ({ await Promise.all( range(0, numMessages).map(async index => { await sleep(index * 100); - log.info(`Create message ${index + 1}`); + window.SignalWindow.log.info(`Create message ${index + 1}`); const message = await createRandomMessage({ conversationId }); return Signal.Data.saveMessage(message); }) @@ -108,7 +108,10 @@ const createRandomMessage = async ({ conversationId } = {}) => { }; const message = _createMessage({ commonProperties, conversationId, type }); - return Message.initializeSchemaVersion({ message, logger: log }); + return Message.initializeSchemaVersion({ + message, + logger: window.SignalWindow.log, + }); }; const _createMessage = ({ commonProperties, conversationId, type } = {}) => { diff --git a/js/modules/i18n.js b/js/modules/i18n.js index 975ffe9e5..67093a8fb 100644 --- a/js/modules/i18n.js +++ b/js/modules/i18n.js @@ -3,9 +3,6 @@ /* eslint-env node, browser */ -// eslint-disable-next-line no-console -const log = typeof window !== 'undefined' ? window.log : console; - exports.setup = (locale, messages) => { if (!locale) { throw new Error('i18n: locale parameter is required'); @@ -15,6 +12,10 @@ exports.setup = (locale, messages) => { } function getMessage(key, substitutions) { + // eslint-disable-next-line no-console + const log = + typeof window !== 'undefined' ? window.SignalWindow.log : console; + const entry = messages[key]; if (!entry) { log.error( diff --git a/js/modules/idle_detector.js b/js/modules/idle_detector.js index fd5eac4b1..b71ddb1ea 100644 --- a/js/modules/idle_detector.js +++ b/js/modules/idle_detector.js @@ -16,7 +16,7 @@ class IdleDetector extends EventEmitter { } start() { - window.log.info('Start idle detector'); + window.SignalWindow.log.info('Start idle detector'); this._scheduleNextCallback(); } @@ -25,7 +25,7 @@ class IdleDetector extends EventEmitter { return; } - window.log.info('Stop idle detector'); + window.SignalWindow.log.info('Stop idle detector'); this._clearScheduledCallbacks(); } diff --git a/js/modules/indexeddb.js b/js/modules/indexeddb.js index a057f3d4a..699e3f941 100644 --- a/js/modules/indexeddb.js +++ b/js/modules/indexeddb.js @@ -12,7 +12,9 @@ module.exports = { }; async function doesDatabaseExist() { - window.log.info('Checking for the existence of IndexedDB data...'); + window.SignalWindow.log.info( + 'Checking for the existence of IndexedDB data...' + ); return new Promise((resolve, reject) => { const { id } = Whisper.Database; const req = window.indexedDB.open(id); @@ -20,7 +22,7 @@ async function doesDatabaseExist() { let existed = true; setTimeout(() => { - window.log.warn( + window.SignalWindow.log.warn( 'doesDatabaseExist: Timed out attempting to check IndexedDB status' ); return resolve(false); @@ -41,6 +43,8 @@ async function doesDatabaseExist() { } function removeDatabase() { - window.log.info(`Deleting IndexedDB database '${Whisper.Database.id}'`); + window.SignalWindow.log.info( + `Deleting IndexedDB database '${Whisper.Database.id}'` + ); window.indexedDB.deleteDatabase(Whisper.Database.id); } diff --git a/js/modules/messages_data_migrator.js b/js/modules/messages_data_migrator.js index ff3e38d10..9f89e99e9 100644 --- a/js/modules/messages_data_migrator.js +++ b/js/modules/messages_data_migrator.js @@ -45,7 +45,7 @@ exports.processNext = async ({ } ); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'processNext error:', error && error.stack ? error.stack : error ); diff --git a/js/modules/types/conversation.js b/js/modules/types/conversation.js index 8bf815030..b222167e9 100644 --- a/js/modules/types/conversation.js +++ b/js/modules/types/conversation.js @@ -53,7 +53,7 @@ function buildAvatarUpdater({ field }) { const { hash, path } = avatar; const exists = await doesAttachmentExist(path); if (!exists) { - window.log.warn( + window.SignalWindow.log.warn( `Conversation.buildAvatarUpdater: attachment ${path} did not exist` ); } diff --git a/js/notifications.js b/js/notifications.js index 479b7bb88..113026737 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -133,7 +133,7 @@ } if (status.type !== 'ok') { - window.log.info( + window.SignalWindow.log.info( `Not updating notifications; notification status is ${status.type}. ${ status.shouldClearNotifications ? 'Also clearing notifications' : '' }` @@ -145,7 +145,7 @@ return; } - window.log.info('Showing a notification'); + window.SignalWindow.log.info('Showing a notification'); let notificationTitle; let notificationMessage; @@ -191,7 +191,7 @@ } } else { if (userSetting !== SettingNames.NO_NAME_OR_MESSAGE) { - window.log.error( + window.SignalWindow.log.error( `Error: Unknown user notification setting: '${userSetting}'` ); } @@ -216,7 +216,7 @@ ); }, clear() { - window.log.info('Removing notification'); + window.SignalWindow.log.info('Removing notification'); this.notificationData = null; this.update(); }, diff --git a/js/reliable_trigger.js b/js/reliable_trigger.js index 4e3c79e8a..3479c2705 100644 --- a/js/reliable_trigger.js +++ b/js/reliable_trigger.js @@ -66,7 +66,7 @@ a2 = args[1], a3 = args[2]; const logError = function (error) { - window.log.error( + window.SignalWindow.log.error( 'Model caught error triggering', name, 'event:', diff --git a/js/rotate_signed_prekey_listener.js b/js/rotate_signed_prekey_listener.js index 4589cc543..d61f57d9c 100644 --- a/js/rotate_signed_prekey_listener.js +++ b/js/rotate_signed_prekey_listener.js @@ -21,13 +21,13 @@ } async function run() { - window.log.info('Rotating signed prekey...'); + window.SignalWindow.log.info('Rotating signed prekey...'); try { await getAccountManager().rotateSignedPreKey(); scheduleNextRotation(); setTimeoutForNextRun(); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'rotateSignedPrekey() failed. Trying again in five minutes' ); setTimeout(setTimeoutForNextRun, 5 * 60 * 1000); @@ -38,7 +38,7 @@ if (navigator.onLine) { run(); } else { - window.log.info( + window.SignalWindow.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.log.info( + window.SignalWindow.log.info( 'Next signed key rotation scheduled for', new Date(time).toISOString() ); @@ -71,7 +71,9 @@ Whisper.RotateSignedPreKeyListener = { init(events, newVersion) { if (initComplete) { - window.log.info('Rotate signed prekey listener: Already initialized'); + window.SignalWindow.log.info( + 'Rotate signed prekey listener: Already initialized' + ); return; } initComplete = true; diff --git a/js/views/debug_log_view.js b/js/views/debug_log_view.js deleted file mode 100644 index b256db409..000000000 --- a/js/views/debug_log_view.js +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2015-2021 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -/* global i18n, Whisper, $ */ - -// eslint-disable-next-line func-names -(function () { - window.Whisper = window.Whisper || {}; - - // This enum-like object describes the load state of `DebugLogView`. It's designed to be - // unidirectional; `NotStarted` → `Started` → `LogsFetchedButNotInTextarea`, etc. - const LoadState = { - NotStarted: 0, - Started: 1, - LogsFetchedButNotInTextarea: 2, - PuttingLogsInTextarea: 3, - LogsInTextarea: 4, - }; - - Whisper.LoadingFullLogsToast = Whisper.ToastView.extend({ - render_attributes() { - return { toastMessage: i18n('loading') }; - }, - }); - - Whisper.LinkedCopiedToast = Whisper.ToastView.extend({ - render_attributes() { - return { toastMessage: i18n('debugLogLinkCopied') }; - }, - }); - - Whisper.DebugLogLinkView = Whisper.View.extend({ - template: () => $('#debug-log-link').html(), - initialize(options) { - this.url = options.url; - }, - events: { - 'click .copy': 'copy', - }, - render_attributes() { - return { - url: this.url, - reportIssue: i18n('reportIssue'), - debugLogCopy: i18n('debugLogCopy'), - debugLogCopyAlt: i18n('debugLogCopyAlt'), - }; - }, - copy(e) { - e.preventDefault(); - window.copyText(e.currentTarget.href); - Whisper.ToastView.show(Whisper.LinkedCopiedToast, document.body); - }, - }); - - /** - * The bulk of the logic in this view involves grabbing the logs from disk and putting - * them in a `