From 3dc3667b4577bb51e9592184421bcce144b36b5e Mon Sep 17 00:00:00 2001 From: Axel Date: Fri, 13 Oct 2017 20:39:18 +0200 Subject: [PATCH] Add setting to hide menu bar (#1551) * Add setting to hide menu bar Add a setting in the themes section to hide the menu bar. The menu bar is not needed in everyday use and might not fit in with signals dark theme. The hidden menu bar can still be shown by pressing alt. autoHideMenuBar is added to windowConfig and saved and restored on startup to prevent flickering. * Trigger events only when related setting changes Set the event to trigger on instanciation of the view. Notification settings no longer reapply the theme or menu bar settings. * Save window state when closing the window When not moving or resizing the window, no BrowserWindow config would be created and saved. --- _locales/en/messages.json | 4 ++++ background.html | 5 +++++ js/views/app_view.js | 9 ++++++++- js/views/settings_view.js | 19 +++++++++++++++++-- main.js | 11 +++++++++++ preload.js | 6 ++++++ 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e9f2af36e..e1b7cebf2 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -812,6 +812,10 @@ "message": "Android (dark)", "description": "Label text for dark Android theme" }, + "hideMenuBar": { + "message": "Hide menu bar", + "description": "Label text for menu bar visibility setting" + }, "newContact": { "message": "Click to create new contact", "description": "" diff --git a/background.html b/background.html index 1d6d25d17..d0f19e61c 100644 --- a/background.html +++ b/background.html @@ -583,6 +583,11 @@ +
+

{{ notifications }}

diff --git a/js/views/app_view.js b/js/views/app_view.js index bf587136f..6d34853d9 100644 --- a/js/views/app_view.js +++ b/js/views/app_view.js @@ -8,12 +8,14 @@ this.inboxView = null; this.installView = null; this.applyTheme(); + this.applyHideMenu(); }, events: { 'click .openInstaller': 'openInstaller', 'click .openStandalone': 'openStandalone', 'openInbox': 'openInbox', - 'change-theme': 'applyTheme' + 'change-theme': 'applyTheme', + 'change-hide-menu': 'applyHideMenu', }, applyTheme: function() { var theme = storage.get('theme-setting') || 'android'; @@ -22,6 +24,11 @@ .removeClass('android') .addClass(theme); }, + applyHideMenu: function() { + var hideMenuBar = storage.get('hide-menu-bar', false); + window.setAutoHideMenuBar(hideMenuBar); + window.setMenuBarVisibility(!hideMenuBar); + }, openView: function(view) { this.el.innerHTML = ""; this.el.append(view.el); diff --git a/js/views/settings_view.js b/js/views/settings_view.js index e8a2171cf..65374dce0 100644 --- a/js/views/settings_view.js +++ b/js/views/settings_view.js @@ -9,6 +9,7 @@ initialize: function(options) { this.name = options.name; this.defaultValue = options.defaultValue; + this.event = options.event; this.populate(); }, events: { @@ -18,6 +19,9 @@ var value = e.target.checked; storage.put(this.name, value); console.log(this.name, 'changed to', value); + if (this.event) { + this.$el.trigger(this.event); + } }, populate: function() { var value = storage.get(this.name, this.defaultValue); @@ -28,6 +32,7 @@ initialize: function(options) { this.name = options.name; this.defaultValue = options.defaultValue; + this.event = options.event; this.populate(); }, events: { @@ -37,7 +42,9 @@ var value = this.$(e.target).val(); storage.put(this.name, value); console.log(this.name, 'changed to', value); - this.$el.trigger('change-theme'); + if (this.event) { + this.$el.trigger(this.event); + } }, populate: function() { var value = storage.get(this.name, this.defaultValue); @@ -57,13 +64,20 @@ new RadioButtonGroupView({ el: this.$('.theme-settings'), defaultValue: 'android', - name: 'theme-setting' + name: 'theme-setting', + event: 'change-theme' }); new CheckboxView({ el: this.$('.audio-notification-setting'), defaultValue: false, name: 'audio-notification' }); + new CheckboxView({ + el: this.$('.menu-bar-setting'), + defaultValue: false, + name: 'hide-menu-bar', + event: 'change-hide-menu' + }); if (textsecure.storage.user.getDeviceId() != '1') { var syncView = new SyncView().render(); this.$('.content').append(syncView.el); @@ -84,6 +98,7 @@ nameOnly: i18n('nameOnly'), audioNotificationDescription: i18n('audioNotificationDescription'), themeAndroidDark: i18n('themeAndroidDark'), + hideMenuBar: i18n('hideMenuBar'), }; } }); diff --git a/main.js b/main.js index 33945d66f..57e98fe80 100644 --- a/main.js +++ b/main.js @@ -58,6 +58,7 @@ function createWindow () { height: 610, minWidth: 700, minHeight: 360, + autoHideMenuBar: false, webPreferences: { nodeIntegration: false, //sandbox: true, @@ -81,6 +82,7 @@ function createWindow () { // so if we need to recreate the window, we have the most recent settings windowConfig = { maximized: mainWindow.isMaximized(), + autoHideMenuBar: mainWindow.isMenuBarAutoHide(), width: size[0], height: size[1], x: position[0], @@ -99,6 +101,7 @@ function createWindow () { mainWindow.on('resize', captureAndSaveWindowStats); mainWindow.on('move', captureAndSaveWindowStats); + mainWindow.on('close', captureAndSaveWindowStats); mainWindow.on('focus', function() { mainWindow.flashFrame(false); @@ -260,3 +263,11 @@ ipc.on('restart', function(event) { app.relaunch(); app.quit(); }); + +ipc.on("set-auto-hide-menu-bar", function(event, autoHide) { + mainWindow.setAutoHideMenuBar(autoHide); +}); + +ipc.on("set-menu-bar-visibility", function(event, visibility) { + mainWindow.setMenuBarVisibility(visibility); +}); diff --git a/preload.js b/preload.js index 6490e97bf..19f928190 100644 --- a/preload.js +++ b/preload.js @@ -21,6 +21,12 @@ console.log('show window'); ipc.send('show-window'); }; + window.setAutoHideMenuBar = function(autoHide) { + ipc.send('set-auto-hide-menu-bar', autoHide); + }; + window.setMenuBarVisibility = function(visibility) { + ipc.send('set-menu-bar-visibility', visibility); + }; window.restart = function() { console.log('restart'); ipc.send('restart');