Changeset 56eb11bc for launchers


Ignore:
Timestamp:
May 2, 2019 10:39:11 PM (11 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
2af1f68
Parents:
214efb8
Message:

Mac OSX Launcher: Adding Swift 4.2 support to the preferences UI classes.

Location:
launchers/macosx/I2PLauncher/userinterface/preferences
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/userinterface/preferences/PreferencesViewController+TableView.swift

    r214efb8 r56eb11bc  
    2525  }
    2626 
    27   func tableViewDoubleClick(_ sender:AnyObject) {
     27  @objc func tableViewDoubleClick(_ sender:AnyObject) {
    2828    print("Double click")
    2929    // 1
     
    3333        return
    3434    }
    35     print(item.name)
     35    print(item.name as Any)
    3636     /*
    3737     if item.isFolder {
     
    4848  func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
    4949    // 1
    50     guard let sortDescriptor = self.advPrefTableView.sortDescriptors.first else {
     50    guard let /*sortDescriptor*/ _ = self.advPrefTableView.sortDescriptors.first else {
    5151      return
    5252    }
     
    8686   
    8787    // 3
    88     if let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
     88    if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: nil) as? NSTableCellView {
    8989      cell.textField?.stringValue = text
    9090      //cell.imageView?.image = image ?? nil
  • launchers/macosx/I2PLauncher/userinterface/preferences/PreferencesViewController.swift

    r214efb8 r56eb11bc  
    1414
    1515
    16 class PreferencesViewController: NSViewController {
    17  
    18   enum ShowAsMode {
    19     case bothIcon
    20     case menubarIcon
    21     case dockIcon
    22   }
     16@objc class PreferencesViewController: NSViewController {
     17 
    2318 
    2419  var changeDockMenubarIconTimer: Timer?
     
    7873   
    7974    if (Preferences.shared().stopRouterOnLauncherShutdown) {
    80       self.checkboxStopWithLauncher?.state = NSOnState;
    81     } else {
    82       self.checkboxStopWithLauncher?.state = NSOffState;
     75      self.checkboxStopWithLauncher?.state = NSControl.StateValue.on;
     76    } else {
     77      self.checkboxStopWithLauncher?.state = NSControl.StateValue.off;
    8378    }
    8479    if (Preferences.shared().startRouterOnLauncherStart) {
    85       self.checkboxStartWithLauncher?.state = NSOnState;
    86     } else {
    87       self.checkboxStartWithLauncher?.state = NSOffState;
     80      self.checkboxStartWithLauncher?.state = NSControl.StateValue.on;
     81    } else {
     82      self.checkboxStartWithLauncher?.state = NSControl.StateValue.off;
    8883    }
    8984   
     
    10297  @IBAction func checkboxStartRouterWithLauncherClicked(_ sender: NSButton) {
    10398    switch sender.state {
    104     case NSOnState:
     99    case NSControl.StateValue.on:
    105100      print("on")
    106101      Preferences.shared().startRouterOnLauncherStart = true
    107     case NSOffState:
     102    case NSControl.StateValue.off:
    108103      print("off")
    109104      Preferences.shared().startRouterOnLauncherStart = false
    110     case NSMixedState:
    111       print("mixed")
    112105    default: break
    113106    }
     
    116109  @IBAction func checkboxStopRouterWithLauncherClicked(_ sender: NSButton) {
    117110    switch sender.state {
    118     case NSOnState:
     111    case NSControl.StateValue.on:
    119112      print("on")
    120113      Preferences.shared().stopRouterOnLauncherShutdown = true
    121     case NSOffState:
     114    case NSControl.StateValue.off:
    122115      print("off")
    123116      Preferences.shared().stopRouterOnLauncherShutdown = false
    124     case NSMixedState:
    125       print("mixed")
    126117    default: break
    127118    }
     
    138129    let startupMgr = Startup()
    139130    switch sender.state {
    140     case NSOnState:
     131    case NSControl.StateValue.on:
    141132      print("on")
    142133      Preferences.shared()["I2Pref_startLauncherAtLogin"] = true
     
    146137        print("SMLoginItemSetEnabled returned \(success)....")
    147138      } else {
    148         startupMgr.addLoginItem(Startup.appPath())
     139        let _ = startupMgr.addLoginItem(Startup.appPath())
    149140        print("Shared file for auto-startup added. (viewable via OSX Preferences -> Users -> Login Items)")
    150141      }
    151     case NSOffState:
     142    case NSControl.StateValue.off:
    152143      print("off")
    153144      Preferences.shared()["I2Pref_startLauncherAtLogin"] = false
     
    157148        print("SMLoginItemSetEnabled returned \(success)....")
    158149      } else {
    159         startupMgr.removeLoginItem(Startup.appPath())
     150        let _ = startupMgr.removeLoginItem(Startup.appPath())
    160151        print("Shared file for auto-startup removed (if any). (viewable via OSX Preferences -> Users -> Login Items)")
    161152      }
    162     case NSMixedState:
    163       print("mixed")
    164153    default: break
    165154    }
     
    167156  @IBAction func checkboxStartFirefoxAlsoAtLaunchClicked(_ sender: NSButton) {
    168157    switch sender.state {
    169     case NSOnState:
     158    case NSControl.StateValue.on:
    170159      print("launch firefox: on")
    171160      Preferences.shared().alsoStartFirefoxOnLaunch = true
    172     case NSOffState:
     161    case NSControl.StateValue.off:
    173162      print("launch firefox: off")
    174163      Preferences.shared().alsoStartFirefoxOnLaunch = false
    175     case NSMixedState:
    176       print("mixed")
    177164    default: break
    178165    }
     
    181168  // MARK: - Radio buttons functions
    182169 
    183   func updateDockMenubarIcons(_ mode: ShowAsMode) -> Bool {
     170  func updateDockMenubarIcons(_ mode: Preferences.ShowAsMode) -> Bool {
    184171    // Update preferences with latest choise
    185172    Preferences.shared().showAsIconMode = mode
     
    204191  }
    205192 
    206   func updateRadioButtonEffect(mode: ShowAsMode, withSideEffect: Bool = true) {
     193  func updateRadioButtonEffect(mode: Preferences.ShowAsMode, withSideEffect: Bool = true) {
    207194    changeDockMenubarIconTimer?.invalidate()
    208195   
    209     radioDockIcon?.state = NSOffState
    210     radioMenubarIcon?.state = NSOffState
    211     radioBothIcon?.state = NSOffState
     196    radioDockIcon?.state = NSControl.StateValue.off
     197    radioMenubarIcon?.state = NSControl.StateValue.off
     198    radioBothIcon?.state = NSControl.StateValue.off
    212199   
    213200    switch mode {
    214201    case .bothIcon:
    215       radioBothIcon?.state = NSOnState
     202      radioBothIcon?.state = NSControl.StateValue.on
    216203    case .dockIcon:
    217       radioDockIcon?.state = NSOnState
     204      radioDockIcon?.state = NSControl.StateValue.on
    218205    case .menubarIcon:
    219       radioMenubarIcon?.state = NSOnState
     206      radioMenubarIcon?.state = NSControl.StateValue.on
    220207    }
    221208   
     
    224211        changeDockMenubarIconTimer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false, block: { _ in
    225212          // If we're on 10.12 or later
    226           self.updateDockMenubarIcons(mode)
     213          let _ = self.updateDockMenubarIcons(mode)
    227214        })
    228215      } else {
    229216        // Fallback on earlier versions
    230         self.updateDockMenubarIcons(mode)
     217        let _ = self.updateDockMenubarIcons(mode)
    231218      }
    232219    }
     
    234221 
    235222  @IBAction func radioBothIconSelected(_ sender: Any) {
    236     updateRadioButtonEffect(mode: ShowAsMode.bothIcon)
     223    updateRadioButtonEffect(mode: Preferences.ShowAsMode.bothIcon)
    237224  }
    238225 
    239226  @IBAction func radioDockIconOnlySelected(_ sender: Any) {
    240     updateRadioButtonEffect(mode: ShowAsMode.dockIcon)
     227    updateRadioButtonEffect(mode: Preferences.ShowAsMode.dockIcon)
    241228  }
    242229 
    243230  @IBAction func radioMenubarOnlySelected(_ sender: Any) {
    244     updateRadioButtonEffect(mode: ShowAsMode.menubarIcon)
     231    updateRadioButtonEffect(mode: Preferences.ShowAsMode.menubarIcon)
    245232  }
    246233 
     
    265252    var result: Bool
    266253    if state {
    267       result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.regular)
    268     } else {
    269       result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.accessory)
     254      result = NSApp.setActivationPolicy(NSApplication.ActivationPolicy.regular)
     255    } else {
     256      result = NSApp.setActivationPolicy(NSApplication.ActivationPolicy.accessory)
    270257    }
    271258    return result
     
    273260 
    274261  func getDockIconStateIsShowing() -> Bool {
    275     if NSApp.activationPolicy() == NSApplicationActivationPolicy.regular {
     262    if NSApp.activationPolicy() == NSApplication.ActivationPolicy.regular {
    276263      return true
    277264    } else {
     
    285272  @IBAction func checkboxEnableAdvancedPreferencesClicked(_ sender: NSButton) {
    286273    switch sender.state {
    287     case NSOnState:
     274    case NSControl.StateValue.on:
    288275      print("on")
    289276      Preferences.shared().allowAdvancedPreferenceEdit = true
    290277      self.advPrefTableView.isEnabled = true
    291     case NSOffState:
     278    case NSControl.StateValue.off:
    292279      print("off")
    293280      Preferences.shared().allowAdvancedPreferenceEdit = false
    294281      self.advPrefTableView.isEnabled = false
    295     case NSMixedState:
    296       print("mixed")
    297282    default: break
    298283    }
  • launchers/macosx/I2PLauncher/userinterface/preferences/PreferencesWindowController.swift

    r214efb8 r56eb11bc  
    1111class PreferencesWindowController: NSWindowController, NSWindowDelegate {
    1212
    13     override func windowDidLoad() {
    14         super.windowDidLoad()
     13  override func windowDidLoad() {
     14    super.windowDidLoad()
     15 
     16    let visualEffect = NSVisualEffectView()
     17    visualEffect.blendingMode = .behindWindow
     18    visualEffect.state = .active
     19    visualEffect.material = .dark
     20    //self.window?.contentView = visualEffect
    1521   
    16         // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    17     }
     22    //self.window?.titlebarAppearsTransparent = true
     23    //self.window?.styleMask.insert(.fullSizeContentView)
     24    window?.titlebarAppearsTransparent = true
     25  }
    1826 
    1927  func windowShouldClose(_ sender: NSWindow) -> Bool {
Note: See TracChangeset for help on using the changeset viewer.