MCPcopy Create free account
hub / github.com/zxlie/FeHelper / _updateBrowserAction

Function _updateBrowserAction

apps/background/background.js:443–514  ·  view source on GitHub ↗
(action, showTips, menuOnly)

Source from the content-addressed store, hash-verified

441 * @private
442 */
443 let _updateBrowserAction = function (action, showTips, menuOnly) {
444 if (!menuOnly) {
445 // 对于卸载操作,添加一个小延迟确保存储操作完成
446 const delay = action === 'offload' ? 100 : 0;
447
448 setTimeout(() => {
449 // 如果有安装过工具,则显示Popup模式
450 Awesome.getInstalledTools().then(tools => {
451 // 计算已安装的工具数量
452 const installedTools = Object.keys(tools).filter(tool => tools[tool].installed);
453 const installedCount = installedTools.length;
454
455 if (installedCount > 1) {
456 // 多个工具:显示popup
457 chrome.action.setPopup({ popup: '/popup/index.html' });
458 // 移除点击监听器(如果存在)
459 if (chrome.action.onClicked.hasListener(browserActionClickedHandler)) {
460 chrome.action.onClicked.removeListener(browserActionClickedHandler);
461 }
462 } else if (installedCount === 1) {
463 // 只有一个工具:直接打开工具,不显示popup
464 chrome.action.setPopup({ popup: '' });
465
466 // 添加点击监听器
467 if (!chrome.action.onClicked.hasListener(browserActionClickedHandler)) {
468 chrome.action.onClicked.addListener(browserActionClickedHandler);
469 }
470 } else {
471 // 没有安装任何工具:显示popup(让用户去安装工具)
472 chrome.action.setPopup({ popup: '/popup/index.html' });
473 // 移除点击监听器(如果存在)
474 if (chrome.action.onClicked.hasListener(browserActionClickedHandler)) {
475 chrome.action.onClicked.removeListener(browserActionClickedHandler);
476 }
477 }
478 });
479 }, delay);
480
481 if (action === 'offload') {
482 _animateTips('-1');
483 } else if(action) {
484 _animateTips('+1');
485 }
486 } else {
487 // 重绘菜单
488 Menu.rebuild();
489 }
490
491 if (showTips) {
492 let actionTxt;
493 switch (action) {
494 case 'install':
495 actionTxt = '工具已「安装」成功,并已添加到弹出下拉列表,点击FeHelper图标可正常使用!';
496 break;
497 case 'offload':
498 actionTxt = '工具已「卸载」成功,并已从弹出下拉列表中移除!';
499 break;
500 case 'menu-install':

Callers 1

_addExtensionListenerFunction · 0.85

Calls 3

setTimeoutFunction · 0.85
_animateTipsFunction · 0.85
notifyTextFunction · 0.70

Tested by

no test coverage detected