@@ -76,30 +76,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
76
76
} )
77
77
78
78
DispatchQueue . global ( qos: . background) . async {
79
- let task = Process ( )
80
- let stdin = Pipe ( )
81
- #if DEBUG
82
- task. launchPath = " /usr/local/bin/crc "
83
- #else
84
- task. launchPath = NSString . path ( withComponents: [ Bundle . main. bundlePath, " Contents " , " Resources " , " crc " ] )
85
- #endif
86
- task. arguments = [ " daemon " , " --watchdog " ]
87
- task. standardInput = stdin
88
- do {
89
- try task. run ( )
90
- } catch let error {
91
- fatal ( message: " Cannot start the daemon " ,
92
- informativeMsg: " Check the logs and restart the application. \n Error: \( error. localizedDescription) " )
93
- return
94
- }
95
- task. waitUntilExit ( )
96
- if task. terminationStatus == 2 {
97
- fatal ( message: " Setup incomplete " ,
98
- informativeMsg: " Open a terminal, run 'crc setup', and start again this application. " )
99
- } else {
100
- fatal ( message: " Daemon crashed " ,
101
- informativeMsg: " Check the logs and restart the application " )
102
- }
79
+ self . startDaemon ( )
103
80
}
104
81
105
82
DispatchQueue . global ( qos: . background) . async {
@@ -113,6 +90,33 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
113
90
NotificationCenter . default. addObserver ( self , selector: #selector( updateViewWithClusterStatus ( _: ) ) , name: statusNotification, object: nil )
114
91
}
115
92
93
+ func startDaemon( ) {
94
+ let task = Process ( )
95
+ let stdin = Pipe ( )
96
+ #if DEBUG
97
+ task. launchPath = " /usr/local/bin/crc "
98
+ #else
99
+ task. launchPath = NSString . path ( withComponents: [ Bundle . main. bundlePath, " Contents " , " Resources " , " crc " ] )
100
+ #endif
101
+ task. arguments = [ " daemon " , " --watchdog " ]
102
+ task. standardInput = stdin
103
+ do {
104
+ try task. run ( )
105
+ } catch let error {
106
+ fatal ( message: " Cannot start the daemon " ,
107
+ informativeMsg: " Check the logs and restart the application. \n Error: \( error. localizedDescription) " )
108
+ return
109
+ }
110
+ task. waitUntilExit ( )
111
+ if task. terminationStatus == 2 {
112
+ fatal ( message: " Setup incomplete " ,
113
+ informativeMsg: " Open a terminal, run 'crc setup', and start again this application. " )
114
+ } else {
115
+ fatal ( message: " Daemon crashed " ,
116
+ informativeMsg: " Check the logs and restart the application " )
117
+ }
118
+ }
119
+
116
120
func applicationWillTerminate( _ aNotification: Notification ) {
117
121
// Insert code here to tear down your application
118
122
// Maybe kill the daemon too
0 commit comments