source: launchers/macosx/I2PLauncher/Utils/EventMonitor.swift @ 7615b92

Last change on this file since 7615b92 was 7615b92, checked in by meeh <meeh@…>, 2 years ago

Adding all new code, removed a lot obsolete code and fixed import paths etc.
Mac OS X launcher:

  • UI built on Swift
    • Why?
      • Apple seems to on purpose make it harder to get into Objective-C these days
      • Swift is compiled to native code, but has easiness of Javascript in programming
      • Perfect for the OS X UI, many guides & tutorials as well
  • "Backend" in Objective-C++ / C++14
    • Why?
      • Originally written in Objective-C / C++14 with C++17 backports
      • Only for backend because of the time the development takes *

Short summary of features:

  • Java
    • It can detect java from:
      • JAVA_HOME environment variable
      • "Internet Plug-Ins" Apple stuff
      • By the /usr/libexec/java_home binary helper
    • It can unpack a new version of I2P
      • Unpacks to ~/Library/I2P
      • Can check currently unpacked version in ~/Library/I2P via i2p.jar's "net.i2p.CoreVersion?"
  • User Interface (a popover, see https://youtu.be/k8L3lQ5rUq0 for example of this concept)
    • Router control tab view
      • It can start the router
      • It can stop the router
      • It can detect already running router, then avoid fireing up one
      • It can show basic information about the router state & version
    • Log view tab (not yet done)
  • While left-click triggers popover, right-click draws a minimal context menu
  • Property mode set to 100644
File size: 791 bytes
RevLine 
[7615b92]1//
2//  EventMonitor.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 02/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Foundation
10import Cocoa
11
12public class EventMonitor {
13    private var monitor: Any?
14    private let mask: NSEvent.EventTypeMask
15    private let handler: (NSEvent?) -> Void
16   
17    public init(mask: NSEvent.EventTypeMask, handler: @escaping (NSEvent?) -> Void) {
18        self.mask = mask
19        self.handler = handler
20    }
21   
22    deinit {
23        stop()
24    }
25   
26    public func start() {
27        monitor = NSEvent.addGlobalMonitorForEvents(matching: mask, handler: handler)
28    }
29   
30    public func stop() {
31        if monitor != nil {
32            NSEvent.removeMonitor(monitor!)
33            monitor = nil
34        }
35    }
36}
37
Note: See TracBrowser for help on using the repository browser.