Changeset 1a00f73 for launchers


Ignore:
Timestamp:
Oct 12, 2018 8:52:24 PM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
5f07789
Parents:
d8cfe21e
Message:

OSX Launcher: Extended start/stop/load/unload to be able to set terminationHandler for more reliable execution.

Location:
launchers/macosx/I2PLauncher/Utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/Utils/LaunchAgent+Status.swift

    rd8cfe21e r1a00f73  
    3535  ///
    3636  /// Check the status of the job with `.status()`
    37   public func start() {
    38     LaunchAgentManager.shared.start(self)
     37  public func start(_ callback: ((Process) -> Void)? = nil ) {
     38    LaunchAgentManager.shared.start(self, callback)
    3939  }
    4040 
     
    4242  ///
    4343  /// Check the status of the job with `.status()`
    44   public func stop() {
    45     LaunchAgentManager.shared.stop(self)
     44  public func stop(_ callback: ((Process) -> Void)? = nil ) {
     45    LaunchAgentManager.shared.stop(self, callback)
    4646  }
    4747 
  • launchers/macosx/I2PLauncher/Utils/LaunchAgentManager.swift

    rd8cfe21e r1a00f73  
    8989  ///
    9090  /// Check the status of the job with `.status(_: LaunchAgent)`
    91   public func start(_ agent: LaunchAgent) {
     91  public func start(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) {
    9292    let arguments = ["start", agent.label]
    93     Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     93    let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     94    if ((termHandler) != nil) {
     95      proc.terminationHandler = termHandler
     96    }
    9497  }
    9598 
     
    97100  ///
    98101  /// Check the status of the job with `.status(_: LaunchAgent)`
    99   public func stop(_ agent: LaunchAgent) {
     102  public func stop(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) {
    100103    let arguments = ["stop", agent.label]
    101     Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     104    let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     105    if ((termHandler) != nil) {
     106      proc.terminationHandler = termHandler
     107    }
    102108  }
    103109 
     
    105111  ///
    106112  /// Check the status of the job with `.status(_: LaunchAgent)`
    107   public func load(_ agent: LaunchAgent) throws {
     113  public func load(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) throws {
    108114    guard let agentURL = agent.url else {
    109115      throw LaunchAgentManagerError.urlNotSet(label: agent.label)
     
    111117   
    112118    let arguments = ["load", agentURL.path]
    113     Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     119    let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     120    if ((termHandler) != nil) {
     121      proc.terminationHandler = termHandler
     122    }
    114123  }
    115124 
     
    117126  ///
    118127  /// Check the status of the job with `.status(_: LaunchAgent)`
    119   public func unload(_ agent: LaunchAgent) throws {
     128  public func unload(_ agent: LaunchAgent, _ termHandler: ((Process) -> Void)? = nil ) throws {
    120129    guard let agentURL = agent.url else {
    121130      throw LaunchAgentManagerError.urlNotSet(label: agent.label)
     
    123132   
    124133    let arguments = ["unload", agentURL.path]
    125     Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     134    let proc = Process.launchedProcess(launchPath: LaunchAgentManager.launchctl, arguments: arguments)
     135    if ((termHandler) != nil) {
     136      proc.terminationHandler = termHandler
     137    }
    126138  }
    127139 
Note: See TracChangeset for help on using the changeset viewer.