perf(efficiency): 接入真实CPU能量并隔离展示与采样需求
This commit is contained in:
+18
-2
@@ -13,7 +13,7 @@ import AppKit
|
||||
}
|
||||
|
||||
@MainActor private final class ApplicationLifecycle: NSObject, NSApplicationDelegate {
|
||||
private let metrics = MetricsStore()
|
||||
private let metrics = MetricsStore(energyEnabled: PanelResourceAudit.omitted != "energy")
|
||||
private let awake = KeepAwakeService()
|
||||
private let presentation = SettingsPresentation()
|
||||
private let appearance = AppearancePreferences()
|
||||
@@ -21,8 +21,20 @@ import AppKit
|
||||
private var openSettingsAction: (() -> Void)?
|
||||
private var scenes: AnyObject?
|
||||
private var menuBar: MenuPanelController?
|
||||
private var workspaceTokens: [NSObjectProtocol] = []
|
||||
|
||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
||||
let center = NSWorkspace.shared.notificationCenter
|
||||
for (name, sleeping) in [(NSWorkspace.willSleepNotification, true), (NSWorkspace.didWakeNotification, false)] {
|
||||
workspaceTokens.append(center.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated { self?.metrics.setSystemSleeping(sleeping) }
|
||||
})
|
||||
}
|
||||
for (name, sleeping) in [(NSWorkspace.screensDidSleepNotification, true), (NSWorkspace.screensDidWakeNotification, false)] {
|
||||
workspaceTokens.append(center.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated { self?.metrics.setDisplaySleeping(sleeping) }
|
||||
})
|
||||
}
|
||||
let settings = NSHostingSceneRepresentation {
|
||||
Settings {
|
||||
AppLanguageScope(preferences: language, onChange: { self.configureMainMenu() }) { [self] in
|
||||
@@ -38,7 +50,9 @@ import AppKit
|
||||
menuTitle: { [language] key in
|
||||
AppLocalization.string("status." + key, locale: language.locale, table: "StatusItem")
|
||||
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
|
||||
if PanelResourceAudit.omitted == "all" {
|
||||
if PanelResourceAudit.omitted == "text" {
|
||||
TextMonitoringAuditView(metrics: self.metrics, appearance: self.appearance)
|
||||
} else if PanelResourceAudit.omitted == "all" {
|
||||
Text(verbatim: "Kymo").frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
AppLanguageScope(preferences: language) {
|
||||
@@ -84,6 +98,8 @@ import AppKit
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
workspaceTokens.forEach(NSWorkspace.shared.notificationCenter.removeObserver)
|
||||
workspaceTokens.removeAll()
|
||||
menuBar?.shutdown()
|
||||
awake.disable()
|
||||
menuBar = nil
|
||||
|
||||
Reference in New Issue
Block a user