feat(settings): 新增关于菜单和基于正式发布的更新检测
This commit is contained in:
+18
-8
@@ -18,6 +18,7 @@ import notify
|
||||
private let metrics = MetricsStore()
|
||||
private let awake = KeepAwakeService()
|
||||
private let presentation = SettingsPresentation()
|
||||
private let updates = ReleaseUpdates()
|
||||
private let appearance = AppearancePreferences()
|
||||
private let menuBarPreferences = MenuBarPreferences()
|
||||
private let language = LanguagePreferences()
|
||||
@@ -57,7 +58,7 @@ import notify
|
||||
Settings {
|
||||
AppLanguageScope(preferences: language, onChange: { self.configureMainMenu() }) { [self] in
|
||||
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling,
|
||||
menuBar: menuBarPreferences, readings: readings, presentation: presentation)
|
||||
menuBar: menuBarPreferences, readings: readings, presentation: presentation, updates: updates)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,13 +70,12 @@ import notify
|
||||
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
|
||||
}, openSettings: { [weak self] in self?.settingsCommand() }, openAbout: { [weak self] in self?.aboutCommand() }) { [self] panel in
|
||||
AppLanguageScope(preferences: language) {
|
||||
MenuPanelView(metrics: self.metrics, preferences: self.appearance, keepAwake: self.awake, settingsPresentation: self.presentation,
|
||||
MenuPanelView(metrics: self.metrics, preferences: self.appearance, keepAwake: self.awake, updates: self.updates,
|
||||
presentation: panel, onOpenSettings: { [weak self] in
|
||||
self?.menuBar?.hide()
|
||||
settings.environment.openSettings()
|
||||
}, onPreferredHeight: { [weak self] height in
|
||||
self?.settingsCommand()
|
||||
}, onOpenAbout: { [weak self] in self?.aboutCommand() }, onPreferredHeight: { [weak self] height in
|
||||
self?.menuBar?.setPreferredContentHeight(height)
|
||||
})
|
||||
}
|
||||
@@ -87,6 +87,10 @@ import notify
|
||||
let root = NSMenu()
|
||||
let application = NSMenu()
|
||||
let appItem = NSMenuItem(); appItem.submenu = application; root.addItem(appItem)
|
||||
let about = NSMenuItem(title: AppLocalization.string("action.about", locale: language.locale), action: #selector(aboutCommand), keyEquivalent: "")
|
||||
about.target = self
|
||||
application.addItem(about)
|
||||
application.addItem(.separator())
|
||||
let settings = NSMenuItem(title: AppLocalization.string("action.settings", locale: language.locale), action: #selector(settingsCommand), keyEquivalent: ",")
|
||||
settings.target = self
|
||||
application.addItem(settings)
|
||||
@@ -106,9 +110,14 @@ import notify
|
||||
NSApp.mainMenu = root
|
||||
}
|
||||
|
||||
@objc private func settingsCommand() {
|
||||
func applicationDidFinishLaunching(_ notification: Notification) { updates.start() }
|
||||
|
||||
@objc private func settingsCommand() { showSettings() }
|
||||
@objc private func aboutCommand() { showSettings(.about) }
|
||||
|
||||
private func showSettings(_ page: SettingsPage? = nil) {
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
presentation.request()
|
||||
presentation.request(page)
|
||||
menuBar?.hide()
|
||||
openSettingsAction?()
|
||||
}
|
||||
@@ -118,6 +127,7 @@ import notify
|
||||
workspaceTokens.forEach(NSWorkspace.shared.notificationCenter.removeObserver)
|
||||
workspaceTokens.removeAll()
|
||||
menuBar?.shutdown()
|
||||
updates.stop()
|
||||
awake.disable()
|
||||
menuBar = nil
|
||||
openSettingsAction = nil
|
||||
|
||||
Reference in New Issue
Block a user