Changeset 36a5790 for launchers


Ignore:
Timestamp:
Dec 8, 2018 2:37:59 PM (16 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
d382f12
Parents:
b946bb0
Message:

Mac OS X Launcher: Misc minor updates to Preferences

Location:
launchers/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher.xcodeproj/project.pbxproj

    rb946bb0 r36a5790  
    2020                BF1D6D9B21BB86520014EB07 /* ConsoleWebView.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF1D6D9A21BB86520014EB07 /* ConsoleWebView.storyboard */; };
    2121                BF1D6D9D21BB87000014EB07 /* EmbeddedConsoleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1D6D9C21BB87000014EB07 /* EmbeddedConsoleView.swift */; };
    22                 BF1D6D9F21BBA1460014EB07 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF1D6D9E21BBA1460014EB07 /* WebKit.framework */; };
     22                BF1D6D9F21BBA1460014EB07 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF1D6D9E21BBA1460014EB07 /* WebKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
    2323                BF1D6DA321BBB8120014EB07 /* AdvancedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1D6DA221BBB8120014EB07 /* AdvancedTableView.swift */; };
    2424                BF1D6DA521BBB84E0014EB07 /* PreferencesViewController+TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF1D6DA421BBB84E0014EB07 /* PreferencesViewController+TableView.swift */; };
  • launchers/macosx/I2PLauncher/Utils/Preferences.swift

    rb946bb0 r36a5790  
    2828  private var prefObject: Dictionary<String,Any> = Dictionary<String,Any>()
    2929  private var prefDict = Dictionary<String,PreferenceRow>()
    30   private var prefDefaultDict: Dictionary<String,Any>?
    31  
    32   // This makes an read-only property computed from another property
    33   // It's usage is mainly in UI Table view, so we want the prefDict size
    34   var count: Int {
    35     get {
    36       return prefDict.count
    37     }
    38   }
     30  private var prefDefaultDict: Dictionary<String,Any> = Dictionary<String,Any>()
     31 
     32  var count: Int = 0
    3933 
    4034  // Interface with a string setting in background
    4135  var showAsIconMode: PreferencesViewController.ShowAsMode {
    4236    get {
    43       var mode = self.prefObject["I2Pref_showAsIconMode"]
     37      var mode = self["I2Pref_showAsIconMode"]
    4438      if (mode == nil) {
    4539        mode = "bothIcon"
     
    6761        newMode = "dockIcon"
    6862      }
    69       self.prefObject["I2Pref_showAsIconMode"] = newMode
    70       UserDefaults.standard.setPersistentDomain(self.prefObject, forName: APPDOMAIN)
     63      self["I2Pref_showAsIconMode"] = newMode
     64      self.syncPref()
    7165    }
    7266  }
     
    7973    set(newValue) {
    8074      prefObject[prefName] = newValue
    81       prefDict[prefName] = PreferenceRow(prefName, newValue)
    82       UserDefaults.standard.setPersistentDomain(self.prefObject, forName: APPDOMAIN)
    83     }
     75      prefDict[prefName] = PreferenceRow(prefName, newValue, prefDefaultDict[prefName])
     76      self.syncPref()
     77    }
     78  }
     79 
     80  func syncPref() {
     81    UserDefaults.standard.setPersistentDomain(self.prefObject, forName: APPDOMAIN)
     82    UserDefaults.standard.synchronize()
    8483  }
    8584 
     
    9089    }
    9190    set(newValue) {
    92       let pKey = Array(prefDict.keys)[index]
     91      let pKey = Array(prefDefaultDict.keys)[index]
    9392      prefDict[pKey] = newValue!
    9493      prefObject[pKey] = newValue!.asRawValue()
    95       UserDefaults.standard.setPersistentDomain(self.prefObject, forName: APPDOMAIN)
    9694    }
    9795  }
     
    124122    preferences.prefDefaultDict = defaults
    125123   
    126     if (preferences.prefDict.isEmpty) {
     124    /*if (preferences.prefDict.isEmpty) {
    127125      print("Stored new user defaults")
    128126      preferences.addDictToPrefTable(defaults)
    129     }
     127    }*/
     128    for name in Array(preferences.prefDefaultDict.keys) {
     129      let potentialValue = UserDefaults.standard.object(forKey: name)
     130      //preferences.prefDict[name] = PreferenceRow(name, potentialValue, preferences.prefDefaultDict[name])
     131      preferences[name] = potentialValue
     132    }
     133    preferences.count = preferences.prefDict.keys.count
     134    UserDefaults.standard.register(defaults: defaults)
     135    UserDefaults.standard.setPersistentDomain(preferences.prefObject, forName: APPDOMAIN)
     136    UserDefaults.standard.synchronize()
    130137   
    131138    print("User Preferences loaded - Got \(preferences.count) items.")
     
    143150      if (pKey.starts(with: "I2P")) {
    144151        print("Preference -> \(pKey)")
    145         prefDict[pKey] = PreferenceRow(pKey, pVal, self.prefDefaultDict![pKey])
     152        self[pKey] = pVal
    146153      } else {
    147154        print("Skipping preference -> \(pKey)")
     
    154161  private override init() {
    155162    super.init()
    156     self.prefObject = UserDefaults.standard.persistentDomain(forName: APPDOMAIN) ?? Dictionary<String,Any>()
     163    let fromDisk = UserDefaults.standard.persistentDomain(forName: APPDOMAIN) ?? Dictionary<String,Any>()
     164    for (pKey, pVal) in fromDisk {
     165      if (pKey.starts(with: "I2P")) {
     166        print("Preference -> \(pKey)")
     167        self[pKey] = pVal
     168      } else {
     169        print("Skipping preference -> \(pKey)")
     170      }
     171    }
    157172    print("Preferences size from disk is: \(prefObject.count).")
    158     self.addDictToPrefTable(self.prefObject)
    159     UserDefaults.standard.setPersistentDomain(self.prefObject, forName: APPDOMAIN)
     173    self.syncPref()
    160174  }
    161175 
     
    172186 
    173187  func redrawPrefTableItems() {
    174     self.addDictToPrefTable(self.prefObject, true)
     188    self.addDictToPrefTable(self.prefObject, false)
    175189  }
    176190 
     
    180194  var startRouterOnLauncherStart: Bool {
    181195    get {
    182       let dfl = self.prefDefaultDict?["I2Pref_startRouterAtStartup"] as! Bool
    183       return (self.prefObject["I2Pref_startRouterAtStartup"] as? Bool ?? dfl)
    184     }
    185     set(newValue) {
    186       self.prefObject["I2Pref_startRouterAtStartup"] = newValue
    187       UserDefaults.standard.synchronize()
     196      let dfl = self.prefDefaultDict["I2Pref_startRouterAtStartup"] as! Bool
     197      return (self["I2Pref_startRouterAtStartup"] as? Bool ?? dfl)
     198    }
     199    set(newValue) {
     200      self["I2Pref_startRouterAtStartup"] = newValue
     201      self.syncPref()
    188202    }
    189203  }
     
    191205  var stopRouterOnLauncherShutdown: Bool {
    192206    get {
    193       let dfl = self.prefDefaultDict?["I2Pref_stopRouterAtShutdown"] as! Bool
    194       return (self.prefObject["I2Pref_stopRouterAtShutdown"] as? Bool ?? dfl)
    195     }
    196     set(newValue) {
    197       self.prefObject["I2Pref_stopRouterAtShutdown"] = newValue
    198       UserDefaults.standard.synchronize()
     207      let dfl = self.prefDefaultDict["I2Pref_stopRouterAtShutdown"] as! Bool
     208      return (self["I2Pref_stopRouterAtShutdown"] as? Bool ?? dfl)
     209    }
     210    set(newValue) {
     211      self["I2Pref_stopRouterAtShutdown"] = newValue
     212      self.syncPref()
    199213    }
    200214  }
     
    202216  var allowAdvancedPreferenceEdit: Bool {
    203217    get {
    204       let dfl = self.prefDefaultDict?["I2Pref_allowAdvancedPreferences"] as! Bool
    205       return (self.prefObject["I2Pref_allowAdvancedPreferences"] as? Bool ?? dfl)
    206     }
    207     set(newValue) {
    208       self.prefObject["I2Pref_allowAdvancedPreferences"] = newValue
    209       UserDefaults.standard.synchronize()
     218      let dfl = self.prefDefaultDict["I2Pref_allowAdvancedPreferences"] as! Bool
     219      return (self["I2Pref_allowAdvancedPreferences"] as? Bool ?? dfl)
     220    }
     221    set(newValue) {
     222      self["I2Pref_allowAdvancedPreferences"] = newValue
     223      self.syncPref()
    210224    }
    211225  }
     
    213227  var alsoStartFirefoxOnLaunch: Bool {
    214228    get {
    215       let dfl = self.prefDefaultDict?["I2Pref_alsoStartFirefoxOnLaunch"] as! Bool
    216       return (self.prefObject["I2Pref_alsoStartFirefoxOnLaunch"] as? Bool ?? dfl)
    217     }
    218     set(newValue) {
    219       self.prefObject["I2Pref_alsoStartFirefoxOnLaunch"] = newValue
    220       UserDefaults.standard.synchronize()
     229      let dfl = self.prefDefaultDict["I2Pref_alsoStartFirefoxOnLaunch"] as! Bool
     230      return (self["I2Pref_alsoStartFirefoxOnLaunch"] as? Bool ?? dfl)
     231    }
     232    set(newValue) {
     233      self["I2Pref_alsoStartFirefoxOnLaunch"] = newValue
     234      self.syncPref()
    221235    }
    222236  }
     
    224238  var featureToggleExperimental: Bool {
    225239    get {
    226       let dfl = self.prefDefaultDict?["I2Pref_featureToggleExperimental"] as! Bool
    227       return (self.prefObject["I2Pref_featureToggleExperimental"] as? Bool ?? dfl)
    228     }
    229     set(newValue) {
    230       self.prefObject["I2Pref_featureToggleExperimental"] = newValue
    231       UserDefaults.standard.synchronize()
     240      let dfl = self.prefDefaultDict["I2Pref_featureToggleExperimental"] as! Bool
     241      return (self["I2Pref_featureToggleExperimental"] as? Bool ?? dfl)
     242    }
     243    set(newValue) {
     244      self["I2Pref_featureToggleExperimental"] = newValue
     245      self.syncPref()
    232246    }
    233247  }
     
    235249  var i2pBaseDirectory: String {
    236250    get {
    237       let dfl = self.prefDefaultDict?["I2Pref_i2pBaseDirectory"] as! String
    238       return (self.prefObject["I2Pref_i2pBaseDirectory"] as? String ?? dfl)
     251      let dfl = self.prefDefaultDict["I2Pref_i2pBaseDirectory"] as! String
     252      return (self["I2Pref_i2pBaseDirectory"] as? String ?? dfl)
    239253    }
    240254    set(newValue) {
    241255      // TODO: Check if string is a valid directory path, and that it exists.
    242       self.prefObject["I2Pref_i2pBaseDirectory"] = newValue
    243       UserDefaults.standard.synchronize()
     256      self["I2Pref_i2pBaseDirectory"] = newValue
     257      self.syncPref()
    244258    }
    245259  }
     
    247261  var i2pLogDirectory: String {
    248262    get {
    249       let dfl = self.prefDefaultDict?["I2Pref_i2pLogDirectory"] as! String
    250       return (self.prefObject["I2Pref_i2pLogDirectory"] as? String ?? dfl)
     263      let dfl = self.prefDefaultDict["I2Pref_i2pLogDirectory"] as! String
     264      return (self["I2Pref_i2pLogDirectory"] as? String ?? dfl)
    251265    }
    252266    set(newValue) {
    253267      // TODO: Check if string is a valid java command path, check if it executes with -version.
    254       self.prefObject["I2Pref_i2pLogDirectory"] = newValue
    255       UserDefaults.standard.synchronize()
     268      self["I2Pref_i2pLogDirectory"] = newValue
     269      self.syncPref()
    256270    }
    257271  }
     
    259273  var javaCommandPath: String {
    260274    get {
    261       let dfl = self.prefDefaultDict?["I2Pref_javaCommandPath"] as! String
    262       return (self.prefObject["I2Pref_javaCommandPath"] as? String ?? dfl)
     275      let dfl = self.prefDefaultDict["I2Pref_javaCommandPath"] as! String
     276      return (self["I2Pref_javaCommandPath"] as? String ?? dfl)
    263277    }
    264278    set(newValue) {
    265279      // TODO: Check if string is a valid java command path, check if it executes with -version.
    266       self.prefObject["I2Pref_javaCommandPath"] = newValue
    267       UserDefaults.standard.synchronize()
     280      self["I2Pref_javaCommandPath"] = newValue
     281      self.syncPref()
    268282    }
    269283  }
     
    271285  var javaCommandOptions: String {
    272286    get {
    273       let dfl = self.prefDefaultDict?["I2Pref_javaCommandOptions"] as! String
    274       return (self.prefObject["I2Pref_javaCommandOptions"] as? String ?? dfl)
     287      let dfl = self.prefDefaultDict["I2Pref_javaCommandOptions"] as! String
     288      return (self["I2Pref_javaCommandOptions"] as? String ?? dfl)
    275289    }
    276290    set(newValue) {
    277291      // TODO: Check if string is a valid set of java options
    278       self.prefObject["I2Pref_javaCommandOptions"] = newValue
    279       UserDefaults.standard.synchronize()
     292      self["I2Pref_javaCommandOptions"] = newValue
     293      self.syncPref()
    280294    }
    281295  }
Note: See TracChangeset for help on using the changeset viewer.