@@ -23,8 +23,7 @@ struct ExtendFSApp: App {
2323
2424 init ( ) {
2525 // handle unmounted disks that were previously unmounted during a quit event, probably indicating an App Store update relaunch
26-
27- if let contents = try ? FileManager . default. contentsOfDirectory ( at: URL . temporaryDirectory, includingPropertiesForKeys: nil ) {
26+ if let contents = try ? FileManager . default. contentsOfDirectory ( at: URL . temporaryDirectory, includingPropertiesForKeys: [ . creationDateKey] ) {
2827 let bsdList = contents
2928 . filter ( { $0. lastPathComponent. starts ( with: " unmounted- " ) } )
3029 guard bsdList. count > 0 else {
@@ -46,6 +45,11 @@ struct ExtendFSApp: App {
4645 logger. error ( " Couldn't create disk from BSD name \( bsd, privacy: . public) " )
4746 }
4847
48+ if let creationDate = try ? name. resourceValues ( forKeys: [ . creationDateKey] ) . creationDate, abs ( creationDate. timeIntervalSinceNow) > 60 * 10 {
49+ logger. log ( " Disk was marked as unmounted more than 10 minutes ago, which is strange. Will open GUI as a fallback " )
50+ couldCleanAllItems = false
51+ }
52+
4953 do {
5054 try FileManager . default. removeItem ( at: name)
5155 } catch {
@@ -66,6 +70,8 @@ struct ExtendFSApp: App {
6670 . onOpenURL { url in
6771 guard !delegate. wasStartedForGUI, url. scheme == " extendfs-internal-diskwatch " else { return }
6872
73+ logger. log ( " Got request to monitor disk \( url. lastPathComponent, privacy: . public) " )
74+
6975 dismissWindow ( id: " main " )
7076 let devNode = url. path ( percentEncoded: false )
7177 NSApp . hide ( nil )
@@ -87,9 +93,17 @@ struct ExtendFSApp: App {
8793 }
8894 do {
8995 try Task . checkCancellation ( )
96+ logger. log ( " Normal app launch " )
9097 delegate. wasStartedForGUI = true
9198 NSApp . setActivationPolicy ( . regular)
9299 NSApp . activate ( )
100+ if !NSApp. isActive {
101+ // weird workaround since LSUIElement is set to avoid dock flickering, but that causes the window to not be activated by default
102+ // either this will activate the GUI, or a background process which is setup to then activate the GUI
103+ let appURL = Bundle . main. bundleURL
104+ let config = NSWorkspace . OpenConfiguration ( )
105+ NSWorkspace . shared. openApplication ( at: appURL, configuration: config)
106+ }
93107 } catch { }
94108 }
95109 }
0 commit comments