A full-featured download manager.
feat: tray menu support disable item
Dr_rOot5c2acf12eed5
diff --git a/src/main/Application.js b/src/main/Application.jsindex 3f8eb3b1..acbc2ae9 100644--- a/src/main/Application.js+++ b/src/main/Application.js@@ -257,6 +257,7 @@ export default class Application extends EventEmitter {handleUpdaterEvents () {this.updateManager.on('checking', (event) => {this.menuManager.updateMenuItemEnabledState('app.check-for-updates', false)+ this.trayManager.updateMenuItemEnabledState('app.check-for-updates', false)})this.updateManager.on('download-progress', (event) => {@@ -266,10 +267,12 @@ export default class Application extends EventEmitter {this.updateManager.on('update-not-available', (event) => {this.menuManager.updateMenuItemEnabledState('app.check-for-updates', true)+ this.trayManager.updateMenuItemEnabledState('app.check-for-updates', true)})this.updateManager.on('update-downloaded', (event) => {this.menuManager.updateMenuItemEnabledState('app.check-for-updates', true)+ this.trayManager.updateMenuItemEnabledState('app.check-for-updates', true)const win = this.windowManager.getWindow('index')win.setProgressBar(0)})@@ -280,6 +283,7 @@ export default class Application extends EventEmitter {this.updateManager.on('update-error', (event) => {this.menuManager.updateMenuItemEnabledState('app.check-for-updates', true)+ this.trayManager.updateMenuItemEnabledState('app.check-for-updates', true)})}@@ -402,6 +406,7 @@ export default class Application extends EventEmitter {ipcMain.on('update-menu-states', (event, visibleStates, enabledStates, checkedStates) => {this.menuManager.updateMenuStates(visibleStates, enabledStates, checkedStates)+ this.trayManager.updateMenuStates(visibleStates, enabledStates, checkedStates)})ipcMain.on('download-status-change', (event, status) => {diff --git a/src/main/ui/TrayManager.js b/src/main/ui/TrayManager.jsindex 4b0de055..185810c5 100644--- a/src/main/ui/TrayManager.js+++ b/src/main/ui/TrayManager.js@@ -2,7 +2,11 @@ import { EventEmitter } from 'events'import { join } from 'path'import { Tray, Menu, systemPreferences } from 'electron'import is from 'electron-is'-import { translateTemplate } from '../utils/menu'+import {+ translateTemplate,+ flattenMenuItems,+ updateStates+} from '../utils/menu'import { getI18n } from '@/ui/Locale'import { LIGHT_THEME, DARK_THEME } from '@shared/constants'@@ -45,6 +49,7 @@ export default class TrayManager extends EventEmitter {const template = JSON.parse(JSON.stringify(this.template))const tpl = translateTemplate(template, keystrokesByCommand, this.i18n)this.menu = Menu.buildFromTemplate(tpl)+ this.items = flattenMenuItems(this.menu)}setup () {@@ -113,6 +118,24 @@ export default class TrayManager extends EventEmitter {this.updateIcon()}+ updateMenuStates (visibleStates, enabledStates, checkedStates) {+ updateStates(this.items, visibleStates, enabledStates, checkedStates)+ }++ updateMenuItemVisibleState (id, flag) {+ const visibleStates = {+ [id]: flag+ }+ this.updateMenuStates(visibleStates, null, null)+ }++ updateMenuItemEnabledState (id, flag) {+ const enabledStates = {+ [id]: flag+ }+ this.updateMenuStates(null, enabledStates, null)+ }+destroy () {tray.destroy()}