feat(menubar): 新增可配置的实时菜单栏指标与设置预览
使用竖条显示 CPU、GPU、内存与磁盘占用,分行展示上传和下载速率。支持全选、取消全选与空选恢复品牌图标,实时指标跟随面板刷新间隔。
This commit is contained in:
+20
-2
@@ -17,6 +17,7 @@ import AppKit
|
||||
private let awake = KeepAwakeService()
|
||||
private let presentation = SettingsPresentation()
|
||||
private let appearance = AppearancePreferences()
|
||||
private let menuBarPreferences = MenuBarPreferences()
|
||||
private let language = LanguagePreferences()
|
||||
private var openSettingsAction: (() -> Void)?
|
||||
private var scenes: AnyObject?
|
||||
@@ -35,10 +36,21 @@ import AppKit
|
||||
MainActor.assumeIsolated { self?.metrics.setDisplaySleeping(sleeping) }
|
||||
})
|
||||
}
|
||||
let readings = { [metrics, menuBarPreferences, language] () -> [MenuBarReading] in
|
||||
let selected = menuBarPreferences.selected
|
||||
guard !selected.isEmpty else { return [] }
|
||||
let locale = language.locale
|
||||
return MenuBarReading.readings(selection: selected, snapshot: metrics.snapshot) {
|
||||
AppLocalization.string($0.titleKey, locale: locale)
|
||||
}
|
||||
}
|
||||
menuBarPreferences.onDemandChange = { [metrics] in metrics.setMenuBarEnabled($0) }
|
||||
metrics.setMenuBarEnabled(!menuBarPreferences.selected.isEmpty)
|
||||
let settings = NSHostingSceneRepresentation {
|
||||
Settings {
|
||||
AppLanguageScope(preferences: language, onChange: { self.configureMainMenu() }) { [self] in
|
||||
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling, presentation: presentation)
|
||||
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling,
|
||||
menuBar: menuBarPreferences, readings: readings, presentation: presentation)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +59,7 @@ import AppKit
|
||||
openSettingsAction = { settings.environment.openSettings() }
|
||||
configureMainMenu()
|
||||
metrics.setDetailDemand(processes: true, slowMetrics: true)
|
||||
menuBar = MenuPanelController(visibility: { [metrics] in metrics.setPanelVisible($0) },
|
||||
menuBar = MenuPanelController(readings: readings, visibility: { [metrics] in metrics.setPanelVisible($0) },
|
||||
menuTitle: { [language] key in
|
||||
AppLocalization.string("status." + key, locale: language.locale, table: "StatusItem")
|
||||
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
|
||||
@@ -104,5 +116,11 @@ import AppKit
|
||||
scenes = nil
|
||||
}
|
||||
|
||||
// Finder or Spotlight remains a settings entry point when macOS hides a wide status item.
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
if !flag { settingsCommand() }
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { false }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user