-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
35 lines (30 loc) · 1.13 KB
/
Copy pathAppDelegate.swift
File metadata and controls
35 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import AppKit
final class AppDelegate: NSObject, NSApplicationDelegate {
private var openStatisticsWindow: (() -> Void)?
private var shouldOpenStatisticsWhenReady = false
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.accessory)
// 冷启动(含开机自启、Dock/应用程序/Launchpad/Raycast 手动启动)一律静默,
// 只驻留菜单栏;主窗口只在用户点 Dock 图标触发 reopen 时才打开。
}
func applicationShouldHandleReopen(
_ sender: NSApplication,
hasVisibleWindows flag: Bool
) -> Bool {
requestOpenStatisticsWindow()
return false
}
func installOpenStatisticsHandler(_ handler: @escaping () -> Void) {
openStatisticsWindow = handler
guard shouldOpenStatisticsWhenReady else { return }
shouldOpenStatisticsWhenReady = false
handler()
}
private func requestOpenStatisticsWindow() {
guard let openStatisticsWindow else {
shouldOpenStatisticsWhenReady = true
return
}
openStatisticsWindow()
}
}