Changeset 540e7c3 for launchers


Ignore:
Timestamp:
May 2, 2019 10:51:35 PM (19 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
67ca6e65
Parents:
7cb0c9b
Message:

Mac OSX Launcher: Cleanup and update in UI classes. Swift 4.2

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

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/userinterface/LogViewController.swift

    r7cb0c9b r540e7c3  
    4242        self.textFieldView?.string = nextOutput
    4343       
    44         let range = NSRange(location:nextOutput.characters.count,length:0)
     44        let range = NSRange(location:nextOutput.count,length:0)
    4545        self.textFieldView?.scrollRangeToVisible(range)
    4646      }
  • launchers/macosx/I2PLauncher/userinterface/RouterStatusView.swift

    r7cb0c9b r540e7c3  
    3535 
    3636  @objc func actionBtnOpenConsole(_ sender: Any?) {
    37     SwiftMainDelegate.openLink(url: "http://localhost:7657")
     37    SwiftApplicationDelegate.openLink(url: "http://localhost:7657")
    3838  }
    3939 
     
    8181    DispatchQueue.global(qos: .background).async {
    8282      Swift.print("Starting firefox")
    83       FirefoxManager.shared().executeFirefox()
     83      let _ = FirefoxManager.shared().executeFirefox()
    8484    }
    8585  }
  • launchers/macosx/I2PLauncher/userinterface/StatusBarController.swift

    r7cb0c9b r540e7c3  
    99import Foundation
    1010import Cocoa
     11import Sparkle
    1112
    1213@objc class StatusBarController: NSObject, NSMenuDelegate {
    1314 
    1415  let popover = NSPopover()
    15   let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
     16  let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
    1617  let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main)
     18 
     19  let updaterObject: SUUpdater = SUUpdater()
    1720 
    1821  var ctrl : PopoverViewController?
     
    2225  @IBOutlet var routerStatusTabView: RouterStatusView?
    2326 
    24   @IBAction func handleNativePreferencesClicked(_ sender: Any) {
     27  @IBAction func handleNativePrefMenuClicked(_ sender: Any) {
    2528    StatusBarController.launchPreferences(sender)
    2629  }
     30 
    2731  //var updateObjectRef : SUUpdater?
    2832 
    2933  @objc func handleOpenConsole(_ sender: Any?) {
    30     SwiftMainDelegate.openLink(url: "http://localhost:7657")
    31   }
    32  
    33   @objc func constructMenu() -> NSMenu {
    34     let menu = NSMenu()
    35    
    36     /*let updateMenuItem = NSMenuItem(title: "Check for updates", action: #selector(self.updateObjectRef?.checkForUpdates(_:)), keyEquivalent: "U")
    37     updateMenuItem.isEnabled = true
    38     */
    39    
    40     let preferencesMenuItem = NSMenuItem(title: "Preferences", action: #selector(StatusBarController.launchPreferences(_:)), keyEquivalent: "P")
    41     preferencesMenuItem.isEnabled = true
    42    
    43     menu.addItem(NSMenuItem(title: "Open I2P Console", action: #selector(self.handleOpenConsole(_:)), keyEquivalent: "O"))
    44     menu.addItem(NSMenuItem.separator())
    45     //menu.addItem(updateMenuItem)
    46     menu.addItem(preferencesMenuItem)
    47     menu.addItem(NSMenuItem.separator())
    48     menu.addItem(NSMenuItem(title: "Quit I2P Launcher", action: #selector(SwiftMainDelegate.terminate(_:)), keyEquivalent: "q"))
    49    
    50     return menu
     34    SwiftApplicationDelegate.openLink(url: "http://localhost:7657")
    5135  }
    5236 
     
    6852  }
    6953 
    70   static func launchPreferences(_ sender: Any) {
     54  @objc static func launchPreferences(_ sender: Any) {
    7155    print("Preferences clicked")
    7256    if !(preferencesController != nil) {
     
    8266  }
    8367 
     68  @objc func launchPreferencesStaticProxy(_ sender: Any) {
     69    StatusBarController.launchPreferences(sender)
     70  }
     71 
    8472  static func launchRouterConsole(_ sender: Any) {
    8573    if (!Preferences.shared().featureToggleExperimental) {
    8674      // The normal...
    87       NSWorkspace.shared().open(URL(string: "http://127.0.0.1:7657")!)
     75      NSWorkspace.shared.open(URL(string: "http://127.0.0.1:7657")!)
    8876    } else {
    8977      // Experimental
     
    9381  func pidReaction(information:Any?){
    9482    let pidStr = information as! String
    95     NSLog("PID! %@", pidStr)
     83    NSLog("Router PID is %@", pidStr)
    9684    showPopover(sender: nil)
    9785    RouterManager.shared().lastRouterPid = pidStr
     
    112100    RouterManager.shared().eventManager.listenTo(eventName: "toggle_popover", action: event_toggle)
    113101   
    114     FirefoxManager.shared().tryAutoDetect()
     102    let _ = FirefoxManager.shared().tryAutoDetect()
    115103   
    116104    print("Is Firefox found? \(FirefoxManager.shared().IsFirefoxFound())")
    117105    print("Is Firefox profile extracted at \(Preferences.shared()["I2Pref_firefoxProfilePath"] as! String)? \(FirefoxManager.shared().IsProfileExtracted())")
    118106    if (!FirefoxManager.shared().IsProfileExtracted()) {
    119       FirefoxManager.shared().unzipProfile()
     107      let _ = FirefoxManager.shared().unzipProfile()
    120108    }
    121109   
     
    136124 
    137125  @IBAction func quitClicked(_ sender: NSMenuItem) {
    138     NSApplication.shared().terminate(self)
    139   }
    140  
    141   // Submenu
    142  
    143   @IBAction func startRouterClicked(_ sender: NSMenuItem) {
    144    
    145   }
    146  
    147   @IBAction func restartRouterClicked(_ sender: NSMenuItem) {
    148    
    149   }
    150  
    151   @IBAction func stopRouterClicked(_ sender: NSMenuItem) {
    152    
    153   }
    154  
    155   func statusBarButtonClicked(sender: NSStatusBarButton) {
     126    NSApplication.shared.terminate(self)
     127  }
     128 
     129  @objc func checkUpdateClicked(_ sender: NSMenuItem) {
     130    //DispatchQueue(label: "updaterqueue").async {}
     131    self.updaterObject.checkForUpdates(sender)
     132  }
     133 
     134}
     135
     136/**
     137 *
     138 * Here you find menu & popover trigger related code.
     139 *
     140 */
     141
     142extension StatusBarController {
     143 
     144  // This is the construction of the context (right-click) menu spawned at the system tray icon.
     145  @objc func constructMenu() -> NSMenu {
     146    let menu = NSMenu()
     147   
     148    let updateMenuItem = NSMenuItem(title: "Check for updates", action: #selector(self.checkUpdateClicked(_:)), keyEquivalent: "U")
     149    updateMenuItem.isEnabled = true
     150    updateMenuItem.target = self
     151   
     152   
     153    let preferencesMenuItem = NSMenuItem(title: "Preferences", action: #selector(self.launchPreferencesStaticProxy(_:)), keyEquivalent: "P")
     154    preferencesMenuItem.isEnabled = true
     155    preferencesMenuItem.target = self
     156   
     157    menu.addItem(NSMenuItem(title: "Open I2P Console", action: #selector(self.handleOpenConsole(_:)), keyEquivalent: "O"))
     158    menu.addItem(NSMenuItem.separator())
     159    menu.addItem(updateMenuItem)
     160    menu.addItem(preferencesMenuItem)
     161    menu.addItem(NSMenuItem.separator())
     162    menu.addItem(NSMenuItem(title: "Quit I2P Launcher", action: #selector(SwiftApplicationDelegate.terminate(_:)), keyEquivalent: "q"))
     163   
     164    return menu
     165  }
     166 
     167  @objc func statusBarButtonClicked(sender: NSStatusBarButton) {
    156168    let event = NSApp.currentEvent!
    157169   
    158     if event.type == NSEventType.rightMouseUp {
     170    if event.type == NSEvent.EventType.rightMouseUp {
    159171      closePopover(sender: nil)
    160172     
     
    192204    popover.performClose(sender)
    193205  }
    194  
    195  
    196206}
    197 
Note: See TracChangeset for help on using the changeset viewer.