From 455b09566ae98f333fc82982c3cac8510d76ef35 Mon Sep 17 00:00:00 2001 From: svrnm Date: Thu, 28 Jul 2022 13:22:24 +0200 Subject: [PATCH] fix: update context menus. --- src/background.js | 26 ++++++++++++++------------ src/models/Badge.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/background.js b/src/background.js index af8ad23..756037b 100644 --- a/src/background.js +++ b/src/background.js @@ -139,6 +139,8 @@ try { return } + console.log(changeInfo.status) + scope.chrome.tabs.get(tabId, (tab) => { if (tab.url) { scope.chrome.scripting.executeScript({ @@ -149,7 +151,8 @@ try { console.log('Injection completed for', tabId, tab.url) }) } else { - console.log('Did not inject into tab ', tabId, 'Permission denied') + logger('warn', 'Did not inject into tab ', tabId, 'Permission denied').write() + badge.updateDemoCounter('!') } }) }) @@ -311,25 +314,24 @@ try { } }) - /* TODO: MV3 Unfixed scope.chrome.contextMenus.create({ - id: 'dmContextMenu', + id: 'dmToggleLiveMode', title: 'Toggle Live Mode', - contexts: ['browser_action'], - onclick: function () { - store.dispatch({ type: 'TOGGLE_LIVE_MODE' }) - } + contexts: ['action'] }) - scope.chrome.contextMenus.create({ - id: 'dmContextMenu', + id: 'dmToggleDebugMode', title: 'Toggle Debug Mode', - contexts: ['browser_action'], - onclick: function () { + contexts: ['action'] + }) + scope.chrome.contextMenus.onClicked.addListener((info, tab) => { + const { menuItemId } = info + if (menuItemId === 'dmToggleLiveMode') { + store.dispatch({ type: 'TOGGLE_LIVE_MODE' }) + } else if (menuItemId === 'dmToggleDebugMode') { store.dispatch({ type: 'TOGGLE_DEBUG_MODE' }) } }) - */ } })(globalThis) } catch (e) { diff --git a/src/models/Badge.js b/src/models/Badge.js index 8e9e8a4..dcf9968 100644 --- a/src/models/Badge.js +++ b/src/models/Badge.js @@ -45,7 +45,7 @@ class Badge { this.browserAction.getBadgeText({ tabId }, (oldText) => { // oldText can be undefined for a new tab, set it to '' const text = this._updateText(typeof oldText === 'undefined' ? '' : oldText, count + '') - const color = count > 0 ? '#952613' : '#5c832f' + const color = (count === '!' || count > 0) ? '#952613' : '#5c832f' this.browserAction.setBadgeText({ text, tabId }) this.browserAction.setBadgeBackgroundColor({ color,