@@ -181,6 +181,12 @@ final class WelcomeViewModel {
181181
182182 loadConnections ( )
183183 linkedConnections = LinkedFolderWatcher . shared. linkedConnections
184+
185+ if let appDelegate = NSApp . delegate as? AppDelegate ,
186+ let pendingURL = appDelegate. pendingConnectionShareURL {
187+ appDelegate. pendingConnectionShareURL = nil
188+ activeSheet = . importFile( pendingURL)
189+ }
184190 }
185191
186192 deinit {
@@ -504,15 +510,25 @@ final class WelcomeViewModel {
504510 }
505511
506512 func focusConnectionFormWindow( ) {
513+ if let window = NSApp . windows. first ( where: { $0. identifier? . rawValue == " connection-form " } ) {
514+ window. makeKeyAndOrderFront ( nil )
515+ return
516+ }
517+
518+ var observer : NSObjectProtocol ?
519+ observer = NotificationCenter . default. addObserver (
520+ forName: NSWindow . didBecomeKeyNotification,
521+ object: nil ,
522+ queue: . main
523+ ) { notification in
524+ guard let window = notification. object as? NSWindow ,
525+ window. identifier? . rawValue == " connection-form " else { return }
526+ if let observer { NotificationCenter . default. removeObserver ( observer) }
527+ }
528+
507529 Task { @MainActor in
508- for _ in 0 ..< 10 {
509- for window in NSApp . windows where
510- window. identifier? . rawValue == " connection-form " {
511- window. makeKeyAndOrderFront ( nil )
512- return
513- }
514- try ? await Task . sleep ( for: . milliseconds( 20 ) )
515- }
530+ try ? await Task . sleep ( for: . milliseconds( 500 ) )
531+ if let observer { NotificationCenter . default. removeObserver ( observer) }
516532 }
517533 }
518534
0 commit comments