From 329adea6f3f6cc81af316647eb15de8c1e089c42 Mon Sep 17 00:00:00 2001 From: Croydon Date: Tue, 28 Mar 2017 11:16:19 +0200 Subject: [PATCH] Manage hotkey by WebExtension (#13) --- index.js | 67 +++++++------------------------ lib/verticaltabs.js | 26 ------------ package.json | 4 +- webextension/main.js | 7 ++++ webextension/manifest.json | 15 ++++++- webextension/options/options.js | 29 ++++++++----- webextension/options/options.json | 15 ++++--- 7 files changed, 63 insertions(+), 100 deletions(-) diff --git a/index.js b/index.js index 812067e..72e3952 100644 --- a/index.js +++ b/index.js @@ -11,13 +11,8 @@ var preferencesService = require("sdk/preferences/service"); var windows = require("sdk/windows"); var windowUtils = require("sdk/window/utils"); -var hotkey = require("sdk/hotkeys").Hotkey; var { viewFor } = require("sdk/view/core"); -//var contentMod = require("sdk/content/mod"); -//var Style = require("sdk/stylesheet/style").Style; - - // WebExtension const webExtension = require("sdk/webextension"); var webextPort; @@ -40,38 +35,8 @@ function toggleDrawInTitlebar() { } } -// Hotkeys -var GLOBAL_SCOPE = this; - -function hotkeyPress() -{ - let windowID = windowUtils.getOuterId(windowUtils.getToplevelWindow(windowUtils.getFocusedWindow())); - GLOBAL_SCOPE["vt"+windowID].toggleDisplayState(); -} - -function initHotkeys() { - let toggleKey = webextPreferences["toggleDisplayHotkey"]; - if(toggleKey != "") - { - GLOBAL_SCOPE.vtToggleDisplayHotkey = hotkey({ - combo: toggleKey, - onPress: hotkeyPress - }); - } -} - -function destroyHotkey() { - if(typeof GLOBAL_SCOPE.vtToggleDisplayHotkey != undefined) - { - GLOBAL_SCOPE.vtToggleDisplayHotkey.destroy(); - } -} -function changeHotkey() { - debugOutput("change Hotkey event!"); - destroyHotkey(); - initHotkeys(); -} +var GLOBAL_SCOPE = this; // // WebExtenions Communication @@ -147,6 +112,12 @@ function webext_replyHandler(message) let windowID = windowUtils.getOuterId(windowUtils.getFocusedWindow()); GLOBAL_SCOPE["vt"+windowID].changeFullscreenMode(message.value); } + + if(message.type == "event.toggleTabbrowser") + { + let windowID = windowUtils.getOuterId(windowUtils.getToplevelWindow(windowUtils.getFocusedWindow())); + GLOBAL_SCOPE["vt"+windowID].toggleDisplayState(); + } } // Send setting to WebExtension @@ -166,20 +137,13 @@ function webext_sendChangedSetting(settingName) function observPrefs(settingName) { - if(settingName == "toggleDisplayHotkey") - { - changeHotkey(); - } - else - { - for (let window of windows.browserWindows) - { - let lowLevelWindow = viewFor(window); - let windowID = windowUtils.getOuterId(lowLevelWindow); - debugOutput("observPrefs: " + settingName); - GLOBAL_SCOPE["vt"+windowID].onPreferenceChange(settingName, webextPreferences); - } - } + for (let window of windows.browserWindows) + { + let lowLevelWindow = viewFor(window); + let windowID = windowUtils.getOuterId(lowLevelWindow); + debugOutput("observPrefs: " + settingName); + GLOBAL_SCOPE["vt"+windowID].onPreferenceChange(settingName, webextPreferences); + } } // @@ -220,8 +184,6 @@ function sdk_init() { deinitialize_window(window) }); - - initHotkeys(); } // Entry point of the add-on @@ -275,7 +237,6 @@ exports.main = function (options, callbacks) { exports.onUnload = function (reason) { //debugOutput("onUnload:" + reason); - destroyHotkey(); for (let window of windows.browserWindows) { diff --git a/lib/verticaltabs.js b/lib/verticaltabs.js index d232e1d..19d4661 100644 --- a/lib/verticaltabs.js +++ b/lib/verticaltabs.js @@ -128,7 +128,6 @@ var VerticalTabsReloaded = class VerticalTabsReloaded if (this.preferences("compact") == true) { this.installStylesheet(this.preferences("dataPath") + "compact.css"); - //this.webext_sendMsg({type: "css.get", name: "compact", file: "compact.css"}); } if (this.preferences("style.tab.status") == true) @@ -296,32 +295,9 @@ var VerticalTabsReloaded = class VerticalTabsReloaded browserbox.dir = "normal"; } break; - case "css": - /*if(this.parsedStyle != undefined) - { - contentMod.detachFrom(this.parsedStyle, this.window); - } - - this.webExtPreferences = newValue; - let newStyle; - - Object.keys(this.webExtPreferences["css"]).forEach(k => - { - this.debugOutput(k); - newStyle = newStyle + this.webExtPreferences["css"][k]; - this.debugOutput(this.webExtPreferences["css"][k]); - }); - - var style = Style({ source: newStyle }); - this.parsedStyle = style; - this.debugOutput("css changed!"); - this.debugOutput(this.parsedStyle); - contentMod.attachTo(this.parsedStyle, this.window); - break;*/ case "theme": this.removeThemeStylesheet(); this.webExtPreferences = newValue; - //this.webext_sendMsg({type: "css.get", name: "theme", file: this.getThemeStylesheet(this.preferences("theme"))}); this.applyThemeStylesheet(); break; @@ -330,12 +306,10 @@ var VerticalTabsReloaded = class VerticalTabsReloaded if (this.preferences("compact") == true) { this.installStylesheet(this.preferences("dataPath") + "compact.css"); - //this.webext_sendMsg({type: "css.get", name: "compact", file: "compact.css"}); } else { this.removeStylesheet(this.preferences("dataPath") + "compact.css"); - //this.webext_sendMsg({type: "css.get", name: "compact", file: "none"}); } break; diff --git a/package.json b/package.json index a29f17d..5e445b3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "icon": "resource://verticaltabsreloaded-at-go-dev-dot-de/webextension/data/icon.png", "author": "Croydon", "license": "MPL-2.0", - "version": "0.8.3", + "version": "0.8.4-alpha", "permissions": { "private-browsing": true, @@ -15,7 +15,7 @@ }, "engines": { - "firefox": "53.0a1 - 55.0" + "firefox": "54.0a1 - 56.0" }, "hasEmbeddedWebExtension": true } diff --git a/webextension/main.js b/webextension/main.js index 7665a80..40533d0 100644 --- a/webextension/main.js +++ b/webextension/main.js @@ -188,6 +188,13 @@ setTimeout(function() { // Set up listener browser.storage.onChanged.addListener(sdk_send_all_settings); + browser.commands.onCommand.addListener(function(command) + { + if (command == "toggleTabbrowser") + { + sdk_sendMsg({type: "event.toggleTabbrowser"}); + } + }); }, 100); diff --git a/webextension/manifest.json b/webextension/manifest.json index 0405494..4dea682 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -2,7 +2,7 @@ "name": "Vertical Tabs Reloaded", "short_name": "VTR", "description": "This Firefox add-on arranges tabs in a vertical rather than horizontal fashion.", - "version": "0.8.3", + "version": "0.8.4-alpha", "manifest_version": 2, "author": "Michael 'Croydon' Keck", "developer": @@ -20,6 +20,17 @@ "page": "options/options.html", "browser_style": true }, + "commands": + { + "toggleTabbrowser": + { + "suggested_key": + { + "default": "Ctrl+Shift+V" + }, + "description": "Hotkey for hiding/showing the tabbrowser" + } + }, "icons": { "16": "data/icon-16.png", @@ -32,7 +43,7 @@ "gecko": { "id": "verticaltabsreloaded@go-dev.de", - "strict_min_version": "53.0" + "strict_min_version": "55.0" } } } diff --git a/webextension/options/options.js b/webextension/options/options.js index 48cb6e2..77773a7 100644 --- a/webextension/options/options.js +++ b/webextension/options/options.js @@ -46,11 +46,11 @@ function build() if(setting.description != undefined) { - var settingsDescription = '
' + setting.description + '
'; + var description = '
' + setting.description + ''; } else { - var settingsDescription = ""; + var description = ''; } if(setting.hidden == true) @@ -62,42 +62,49 @@ function build() var classHidden = ""; } + if(setting.readonly == true) + { + var addition = " disabled"; + } + else + { + var addition = ""; + } + if(setting.type == "bool") { - settingsHTML += '
' + settingsDescription + '
'; + settingsHTML += '
' + description +'
'; } if(setting.type == "string") { if(setting.placeholder == undefined) { setting.placeholder = ""; } - settingsHTML += '' + setting.title + settingsDescription + ' '; + settingsHTML += '' + setting.title + description +' '; } if(setting.type == "integer") { if(setting.placeholder == undefined) { setting.placeholder = ""; } - settingsHTML += '' + setting.title + settingsDescription + ' '; + settingsHTML += '' + setting.title + description +' '; } if(setting.type == "menulist") { - newInnerHTML = '' + setting.title + settingsDescription + ' '; Object.keys(setting.options).forEach(function(key) { let option = setting.options[key]; - newInnerHTML += ''; + settingsHTML += ''; }); - newInnerHTML += ''; - - settingsHTML += newInnerHTML; + settingsHTML += ''; } if(setting.type == "control") { - settingsHTML += '' + setting.title + settingsDescription + ' '; + settingsHTML += '' + setting.title + description +' '; } }); diff --git a/webextension/options/options.json b/webextension/options/options.json index e02eac0..f9f22d8 100644 --- a/webextension/options/options.json +++ b/webextension/options/options.json @@ -72,12 +72,6 @@ } ] }, - "toggleDisplayHotkey": { - "name": "toggleDisplayHotkey", - "type": "string", - "title": "Hotkey for hiding/showing tabbar", - "value": "control-alt-v" - }, "toggleDrawInTitlebar": { "name": "toggleDrawInTitlebar", "type": "control", @@ -105,6 +99,15 @@ "value": 250, "hidden": true }, + "toggleDisplayHotkey": { + "name": "toggleDisplayHotkey", + "type": "string", + "title": "Hotkey for hiding/showing tabbar", + "value": "control-alt-v", + "hidden": true, + "readonly": true, + "description": "Is now editable in the respective Firefox user interface" + }, "debug": { "name": "debug", "type": "bool",