From eeb62575267b2bec3b488a3739f08dc92fb2ec54 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Mar 2020 10:24:23 +1100 Subject: [PATCH] Remove settings view --- js/settings_start.js | 58 ------- js/views/settings_view.js | 327 -------------------------------------- main.js | 131 --------------- preload.js | 119 +------------- settings_preload.js | 100 ------------ 5 files changed, 5 insertions(+), 730 deletions(-) delete mode 100644 js/settings_start.js delete mode 100644 js/views/settings_view.js delete mode 100644 settings_preload.js diff --git a/js/settings_start.js b/js/settings_start.js deleted file mode 100644 index c6627ebd7..000000000 --- a/js/settings_start.js +++ /dev/null @@ -1,58 +0,0 @@ -/* global $, Whisper, storage */ - -$(document).on('keyup', e => { - 'use strict'; - - if (e.keyCode === 27) { - window.closeSettings(); - } -}); - -const $body = $(document.body); -$body.addClass(`${window.theme}-theme`); - -// eslint-disable-next-line strict -const getInitialData = async () => ({ - deviceName: await window.getDeviceName(), - - themeSetting: await window.getThemeSetting(), - hideMenuBar: await window.getHideMenuBar(), - - messageTTL: await window.getMessageTTL(), - readReceiptSetting: await window.getReadReceiptSetting(), - typingIndicatorsSetting: await window.getTypingIndicatorsSetting(), - linkPreviewSetting: await window.getLinkPreviewSetting(), - notificationSetting: await window.getNotificationSetting(), - audioNotification: await window.getAudioNotification(), - - spellCheck: await window.getSpellCheck(), - - mediaPermissions: await window.getMediaPermissions(), - - isPrimary: await window.isPrimary(), - lastSyncTime: await window.getLastSyncTime(), -}); - -window.initialRequest = getInitialData(); - -// eslint-disable-next-line more/no-then -window.initialRequest.then( - data => { - 'use strict'; - - storage.fetch(); - - window.initialData = data; - window.view = new Whisper.SettingsView(); - window.view.$el.appendTo($body); - }, - error => { - 'use strict'; - - window.log.error( - 'settings.initialRequest error:', - error && error.stack ? error.stack : error - ); - window.closeSettings(); - } -); diff --git a/js/views/settings_view.js b/js/views/settings_view.js deleted file mode 100644 index af89d9f95..000000000 --- a/js/views/settings_view.js +++ /dev/null @@ -1,327 +0,0 @@ -/* global i18n: false */ -/* global Whisper: false */ -/* global $: false */ - -/* eslint-disable no-new */ - -// eslint-disable-next-line func-names -(function() { - 'use strict'; - - window.Whisper = window.Whisper || {}; - const { Settings } = window.Signal.Types; - - const CheckboxView = Whisper.View.extend({ - initialize(options) { - this.name = options.name; - this.setFn = options.setFn; - this.value = options.value; - this.populate(); - }, - events: { - change: 'change', - }, - change(e) { - const value = e.target.checked; - this.setFn(value); - window.log.info(this.name, 'changed to', value); - }, - populate() { - this.$('input').prop('checked', !!this.value); - }, - }); - - const MediaPermissionsSettingView = Whisper.View.extend({ - initialize(options) { - this.value = options.value; - this.setFn = options.setFn; - this.populate(); - }, - events: { - change: 'change', - }, - change(e) { - this.value = e.target.checked; - this.setFn(this.value); - window.log.info('media-permissions changed to', this.value); - }, - populate() { - this.$('input').prop('checked', Boolean(this.value)); - }, - }); - - const MessageTTLSettingView = Whisper.View.extend({ - initialize(options) { - this.value = options.value; - this.setFn = options.setFn; - this.populate(); - }, - events: { - change: 'change', - input: 'input', - }, - change(e) { - this.value = e.target.value; - this.setFn(this.value); - window.log.info('message-ttl-setting changed to', this.value); - }, - input(e) { - this.value = e.target.value; - this.$('label').html(`${this.value} Hours`); - }, - populate() { - this.$('input').val(this.value); - this.$('label').html(`${this.value} Hours`); - }, - }); - - const ReadReceiptSettingView = Whisper.View.extend({ - initialize(options) { - this.value = options.value; - this.setFn = options.setFn; - this.populate(); - }, - events: { - change: 'change', - }, - change(e) { - this.value = e.target.checked; - this.setFn(this.value); - window.log.info('read-receipt-setting changed to', this.value); - }, - populate() { - this.$('input').prop('checked', Boolean(this.value)); - }, - }); - - const TypingIndicatorsSettingView = Whisper.View.extend({ - initialize(options) { - this.value = options.value; - this.setFn = options.setFn; - this.populate(); - }, - events: { - change: 'change', - }, - change(e) { - this.value = e.target.checked; - this.setFn(this.value); - window.log.info('typing-indicators-setting changed to', this.value); - }, - populate() { - this.$('input').prop('checked', Boolean(this.value)); - }, - }); - - const RadioButtonGroupView = Whisper.View.extend({ - initialize(options) { - this.name = options.name; - this.setFn = options.setFn; - this.value = options.value; - this.populate(); - }, - events: { - change: 'change', - }, - change(e) { - const value = this.$(e.target).val(); - this.setFn(value); - window.log.info(this.name, 'changed to', value); - }, - populate() { - this.$(`#${this.name}-${this.value}`).attr('checked', 'checked'); - }, - }); - Whisper.SettingsView = Whisper.View.extend({ - className: 'settings modal expand', - templateName: 'settings', - initialize() { - this.render(); - new RadioButtonGroupView({ - el: this.$('.notification-settings'), - name: 'notification-setting', - value: window.initialData.notificationSetting, - setFn: window.setNotificationSetting, - }); - new RadioButtonGroupView({ - el: this.$('.theme-settings'), - name: 'theme-setting', - value: window.initialData.themeSetting, - setFn: theme => { - $(document.body) - .removeClass('dark-theme') - .removeClass('light-theme') - .addClass(`${theme}-theme`); - window.setThemeSetting(theme); - }, - }); - if (Settings.isAudioNotificationSupported()) { - new CheckboxView({ - el: this.$('.audio-notification-setting'), - name: 'audio-notification-setting', - value: window.initialData.audioNotification, - setFn: window.setAudioNotification, - }); - } - new CheckboxView({ - el: this.$('.spell-check-setting'), - name: 'spell-check-setting', - value: window.initialData.spellCheck, - setFn: window.setSpellCheck, - }); - if (Settings.isHideMenuBarSupported()) { - new CheckboxView({ - el: this.$('.menu-bar-setting'), - name: 'menu-bar-setting', - value: window.initialData.hideMenuBar, - setFn: window.setHideMenuBar, - }); - } - new CheckboxView({ - el: this.$('.link-preview-setting'), - name: 'link-preview-setting', - value: window.initialData.linkPreviewSetting, - setFn: window.setLinkPreviewSetting, - }); - new MediaPermissionsSettingView({ - el: this.$('.media-permissions'), - value: window.initialData.mediaPermissions, - setFn: window.setMediaPermissions, - }); - new ReadReceiptSettingView({ - el: this.$('.read-receipt-setting'), - value: window.initialData.readReceiptSetting, - setFn: window.setReadReceiptSetting, - }); - new TypingIndicatorsSettingView({ - el: this.$('.typing-indicators-setting'), - value: window.initialData.typingIndicatorsSetting, - setFn: window.setTypingIndicatorsSetting, - }); - new MessageTTLSettingView({ - el: this.$('.message-ttl-setting'), - value: window.initialData.messageTTL, - setFn: window.setMessageTTL, - }); - const blockedNumberView = new Whisper.BlockedNumberView().render(); - this.$('.blocked-user-setting').append(blockedNumberView.el); - - if (!window.initialData.isPrimary) { - const syncView = new SyncView().render(); - this.$('.sync-setting').append(syncView.el); - } - }, - events: { - 'click .close': 'onClose', - 'click .clear-data': 'onClearData', - }, - render_attributes() { - return { - deviceNameLabel: i18n('deviceName'), - deviceName: window.initialData.deviceName, - theme: i18n('theme'), - notifications: i18n('notifications'), - notificationSettingsDialog: i18n('notificationSettingsDialog'), - settings: i18n('settings'), - disableNotifications: i18n('disableNotifications'), - nameAndMessage: i18n('nameAndMessage'), - noNameOrMessage: i18n('noNameOrMessage'), - nameOnly: i18n('nameOnly'), - audioNotificationDescription: i18n('audioNotificationDescription'), - isAudioNotificationSupported: Settings.isAudioNotificationSupported(), - isHideMenuBarSupported: Settings.isHideMenuBarSupported(), - themeLight: i18n('themeLight'), - themeDark: i18n('themeDark'), - hideMenuBar: i18n('hideMenuBar'), - clearDataHeader: i18n('clearDataHeader'), - clearDataButton: i18n('clearDataButton'), - clearDataExplanation: i18n('clearDataExplanation'), - permissions: i18n('permissions'), - mediaPermissionsDescription: i18n('mediaPermissionsDescription'), - generalHeader: i18n('general'), - readReceiptSettingDescription: i18n('readReceiptSettingDescription'), - typingIndicatorsSettingDescription: i18n( - 'typingIndicatorsSettingDescription' - ), - messageTTL: i18n('messageTTL'), - messageTTLSettingDescription: i18n('messageTTLSettingDescription'), - messageTTLSettingWarning: i18n('messageTTLSettingWarning'), - spellCheckHeader: i18n('spellCheck'), - spellCheckDescription: i18n('spellCheckDescription'), - blockedHeader: 'Blocked Users', - linkPreviews: i18n('linkPreviewsTitle'), - linkPreviewsSettingDescription: i18n('linkPreviewsDescription'), - }; - }, - onClose() { - window.closeSettings(); - }, - onClearData() { - window.deleteAllData(); - window.closeSettings(); - }, - }); - - const SyncView = Whisper.View.extend({ - templateName: 'syncSettings', - className: 'syncSettings', - events: { - 'click .sync': 'sync', - }, - initialize() { - this.lastSyncTime = window.initialData.lastSyncTime; - }, - enable() { - this.$('.sync').text(i18n('syncNow')); - this.$('.sync').removeAttr('disabled'); - }, - disable() { - this.$('.sync').attr('disabled', 'disabled'); - this.$('.sync').text(i18n('syncing')); - }, - onsuccess() { - window.setLastSyncTime(Date.now()); - this.lastSyncTime = Date.now(); - window.log.info('sync successful'); - this.enable(); - this.render(); - }, - ontimeout() { - window.log.error('sync timed out'); - this.$('.synced_at').hide(); - this.$('.sync_failed').show(); - this.enable(); - }, - async sync() { - this.$('.sync_failed').hide(); - if (window.initialData.isPrimary) { - window.log.warn('Tried to sync from device 1'); - return; - } - - this.disable(); - try { - await window.makeSyncRequest(); - this.onsuccess(); - } catch (error) { - this.ontimeout(); - } - }, - render_attributes() { - const attrs = { - sync: i18n('sync'), - syncNow: i18n('syncNow'), - syncExplanation: i18n('syncExplanation'), - syncFailed: i18n('syncFailed'), - }; - let date = this.lastSyncTime; - if (date) { - date = new Date(date); - attrs.lastSynced = i18n('lastSynced'); - attrs.syncDate = date.toLocaleDateString(); - attrs.syncTime = date.toLocaleTimeString(); - } - return attrs; - }, - }); -})(); diff --git a/main.js b/main.js index 48ca42d37..75746d222 100644 --- a/main.js +++ b/main.js @@ -590,54 +590,6 @@ function showAbout() { }); } -let settingsWindow; -async function showSettingsWindow() { - if (settingsWindow) { - settingsWindow.show(); - return; - } - if (!mainWindow) { - return; - } - - const theme = await pify(getDataFromMainWindow)('theme-setting'); - const size = mainWindow.getSize(); - const options = { - width: Math.min(500, size[0]), - height: Math.max(size[1] - 100, MIN_HEIGHT), - resizable: false, - title: locale.messages.signalDesktopPreferences.message, - autoHideMenuBar: true, - backgroundColor: '#FFFFFF', - show: false, - modal: true, - webPreferences: { - nodeIntegration: false, - nodeIntegrationInWorker: false, - contextIsolation: false, - preload: path.join(__dirname, 'settings_preload.js'), - nativeWindowOpen: true, - }, - parent: mainWindow, - }; - - settingsWindow = new BrowserWindow(options); - - captureClicks(settingsWindow); - - settingsWindow.loadURL(prepareURL([__dirname, 'settings.html'], { theme })); - - settingsWindow.on('closed', () => { - removeDarkOverlay(); - settingsWindow = null; - }); - - settingsWindow.once('ready-to-show', () => { - addDarkOverlay(); - settingsWindow.show(); - }); -} - let debugLogWindow; async function showDebugLogWindow() { if (debugLogWindow) { @@ -870,7 +822,6 @@ function setupMenu(options) { showDebugLog: showDebugLogWindow, showWindow, showAbout, - showSettings: showSettingsWindow, openReleaseNotes, openNewBugForm, openSupportPage, @@ -1122,40 +1073,6 @@ function removeDarkOverlay() { } } -ipc.on('show-settings', showSettingsWindow); -ipc.on('close-settings', () => { - if (settingsWindow) { - settingsWindow.close(); - } -}); - -installSettingsGetter('device-name'); - -installSettingsGetter('theme-setting'); -installSettingsSetter('theme-setting'); -installSettingsGetter('hide-menu-bar'); -installSettingsSetter('hide-menu-bar'); - -installSettingsGetter('message-ttl'); -installSettingsSetter('message-ttl'); - -installSettingsGetter('read-receipt-setting'); -installSettingsSetter('read-receipt-setting'); - -installSettingsGetter('typing-indicators-setting'); -installSettingsSetter('typing-indicators-setting'); - -installSettingsGetter('notification-setting'); -installSettingsSetter('notification-setting'); -installSettingsGetter('audio-notification'); -installSettingsSetter('audio-notification'); - -installSettingsGetter('link-preview-setting'); -installSettingsSetter('link-preview-setting'); - -installSettingsGetter('spell-check'); -installSettingsSetter('spell-check'); - // This one is different because its single source of truth is userConfig, not IndexedDB ipc.on('get-media-permissions', event => { event.sender.send( @@ -1176,57 +1093,9 @@ ipc.on('set-media-permissions', (event, value) => { } }); -ipc.on('on-unblock-number', (event, number) => { - if (mainWindow && mainWindow.webContents) { - mainWindow.webContents.send('on-unblock-number', number); - } -}); - -installSettingsGetter('is-primary'); -installSettingsGetter('sync-request'); -installSettingsGetter('sync-time'); -installSettingsSetter('sync-time'); - -ipc.on('delete-all-data', () => { - if (mainWindow && mainWindow.webContents) { - mainWindow.webContents.send('delete-all-data'); - } -}); - function getDataFromMainWindow(name, callback) { ipc.once(`get-success-${name}`, (_event, error, value) => callback(error, value) ); mainWindow.webContents.send(`get-${name}`); } - -function installSettingsGetter(name) { - ipc.on(`get-${name}`, event => { - if (mainWindow && mainWindow.webContents) { - getDataFromMainWindow(name, (error, value) => { - const contents = event.sender; - if (contents.isDestroyed()) { - return; - } - - contents.send(`get-success-${name}`, error, value); - }); - } - }); -} - -function installSettingsSetter(name) { - ipc.on(`set-${name}`, (event, value) => { - if (mainWindow && mainWindow.webContents) { - ipc.once(`set-success-${name}`, (_event, error) => { - const contents = event.sender; - if (contents.isDestroyed()) { - return; - } - - contents.send(`set-success-${name}`, error); - }); - mainWindow.webContents.send(`set-${name}`, value); - } - }); -} diff --git a/preload.js b/preload.js index 1ce8b902b..c688b3696 100644 --- a/preload.js +++ b/preload.js @@ -147,16 +147,7 @@ window.resetDatabase = () => { ipc.send('resetDatabase'); }; -// Events for updating block number states across different windows. -// In this case we need these to update the blocked number -// collection on the main window from the settings window. -window.onUnblockNumber = number => ipc.send('on-unblock-number', number); - -ipc.on('mediaPermissionsChanged', () => { - Whisper.events.trigger('mediaPermissionsChanged'); -}); - -ipc.on('on-unblock-number', (event, number) => { +window.onUnblockNumber = number => { // Unblock the number if (window.BlockedNumberController) { window.BlockedNumberController.unblock(number); @@ -174,6 +165,10 @@ ipc.on('on-unblock-number', (event, number) => { ); } } +}; + +ipc.on('mediaPermissionsChanged', () => { + Whisper.events.trigger('mediaPermissionsChanged'); }); window.closeAbout = () => ipc.send('close-about'); @@ -196,7 +191,6 @@ ipc.on('set-up-as-standalone', () => { // Settings-related events -window.showSettings = () => ipc.send('show-settings'); window.showPermissionsPopup = () => ipc.send('show-permissions-popup'); ipc.on('add-dark-overlay', () => { @@ -239,37 +233,8 @@ window.setSettingValue = (settingID, value) => { } }; -installGetter('device-name', 'getDeviceName'); - -installGetter('theme-setting', 'getThemeSetting'); -installSetter('theme-setting', 'setThemeSetting'); -installGetter('hide-menu-bar', 'getHideMenuBar'); -installSetter('hide-menu-bar', 'setHideMenuBar'); - // Get the message TTL setting window.getMessageTTL = () => window.storage.get('message-ttl', 24); -installGetter('message-ttl', 'getMessageTTL'); -installSetter('message-ttl', 'setMessageTTL'); - -installGetter('read-receipt-setting', 'getReadReceiptSetting'); -installSetter('read-receipt-setting', 'setReadReceiptSetting'); - -installGetter('typing-indicators-setting', 'getTypingIndicatorsSetting'); -installSetter('typing-indicators-setting', 'setTypingIndicatorsSetting'); - -installGetter('notification-setting', 'getNotificationSetting'); -installSetter('notification-setting', 'setNotificationSetting'); -installGetter('audio-notification', 'getAudioNotification'); -installSetter('audio-notification', 'setAudioNotification'); - -installGetter('link-preview-setting', 'getLinkPreviewSetting'); -installSetter('link-preview-setting', 'setLinkPreviewSetting'); - -installGetter('spell-check', 'getSpellCheck'); -installSetter('spell-check', 'setSpellCheck'); - -installGetter('media-permissions', 'getMediaPermissions'); -installGetter('media-permissions', 'setMediaPermissions'); window.getMediaPermissions = () => new Promise((resolve, reject) => { @@ -283,80 +248,6 @@ window.getMediaPermissions = () => ipc.send('get-media-permissions'); }); -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(); - } -}); - -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; - } - - try { - await shutdown(); - ipc.send('now-ready-for-shutdown'); - } catch (error) { - ipc.send( - 'now-ready-for-shutdown', - error && error.stack ? error.stack : error - ); - } -}); - -function installGetter(name, functionName) { - ipc.on(`get-${name}`, async () => { - const getFn = window.Events[functionName]; - if (!getFn) { - ipc.send( - `get-success-${name}`, - `installGetter: ${functionName} not found for event ${name}` - ); - return; - } - try { - ipc.send(`get-success-${name}`, null, await getFn()); - } catch (error) { - ipc.send( - `get-success-${name}`, - error && error.stack ? error.stack : error - ); - } - }); -} - -function installSetter(name, functionName) { - ipc.on(`set-${name}`, async (_event, value) => { - const setFn = window.Events[functionName]; - if (!setFn) { - ipc.send( - `set-success-${name}`, - `installSetter: ${functionName} not found for event ${name}` - ); - return; - } - try { - await setFn(value); - ipc.send(`set-success-${name}`); - } catch (error) { - ipc.send( - `set-success-${name}`, - error && error.stack ? error.stack : error - ); - } - }); -} - window.addSetupMenuItems = () => ipc.send('add-setup-menu-items'); window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items'); diff --git a/settings_preload.js b/settings_preload.js deleted file mode 100644 index 97f94bc8a..000000000 --- a/settings_preload.js +++ /dev/null @@ -1,100 +0,0 @@ -/* global window */ - -const { ipcRenderer } = require('electron'); -const url = require('url'); -const i18n = require('./js/modules/i18n'); - -const config = url.parse(window.location.toString(), true).query; -const { locale } = config; -const localeMessages = ipcRenderer.sendSync('locale-data'); - -window.theme = config.theme; -window.i18n = i18n.setup(locale, localeMessages); - -window.getEnvironment = () => config.environment; -window.getVersion = () => config.version; -window.getAppInstance = () => config.appInstance; - -// So far we're only using this for Signal.Types -const Signal = require('./js/modules/signal'); - -window.Signal = Signal.setup({ - Attachments: null, - userDataPath: null, - getRegionCode: () => null, -}); - -window.closeSettings = () => ipcRenderer.send('close-settings'); - -// Events for updating block number states across different windows. -// In this case we need these to update the blocked number -// collection on the main window from the settings window. -window.onUnblockNumber = number => - ipcRenderer.send('on-unblock-number', number); - -window.getDeviceName = makeGetter('device-name'); - -window.getThemeSetting = makeGetter('theme-setting'); -window.setThemeSetting = makeSetter('theme-setting'); -window.getHideMenuBar = makeGetter('hide-menu-bar'); -window.setHideMenuBar = makeSetter('hide-menu-bar'); - -window.getSpellCheck = makeGetter('spell-check'); -window.setSpellCheck = makeSetter('spell-check'); - -window.getMessageTTL = makeGetter('message-ttl'); -window.setMessageTTL = makeSetter('message-ttl'); - -window.getReadReceiptSetting = makeGetter('read-receipt-setting'); -window.setReadReceiptSetting = makeSetter('read-receipt-setting'); - -window.getTypingIndicatorsSetting = makeGetter('typing-indicators-setting'); -window.setTypingIndicatorsSetting = makeSetter('typing-indicators-setting'); - -window.getNotificationSetting = makeGetter('notification-setting'); -window.setNotificationSetting = makeSetter('notification-setting'); -window.getAudioNotification = makeGetter('audio-notification'); -window.setAudioNotification = makeSetter('audio-notification'); - -window.getLinkPreviewSetting = makeGetter('link-preview-setting'); -window.setLinkPreviewSetting = makeSetter('link-preview-setting'); - -window.getMediaPermissions = makeGetter('media-permissions'); -window.setMediaPermissions = makeSetter('media-permissions'); - -window.isPrimary = makeGetter('is-primary'); -window.makeSyncRequest = makeGetter('sync-request'); -window.getLastSyncTime = makeGetter('sync-time'); -window.setLastSyncTime = makeSetter('sync-time'); - -window.deleteAllData = () => ipcRenderer.send('delete-all-data'); - -function makeGetter(name) { - return () => - new Promise((resolve, reject) => { - ipcRenderer.once(`get-success-${name}`, (event, error, value) => { - if (error) { - return reject(error); - } - - return resolve(value); - }); - ipcRenderer.send(`get-${name}`); - }); -} - -function makeSetter(name) { - return value => - new Promise((resolve, reject) => { - ipcRenderer.once(`set-success-${name}`, (event, error) => { - if (error) { - return reject(error); - } - - return resolve(); - }); - ipcRenderer.send(`set-${name}`, value); - }); -} - -require('./js/logging');