Changeset ba853a8c


Ignore:
Timestamp:
Jan 18, 2019 4:26:08 PM (19 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
5212591
Parents:
6ad64d5b
Message:

Mac OSX Launcher: The firefox manager code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/Utils/browser/FirefoxManager.swift

    r6ad64d5b rba853a8c  
    1111
    1212class FirefoxManager {
     13 
     14  var firefoxAppPath = ""
     15  private var isFirefoxFound = false
     16  private var isFirefoxProfileExtracted = false
     17 
     18  fileprivate func directoryExistsAtPath(_ path: String) -> Bool {
     19    var isDirectory = ObjCBool(true)
     20    let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
     21    return exists && isDirectory.boolValue
     22  }
     23 
     24  func IsFirefoxFound() -> Bool {
     25    return self.isFirefoxFound
     26  }
     27 
     28  func IsProfileExtracted() -> Bool {
     29    return self.isFirefoxProfileExtracted
     30  }
     31 
     32  func bundleExecutableSuffixPath() -> String {
     33    return "/Contents/MacOS/firefox"
     34  }
     35 
     36  func executeFirefox() -> Bool {
     37    let fullExecPath = "\(self.firefoxAppPath)\(self.bundleExecutableSuffixPath())"
     38    let firefoxProcess = Subprocess(executablePath: fullExecPath, arguments: [ "-profile", Preferences.shared()["I2Pref_firefoxProfilePath"] as! String, "http://127.0.0.1:7657/home" ])
     39    DispatchQueue.global(qos: .background).async {
     40      let proc = firefoxProcess.execute()
     41    }
     42    return true
     43  }
    1344
     45  func tryAutoDetect() -> Bool {
     46    let expectedPath = Preferences.shared()["I2Pref_firefoxBundlePath"] as! String
     47   
     48    self.isFirefoxProfileExtracted = directoryExistsAtPath(Preferences.shared()["I2Pref_firefoxProfilePath"] as! String)
     49   
     50    let result = directoryExistsAtPath(expectedPath)
     51    self.isFirefoxFound = result
     52    if (result) {
     53      self.firefoxAppPath = expectedPath
     54      return true
     55    }
     56    return false
     57  }
     58 
     59 
     60  private static var sharedFirefoxManager: FirefoxManager = {
     61    let firefoxMgr = FirefoxManager()
     62   
     63    return firefoxMgr
     64  }()
     65 
     66 
     67  class func shared() -> FirefoxManager {
     68    return sharedFirefoxManager
     69  }
    1470}
    1571
     72extension FirefoxManager {
     73  func unzipProfile() -> Bool {
     74    let resourceUrl = Bundle.main.url(forResource: "profile", withExtension: "tgz")
     75    let profileTgz = resourceUrl!.path
     76    let unzipProc = Subprocess(executablePath: "/usr/bin/tar", arguments: ["-xf",profileTgz,"-C",NSString(format: "%@/Library/Application Support/i2p", NSHomeDirectory()) as String])
     77    DispatchQueue.global(qos: .background).async {
     78      let proc = unzipProc.execute(captureOutput: true)
     79      print("Firefox Profile Extraction Errors: \(proc?.errors)")
     80      print("Firefox Profile Extraction Output: \(proc?.output)")
     81    }
     82    return false
     83  }
     84}
     85
Note: See TracChangeset for help on using the changeset viewer.