forked from domzilla/Caffeine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaffeineApp.swift
More file actions
88 lines (78 loc) · 2.64 KB
/
Copy pathCaffeineApp.swift
File metadata and controls
88 lines (78 loc) · 2.64 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
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
//
// CaffeineApp.swift
// Caffeine
//
// Created by Dominic Rodemer on 11.11.25.
//
import SwiftUI
@main
struct CaffeineApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@State private var settings: SettingsModel
@State private var viewModel: CaffeineViewModel
init() {
let settings = SettingsModel()
self._settings = State(initialValue: settings)
self._viewModel = State(initialValue: CaffeineViewModel(settings: settings))
}
@State private var updater = UpdaterController()
var body: some Scene {
// macOS 27 recommended menu bar API. Renders the
// `active` / `inactive` template image as the icon and
// shows `MenuBarContentView` on left- or right-click.
MenuBarExtra {
MenuBarContentView(updater: self.updater)
.environment(self.viewModel)
} label: {
if self.viewModel.isActive {
Image(systemName: "leaf.fill")
} else {
Image(systemName: "leaf")
}
}
.menuBarExtraStyle(.menu)
// Native macOS Settings scene with a tabbed layout. The
// system owns the title bar, tab chrome, and appearance
// following.
//
// `.defaultSize()` sets the initial window size. The
// previous `.frame(minWidth:)` only constrained the
// content, not the window itself, so the window could
// open wider than 480.
Settings {
TabView {
Tab(
String(localized: "General"),
systemImage: "gearshape"
) {
GeneralSettingsView()
.environment(self.settings)
}
Tab(
String(localized: "Power"),
systemImage: "bolt"
) {
PowerSettingsView()
.environment(self.settings)
}
Tab(
String(localized: "Keyboard"),
systemImage: "keyboard"
) {
KeyboardSettingsView()
.environment(self.settings)
}
Tab(
String(localized: "About"),
systemImage: "info.circle"
) {
AboutSettingsView(updater: self.updater)
}
}
// .focusable(false)
.frame(minWidth: 440, minHeight: 400)
.environment(self.viewModel)
}
.defaultSize(width: 440, height: 400)
}
}