From c11c100cbb03d85ac1e797f5deba5a57a3c106ec Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 16:06:57 +0300 Subject: [PATCH] circumvent the bug with disabling check marks in Chrome 62+ fixes #272 --- background/background.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/background/background.js b/background/background.js index 2dfe2054..4ae24a2b 100644 --- a/background/background.js +++ b/background/background.js @@ -147,9 +147,13 @@ if (chrome.contextMenus) { chrome.contextMenus.create(item, ignoreChromeError); } }; - const toggleCheckmark = (id, checked) => { - chrome.contextMenus.update(id, {checked}, ignoreChromeError); - }; + + // circumvent the bug with disabling check marks in Chrome 62+ + // TODO: replace 1e6 with the actual rev. number when/if the bug is fixed + const toggleCheckmark = CHROME >= 3172 && CHROME <= 1e6 ? + (id => chrome.contextMenus.remove(id, () => createContextMenus([id]) + ignoreChromeError())) : + ((id, checked) => chrome.contextMenus.update(id, {checked}, ignoreChromeError)); + const togglePresence = (id, checked) => { if (checked) { createContextMenus([id]); @@ -157,6 +161,7 @@ if (chrome.contextMenus) { chrome.contextMenus.remove(id, ignoreChromeError); } }; + const keys = Object.keys(contextMenus); prefs.subscribe(keys.filter(id => typeof prefs.readOnlyValues[id] === 'boolean'), toggleCheckmark); prefs.subscribe(keys.filter(id => contextMenus[id].presentIf), togglePresence);