@@ -10,18 +10,19 @@ class WindowController: NSWindowController {
10
10
}
11
11
}
12
12
13
- class AppKitWindowManagerDelegate : NSObject , NSApplicationDelegate ,
14
- NSWindowDelegate
15
- {
16
-
17
- @Published var willTerminate = false
13
+ class AppKitWindowManagerDelegate : NSObject , NSApplicationDelegate , NSWindowDelegate {
14
+
18
15
var mainWindowController : WindowController ?
19
16
let recordingState = TapeRecorderState . shared
20
17
let storeKitManager = StoreManager . shared
21
18
let mainWindowIdentifier = NSUserInterfaceItemIdentifier ( " mainWindow " )
22
19
23
20
private var onboardingWindowController : NSWindowController ?
24
21
private var hudHostingView : NSHostingView < AnyView > ?
22
+ @MainActor private var confirmOnQuit : Bool {
23
+ AppState . shared. confirmOnQuit
24
+ }
25
+ @Published private var willTerminate = false
25
26
26
27
private var hudWindow : NSWindow ?
27
28
private var mainWindow : NSWindow ?
@@ -145,6 +146,42 @@ class AppKitWindowManagerDelegate: NSObject, NSApplicationDelegate,
145
146
onboardingWindowController? . showWindow ( nil )
146
147
window. center ( )
147
148
}
149
+
150
+ func applicationShouldTerminate( _ sender: NSApplication ) -> NSApplication . TerminateReply {
151
+ if confirmOnQuit {
152
+ self . willTerminate = true
153
+ self . promptQuitConfirmation ( )
154
+ return . terminateLater
155
+ }
156
+ return . terminateNow
157
+ }
158
+
159
+ /// dont close (user canceled)
160
+ func `continue`( ) {
161
+ NSApplication . shared. reply ( toApplicationShouldTerminate: false )
162
+ }
163
+ /// close
164
+ func close( ) {
165
+ NSApplication . shared. reply ( toApplicationShouldTerminate: true )
166
+ }
167
+
168
+ func promptQuitConfirmation( ) {
169
+ let alert = NSAlert ( )
170
+ alert. messageText = " Really Quit? "
171
+ alert. informativeText = " You will not be able to use your Global Recording Hotkey to record. "
172
+ alert. alertStyle = . critical
173
+ alert. addButton ( withTitle: " Yes " )
174
+ alert. addButton ( withTitle: " No " )
175
+
176
+ DispatchQueue . main. async {
177
+ let response = alert. runModal ( )
178
+ if response == . alertFirstButtonReturn {
179
+ self . close ( )
180
+ } else {
181
+ self . continue ( )
182
+ }
183
+ }
184
+ }
148
185
149
186
/*
150
187
A function like this should never exist.
0 commit comments