-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordAudioApp.swift
More file actions
53 lines (46 loc) · 1.87 KB
/
Copy pathRecordAudioApp.swift
File metadata and controls
53 lines (46 loc) · 1.87 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
import SwiftUI
import AppKit
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// Apply the saved Dock-icon preference as early as possible.
Appearance.applyDockPolicyFromDefaults()
}
// Keep running (in the menu bar) when the main window is closed.
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
false
}
// If a recording is in progress, finalize the file before quitting so it
// isn't left half-written and unplayable.
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
guard RecorderModel.shared?.isRecording == true else { return .terminateNow }
Task { @MainActor in
await RecorderModel.shared?.finishForQuit()
NSApp.reply(toApplicationShouldTerminate: true)
}
return .terminateLater
}
}
@main
struct RecordAudioApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@StateObject private var model = RecorderModel()
// Menu-bar visibility lives in AppStorage, NOT in the observed model, so the
// MenuBarExtra binding can never trigger a recording-UI re-render loop.
@AppStorage(Appearance.showMenuBarKey) private var showMenuBarIcon = true
var body: some Scene {
Window("RecordAudio", id: "main") {
MainView(model: model)
}
.defaultSize(width: 380, height: 460)
// Menu-bar icon is optional — toggled from Settings.
MenuBarExtra(isInserted: $showMenuBarIcon) {
MenuView(model: model)
} label: {
Image(systemName: model.isRecording ? "largecircle.fill.circle" : "waveform")
}
.menuBarExtraStyle(.window)
Settings {
SettingsView(model: model)
}
}
}