From 812fd1976d0f336da47be6479e325179c8c6e297 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Tue, 17 Dec 2024 08:57:48 -0500 Subject: [PATCH] Split out into separate method so it can early return --- ext/js/background/backend.js | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 5080cc7fe..efb40ed47 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1330,30 +1330,37 @@ export class Backend { this._clipboardMonitor.stop(); } + this._setupContextMenu(options); + + void this._accessibilityController.update(this._getOptionsFull(false)); + + this._sendMessageAllTabsIgnoreResponse({action: 'applicationOptionsUpdated', params: {source}}); + } + + /** + * @param {import('settings').ProfileOptions} options + */ + _setupContextMenu(options) { try { - if (chrome.contextMenus) { - if (options.general.enableContextMenuScanSelected) { - chrome.contextMenus.create({ - id: 'yomitan_lookup', - title: 'Lookup in Yomitan', - contexts: ['selection'], - }, () => this._checkLastError(chrome.runtime.lastError)); - chrome.contextMenus.onClicked.addListener((info) => { - if (info.selectionText) { - this._sendMessageAllTabsIgnoreResponse({action: 'frontendScanSelectedText'}); - } - }); - } else { - chrome.contextMenus.remove('yomitan_lookup', () => this._checkLastError(chrome.runtime.lastError)); - } + if (!chrome.contextMenus) { return; } + + if (options.general.enableContextMenuScanSelected) { + chrome.contextMenus.create({ + id: 'yomitan_lookup', + title: 'Lookup in Yomitan', + contexts: ['selection'], + }, () => this._checkLastError(chrome.runtime.lastError)); + chrome.contextMenus.onClicked.addListener((info) => { + if (info.selectionText) { + this._sendMessageAllTabsIgnoreResponse({action: 'frontendScanSelectedText'}); + } + }); + } else { + chrome.contextMenus.remove('yomitan_lookup', () => this._checkLastError(chrome.runtime.lastError)); } } catch (e) { log.error(e); } - - void this._accessibilityController.update(this._getOptionsFull(false)); - - this._sendMessageAllTabsIgnoreResponse({action: 'applicationOptionsUpdated', params: {source}}); } /**