Changeset a0d356b for launchers/macosx


Ignore:
Timestamp:
Dec 8, 2018 9:12:24 AM (19 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
dfcc616
Parents:
f4496a0
Message:

Mac OS X Launcher: Changes in path lookups (many via Preferences), launchd template changes and java arguments for the router itself.

Location:
launchers/macosx/I2PLauncher/routermgmt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/routermgmt/DetectJava.swift

    rf4496a0 ra0d356b  
    88
    99import Foundation
     10
    1011
    1112@objc class DetectJava : NSObject {
  • launchers/macosx/I2PLauncher/routermgmt/RouterManager.swift

    rf4496a0 ra0d356b  
    2020  // MARK: - Properties
    2121 
    22   static let packedVersion : String = "0.9.37"
     22  static let packedVersion : String = NSDEF_I2P_VERSION
    2323 
    2424  let eventManager = EventManager()
     
    2727  var logViewStorage: NSTextStorage?
    2828  var lastRouterPid : String? = nil
     29  private var canRouterStart : Bool = false
    2930 
    3031  private static func handleRouterException(information:Any?) {
     
    9495    routerManager.eventManager.listenTo(eventName: "router_exception", action: handleRouterException)
    9596    routerManager.eventManager.listenTo(eventName: "router_already_running", action: handleRouterAlreadyStarted)
    96     routerManager.eventManager.listenTo(eventName: "router_can_start", action: routerManager.routerRunner.StartAgent)
     97    routerManager.eventManager.listenTo(eventName: "router_can_start", action: routerManager.setLauncherReadyToStartRouter)
    9798    routerManager.eventManager.listenTo(eventName: "router_can_setup", action: routerManager.routerRunner.SetupAgent)
    9899   
     
    152153  }
    153154 
     155  func setLauncherReadyToStartRouter(_ information: Any?) {
     156    self.canRouterStart = true
     157    if (Preferences.shared().startRouterOnLauncherStart) {
     158      // Trigger the actual start at launch time
     159      print("Start router on launch preference is enabled - Starting")
     160      self.routerRunner.StartAgent(information)
     161    } else {
     162      print("Start router on launch preference is disabled - Router ready when user are!")
     163      SBridge.sendUserNotification("I2P Router Ready", formattedMsg: "The I2P Router is ready to be launched, however the autostart is disabled and require user input to start.")
     164    }
     165  }
     166 
     167  func checkIfRouterCanStart() -> Bool {
     168    return self.canRouterStart
     169  }
     170 
    154171  func setRouterTask(router: I2PRouterTask) {
    155172    self.routerInstance = router
  • launchers/macosx/I2PLauncher/routermgmt/RouterProcessStatus.swift

    rf4496a0 ra0d356b  
    5252  static var routerVersion : String? = Optional.none
    5353  static var routerStartedAt : Date? = Optional.none
    54   static var i2pDirectoryPath : String = NSHomeDirectory() + "/Library/I2P"
     54  static var i2pDirectoryPath : String = Preferences.shared().i2pBaseDirectory
    5555 
    5656 
  • launchers/macosx/I2PLauncher/routermgmt/RouterRunner.swift

    rf4496a0 ra0d356b  
    2121  var currentProcessResults: ExecutionResult?
    2222 
    23   let domainLabel = "net.i2p.macosx.I2PRouter"
    24  
    25   let plistName = "net.i2p.macosx.I2PRouter.plist"
    26  
    27   let defaultStartupCommand:String = "/usr/libexec/java_home"
    28  
    29   let defaultJavaHomeArgs:[String] = [
    30     "-v",
    31     "1.7+",
    32     "--exec",
    33     "java",
    34   ]
    35  
    36   let appSupportPath = FileManager.default.urls(for: FileManager.SearchPathDirectory.applicationSupportDirectory, in: FileManager.SearchPathDomainMask.userDomainMask)
     23  let domainLabel = String(NSString(format: "%@.I2PRouter", APPDOMAIN))
     24 
     25  let plistName = String(NSString(format: "%@.I2PRouter.plist", APPDOMAIN))
     26 
     27  //let appSupportPath = FileManager.default.urls(for: FileManager.SearchPathDirectory.applicationSupportDirectory, in: FileManager.SearchPathDomainMask.userDomainMask)
    3728 
    3829  override init() {
     
    6051  func SetupAndReturnAgent() -> LaunchAgent {
    6152   
     53    let applicationsSupportPath: URL = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
     54   
    6255    let defaultStartupFlags:[String] = [
    63       "-Xmx512M",
    64       "-Xms128m",
    6556      "-Djava.awt.headless=true",
    66       "".appendingFormat("-Di2p.base.dir=%@", NSHomeDirectory()+"/Library/I2P"),
    67       "".appendingFormat("-Dwrapper.logfile=%@/Library/I2P/router.log", NSHomeDirectory()),
    68       "-Dwrapper.logfile.loglevel=DEBUG",
    69       "".appendingFormat("-Dwrapper.java.pidfile=%@/i2p/router.pid", appSupportPath.description),
     57      "".appendingFormat("-Di2p.base.dir=%@", Preferences.shared().i2pBaseDirectory),
     58      "".appendingFormat("-Dwrapper.logfile=%@/i2p/router.log", applicationsSupportPath.absoluteString),
     59      "".appendingFormat("-Dwrapper.java.pidfile=%@/i2p/router.pid", applicationsSupportPath.absoluteString),
     60      "-Dwrapper.logfile.loglevel=DEBUG", // TODO: Allow loglevel to be set from Preferences?
    7061      "-Dwrapper.console.loglevel=DEBUG",
    7162      "net.i2p.router.Router"
    7263    ]
    7364   
    74     self.daemonPath = self.defaultStartupCommand
     65    let javaCliArgs = Preferences.shared().javaCommandPath.splitByWhitespace()
     66   
     67    self.daemonPath = javaCliArgs[0]
    7568    self.arguments = defaultStartupFlags.joined(separator: " ")
    7669   
    77     let basePath = NSHomeDirectory()+"/Library/I2P"
     70    let basePath = Preferences.shared().i2pBaseDirectory
    7871   
    7972    let jars = try! FileManager.default.contentsOfDirectory(atPath: basePath+"/lib")
     
    8679      self.daemonPath!,
    8780      ]
    88     cliArgs.append(contentsOf: self.defaultJavaHomeArgs)
     81    cliArgs.append(contentsOf: javaCliArgs.dropFirst())
    8982    cliArgs.append(contentsOf: [
    9083      "-cp",
    9184      classpath,
    9285      ])
     86    // This allow java arguments to be passed from the settings
     87    cliArgs.append(contentsOf: Preferences.shared().javaCommandOptions.splitByWhitespace())
    9388    cliArgs.append(contentsOf: defaultStartupFlags)
    9489    let agent = LaunchAgent(label: self.domainLabel,program: cliArgs)
     
    9792    agent.workingDirectory = basePath
    9893    agent.userName = NSUserName()
    99     agent.standardErrorPath = NSHomeDirectory()+"/Library/Logs/I2P/router.stderr.log"
    100     agent.standardOutPath = NSHomeDirectory()+"/Library/Logs/I2P/router.stdout.log"
     94    agent.standardErrorPath = NSString(format: "%@/router.stderr.log", Preferences.shared().i2pLogDirectory) as String
     95    agent.standardOutPath = NSString(format: "%@/router.stdout.log", Preferences.shared().i2pLogDirectory) as String
    10196    agent.environmentVariables = [
    10297      "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
     
    107102    RouterRunner.launchAgent = agent
    108103   
    109     let userPreferences = UserDefaults.standard
    110     let shouldStartupAtLogin = userPreferences.bool(forKey: "startRouterAtLogin")
    111     agent.runAtLoad = shouldStartupAtLogin
     104    // NOTE: I suspect this is better to solve in the application
     105    agent.runAtLoad = false //Preferences.shared().startRouterOnLauncherStart
    112106    agent.keepAlive = true
    113107    DispatchQueue(label: "background_starter").async {
    114108      do {
     109        // TODO: Find a better way than sleep
    115110        try LaunchAgentManager.shared.write(agent, called: self.plistName)
    116111        sleep(1)
     
    141136 
    142137  func StartAgent(_ information:Any? = nil) {
    143     let agent = RouterRunner.launchAgent ?? information as! LaunchAgent
    144     DispatchQueue(label: "background_block").async {
    145       LaunchAgentManager.shared.start(agent, { (proc) in
    146         NSLog("Will call onLaunchdStarted")
    147       })
     138    if (RouterManager.shared().checkIfRouterCanStart()) {
     139      let agent = RouterRunner.launchAgent ?? information as! LaunchAgent
     140      DispatchQueue(label: "background_block").async {
     141        LaunchAgentManager.shared.start(agent, { (proc) in
     142          NSLog("Will call onLaunchdStarted")
     143        })
     144      }
     145    } else {
     146      SBridge.sendUserNotification("Whops! Please wait", formattedMsg: "I'm sorry but it's still something unresolved before we can start the I2P router. Please wait.")
    148147    }
    149148  }
Note: See TracChangeset for help on using the changeset viewer.