-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFolderColorApp.swift
94 lines (76 loc) · 2.13 KB
/
FolderColorApp.swift
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// FolderColorApp.swift
// FolderColor
//
// Created by 黄宝成 on 2022/5/5.
//
import SwiftUI
import SwiftUIFlux
let store = Store<AppState>(reducer: appStateReducer, state: AppState())
struct WindowAccessor: NSViewRepresentable {
var callback: (NSWindow) -> ()
func makeNSView(context: Context) -> NSView {
let nsView = NSView()
DispatchQueue.main.async {
if let window = nsView.window {
self.callback(window)
}
}
return nsView
}
func updateNSView(_ nsView: NSView, context: Context) {}
}
struct FixedSizeWindow: NSViewControllerRepresentable {
func makeNSViewController(context: Context) -> NSViewController {
let viewController = NSViewController()
let hostingController = NSHostingController(rootView: ContentView())
viewController.view = hostingController.view
viewController.view.window?.styleMask.remove(.resizable)
if let window = viewController.view.window {
window.setContentSize(NSSize(width: 400, height: 500))
window.minSize = NSSize(width: 400, height: 500)
window.maxSize = NSSize(width: 400, height: 500)
}
return viewController
}
func updateNSViewController(_ nsViewController: NSViewController, context: Context) {
// No update needed
}
}
@main
struct FolderColorApp: App {
// 应用程序生命周期
@Environment(\.scenePhase) var scenePhase
// 存档计时器
let archiveTimer: Timer
func initColor() {
// 判断是否是第一次启动
if LaunchManagerUtil.isFirstLaunch() {
// 第一次启动时的操作
print("This is the first launch.")
// 设置标志为已启动
LaunchManagerUtil.setFirstLaunchFlag()
} else {
// 不是第一次启动时的操作
print("This is not the first launch.")
}
}
init() {
archiveTimer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true, block: { _ in
store.state.archiveState()
})
initColor()
}
var body: some Scene {
WindowGroup {
StoreProvider(store: store) {
FixedSizeWindow()
.frame(width: 400, height: 500)
.background(WindowAccessor { window in
window.title = "Folders Color"
})
}
}
// WindowGroup end
}
} // DouYaDrinkWaterNoFireBaseApp end