@@ -13,13 +13,29 @@ import Combine
1313@NSApplicationMain
1414class AppDelegate : NSObject , NSApplicationDelegate {
1515
16+ lazy var windows = NSWindow ( )
1617 var window : NSWindow !
1718
1819 func applicationDidFinishLaunching( _ aNotification: Notification ) {
1920
2021 SyncManager . shared. initialize ( )
2122
22- let contentView = SnipViewApp ( )
23+ createWindow ( )
24+ }
25+
26+ func applicationWillTerminate( _ aNotification: Notification ) {
27+ }
28+
29+ func application( _ application: NSApplication , open urls: [ URL ] ) {
30+ SyncManager . shared. handleDeepLink ( urls: urls)
31+ }
32+
33+
34+ // Window
35+
36+ func createWindow( ) {
37+
38+ let snipAppView = SnipViewApp ( )
2339 . environmentObject ( Settings ( ) )
2440 . environmentObject ( AppState ( ) )
2541 . edgesIgnoringSafeArea ( . top)
@@ -35,18 +51,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3551 window. isMovableByWindowBackground = true
3652 window. center ( )
3753 window. setFrameAutosaveName ( " Main Window " )
38- window. contentView = NSHostingView ( rootView: contentView)
54+ window. contentView = NSHostingView ( rootView: snipAppView)
55+ window. isReleasedWhenClosed = false
3956 DispatchQueue . main. async {
4057 self . window. orderOut ( nil )
4158 self . window. makeKeyAndOrderFront ( nil )
4259 }
4360 }
4461
45- func applicationWillTerminate( _ aNotification: Notification ) {
62+ func applicationShouldHandleReopen( _ sender: NSApplication , hasVisibleWindows flag: Bool ) -> Bool {
63+ if !flag {
64+ sender. windows. forEach { $0. makeKeyAndOrderFront ( self ) }
65+ }
66+ return true
4667 }
4768
48- func application( _ application: NSApplication , open urls: [ URL ] ) {
49- SyncManager . shared. handleDeepLink ( urls: urls)
69+
70+ // Menu
71+
72+ @IBAction func newWindow( _ sender: Any ) {
73+ window. makeKeyAndOrderFront ( self )
5074 }
5175}
5276
0 commit comments