Skip to content

Commit

Permalink
Split out into separate method so it can early return
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Dec 17, 2024
1 parent a5fac51 commit 812fd19
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}});
}

/**
Expand Down

0 comments on commit 812fd19

Please sign in to comment.