Skip to content

Commit dfdf8df

Browse files
committed
Make it so when the user tries to reopen the already opened app, it sets the activation policy to regular and shows the app.
1 parent 35cf699 commit dfdf8df

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sm_osx/sm_osxApp.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,22 @@ struct sm_osxApp: App {
190190
}
191191
}
192192

193-
//why apple, why, WHY. Couldn't find anything that would work in the swiftui lifecycle, so this will do.
194193
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
195194

196195
func applicationWillFinishLaunching(_ notification: Notification) {
197196
flushSavedWindowState()
198197
}
199198

199+
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
200+
if NSApp.activationPolicy() == .prohibited {
201+
NSApp.setActivationPolicy(.regular)
202+
203+
showApp()
204+
}
205+
206+
return true
207+
}
208+
200209
func flushSavedWindowState() {
201210
do {
202211
let libURL = try FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)

0 commit comments

Comments
 (0)