Skip to content

Commit

Permalink
add commandline option --version
Browse files Browse the repository at this point in the history
  • Loading branch information
fuji246 committed Jun 4, 2019
1 parent 87a8beb commit ff6d861
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
19 changes: 19 additions & 0 deletions LomoAgent/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ extension OSLog {
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationWillFinishLaunching(_ aNotification: Notification) {
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let arguments = CommandLine.arguments
var exit = false
for arg in arguments {
if arg == "--version" {
print("\(version)")
NotificationCenter.default.post(name: .NotifyExit, object: self)
exit = true
break
}
}

if !exit {
os_log("LomoAgent version: %{public}s", log: .logic, version)
NotificationCenter.default.post(name: .NotifyStart, object: self)
}
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
Expand Down
2 changes: 2 additions & 0 deletions LomoAgent/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let PREF_PORT = "PrefPort"

extension Notification.Name {
static let NotifyHomeDirChanged = NSNotification.Name("NotifyHomeDirChanged")
static let NotifyExit = NSNotification.Name("NotifyExit")
static let NotifyStart = NSNotification.Name("NotifyStart")
}

class PreferencesWindow: NSWindowController, NSWindowDelegate {
Expand Down
25 changes: 21 additions & 4 deletions LomoAgent/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ class StatusMenuController: NSObject {
sender.isEnabled = true
}

@objc func onNotification(_ notification: Notification) {
@objc func onStart(_ notification: Notification) {
killLomod()
startLomod()
}

@objc func onExit(_ notification: Notification) {
quitClicked(self)
}

@objc func onHomeDirChanged(_ notification: Notification) {
stopLomod()
startLomod()
}
Expand All @@ -61,12 +70,20 @@ class StatusMenuController: NSObject {
aboutWindow = AboutWindow()

NotificationCenter.default.addObserver(self,
selector: #selector(onNotification(_:)),
selector: #selector(onHomeDirChanged(_:)),
name: .NotifyHomeDirChanged,
object: nil)

killLomod()
startLomod()
NotificationCenter.default.addObserver(self,
selector: #selector(onStart(_:)),
name: .NotifyStart,
object: nil)

NotificationCenter.default.addObserver(self,
selector: #selector(onExit(_:)),
name: .NotifyExit,
object: nil)

stateTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(checkLomodState), userInfo: nil, repeats: true)
}

Expand Down

0 comments on commit ff6d861

Please sign in to comment.