From 77b744e675f8abf17ff5e8433f4f1717e0c9ffb5 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 3 May 2020 04:39:24 +0300 Subject: Modifier key profile condition (#487) * update Frontend options on modifier change * add modifier key profile condition * use select element for modifier condition value * support "is" and "is not" modifier key conditions * use plural * remove dead null check it's never null in that function * pass element on rather than assigning to this * rename event * remove Firefox OS key to Meta detection * hide Meta from dropdown on Firefox * move input type --- ext/fg/js/frontend.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 76ad27e0..d979246d 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -50,6 +50,9 @@ class Frontend { ); this._textScanner.onSearchSource = this.onSearchSource.bind(this); + this._activeModifiers = new Set(); + this._optionsUpdatePending = false; + this._windowMessageHandlers = new Map([ ['popupClose', () => this._textScanner.clearSelection(false)], ['selectionCopy', () => document.execCommand('copy')] @@ -90,6 +93,7 @@ class Frontend { chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); this._textScanner.on('clearSelection', this.onClearSelection.bind(this)); + this._textScanner.on('activeModifiersChanged', this.onActiveModifiersChanged.bind(this)); this._updateContentScale(); this._broadcastRootPopupInformation(); @@ -173,12 +177,21 @@ class Frontend { } } + async updatePendingOptions() { + if (this._optionsUpdatePending) { + this._optionsUpdatePending = false; + await this.updateOptions(); + } + } + async setTextSource(textSource) { await this.onSearchSource(textSource, 'script'); this._textScanner.setCurrentTextSource(textSource); } async onSearchSource(textSource, cause) { + await this.updatePendingOptions(); + let results = null; try { @@ -254,12 +267,24 @@ class Frontend { onClearSelection({passive}) { this.popup.hide(!passive); this.popup.clearAutoPlayTimer(); + this.updatePendingOptions(); + } + + async onActiveModifiersChanged({modifiers}) { + if (areSetsEqual(modifiers, this._activeModifiers)) { return; } + this._activeModifiers = modifiers; + if (await this.popup.isVisible()) { + this._optionsUpdatePending = true; + return; + } + await this.updateOptions(); } async getOptionsContext() { const url = this._getUrl !== null ? await this._getUrl() : window.location.href; const depth = this.popup.depth; - return {depth, url}; + const modifierKeys = [...this._activeModifiers]; + return {depth, url, modifierKeys}; } _showPopupContent(textSource, optionsContext, type=null, details=null) { -- cgit v1.2.3