Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Commit 3dfa477

Browse files
committed
Extract start daemon function
1 parent f8454e4 commit 3dfa477

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

CodeReady Containers/AppDelegate.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
7676
})
7777

7878
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.\nError: \(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()
10380
}
10481

10582
DispatchQueue.global(qos: .background).async {
@@ -113,6 +90,33 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
11390
NotificationCenter.default.addObserver(self, selector: #selector(updateViewWithClusterStatus(_:)), name: statusNotification, object: nil)
11491
}
11592

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.\nError: \(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+
116120
func applicationWillTerminate(_ aNotification: Notification) {
117121
// Insert code here to tear down your application
118122
// Maybe kill the daemon too

0 commit comments

Comments
 (0)