I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 1a00f731 authored by meeh's avatar meeh
Browse files

OSX Launcher: Extended start/stop/load/unload to be able to set...

OSX Launcher: Extended start/stop/load/unload to be able to set terminationHandler for more reliable execution.
parent d8cfe21e
No related branches found
No related tags found
No related merge requests found
...@@ -34,15 +34,15 @@ extension LaunchAgent { ...@@ -34,15 +34,15 @@ extension LaunchAgent {
/// Run `launchctl start` on the agent /// Run `launchctl start` on the agent
/// ///
/// Check the status of the job with `.status()` /// Check the status of the job with `.status()`
public func start() { public func start(_ callback: ((Process) -> Void)? = nil ) {
LaunchAgentManager.shared.start(self) LaunchAgentManager.shared.start(self, callback)
} }
/// Run `launchctl stop` on the agent /// Run `launchctl stop` on the agent
/// ///
/// Check the status of the job with `.status()` /// Check the status of the job with `.status()`
public func stop() { public func stop(_ callback: ((Process) -> Void)? = nil ) {
LaunchAgentManager.shared.stop(self) LaunchAgentManager.shared.stop(self, callback)
} }
/// Run `launchctl load` on the agent /// Run `launchctl load` on the agent
......
...@@ -88,41 +88,53 @@ extension LaunchAgentManager { ...@@ -88,41 +88,53 @@ extension LaunchAgentManager {
/// Run `launchctl start` on the agent /// Run `launchctl start` on the agent
/// ///
/// Check the status of the job with `.status(_: LaunchAgent)` /// Check the status of the job with `.status(_: LaunchAgent)`
public func start(_ agent: LaunchAgent) { public func start(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) {
let arguments = ["start", agent.label] let arguments = ["start", agent.label]
Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments) let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
if ((termHandler) != nil) {
proc.terminationHandler = termHandler
}
} }
/// Run `launchctl stop` on the agent /// Run `launchctl stop` on the agent
/// ///
/// Check the status of the job with `.status(_: LaunchAgent)` /// Check the status of the job with `.status(_: LaunchAgent)`
public func stop(_ agent: LaunchAgent) { public func stop(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) {
let arguments = ["stop", agent.label] let arguments = ["stop", agent.label]
Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments) let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
if ((termHandler) != nil) {
proc.terminationHandler = termHandler
}
} }
/// Run `launchctl load` on the agent /// Run `launchctl load` on the agent
/// ///
/// Check the status of the job with `.status(_: LaunchAgent)` /// Check the status of the job with `.status(_: LaunchAgent)`
public func load(_ agent: LaunchAgent) throws { public func load(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) throws {
guard let agentURL = agent.url else { guard let agentURL = agent.url else {
throw LaunchAgentManagerError.urlNotSet(label: agent.label) throw LaunchAgentManagerError.urlNotSet(label: agent.label)
} }
let arguments = ["load", agentURL.path] let arguments = ["load", agentURL.path]
Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments) let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
if ((termHandler) != nil) {
proc.terminationHandler = termHandler
}
} }
/// Run `launchctl unload` on the agent /// Run `launchctl unload` on the agent
/// ///
/// Check the status of the job with `.status(_: LaunchAgent)` /// Check the status of the job with `.status(_: LaunchAgent)`
public func unload(_ agent: LaunchAgent) throws { public func unload(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) throws {
guard let agentURL = agent.url else { guard let agentURL = agent.url else {
throw LaunchAgentManagerError.urlNotSet(label: agent.label) throw LaunchAgentManagerError.urlNotSet(label: agent.label)
} }
let arguments = ["unload", agentURL.path] let arguments = ["unload", agentURL.path]
Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments) let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
if ((termHandler) != nil) {
proc.terminationHandler = termHandler
}
} }
/// Retreives the status of the LaunchAgent from `launchctl` /// Retreives the status of the LaunchAgent from `launchctl`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment