Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit c424612

Browse files
committed
New window handling
1 parent 10a7403 commit c424612

File tree

3 files changed

+35
-197
lines changed

3 files changed

+35
-197
lines changed

Snip.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@
710710
CODE_SIGN_IDENTITY = "Mac Developer";
711711
CODE_SIGN_STYLE = Manual;
712712
COMBINE_HIDPI_IMAGES = YES;
713-
CURRENT_PROJECT_VERSION = 2;
713+
CURRENT_PROJECT_VERSION = 3;
714714
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
715715
DEVELOPMENT_TEAM = 7XBGRFP286;
716716
ENABLE_HARDENED_RUNTIME = YES;
@@ -737,7 +737,7 @@
737737
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application";
738738
CODE_SIGN_STYLE = Manual;
739739
COMBINE_HIDPI_IMAGES = YES;
740-
CURRENT_PROJECT_VERSION = 2;
740+
CURRENT_PROJECT_VERSION = 3;
741741
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
742742
DEVELOPMENT_TEAM = 7XBGRFP286;
743743
ENABLE_HARDENED_RUNTIME = YES;

Snip/AppDelegate.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@ import Combine
1313
@NSApplicationMain
1414
class 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

Comments
 (0)