Skip to content

Commit

Permalink
added indicator item in menu - fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Mar 7, 2018
1 parent 6436be6 commit 226ffa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Apptivator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
isa = PBXGroup;
children = (
B3B4C2C01E25894B009F8E4E /* AppDelegate.swift */,
155D2C02204F61220087478B /* Credits.rtfd */,
15F39F3B204CB72D00847CD5 /* ViewController.swift */,
1537F5E0204C8D860056EE50 /* ApplicationEntry.swift */,
15FC8CC7204E2E2C000B5E1E /* ApplicationState.swift */,
B3B4C2C21E25894B009F8E4E /* Assets.xcassets */,
B3B4C2C41E25894B009F8E4E /* MainMenu.xib */,
155D2C02204F61220087478B /* Credits.rtfd */,
B3B4C2C71E25894B009F8E4E /* Info.plist */,
);
path = Apptivator;
Expand Down
9 changes: 7 additions & 2 deletions Apptivator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftyJSON
let appName = Bundle.main.infoDictionary![kCFBundleNameKey as String] as! String
let state = ApplicationState()

// Menu bar item icons.
let iconOn = NSImage(named: NSImage.Name(rawValue: "icon-on"))
let iconOff = NSImage(named: NSImage.Name(rawValue: "icon-off"))

Expand All @@ -19,6 +20,7 @@ let iconOff = NSImage(named: NSImage.Name(rawValue: "icon-off"))

var menuBarItem: NSStatusItem? = nil
var contextMenu: NSMenu = NSMenu()
let enabledIndicator = NSMenuItem(title: "\(appName): Enabled", action: nil, keyEquivalent: "")

func applicationDidFinishLaunching(_ aNotification: Notification) {
setupIcon(iconOn)
Expand All @@ -29,12 +31,14 @@ let iconOff = NSImage(named: NSImage.Name(rawValue: "icon-off"))
menuBarItem?.action = #selector(onMenuClick)
menuBarItem?.sendAction(on: [.leftMouseUp, .rightMouseUp])

contextMenu.addItem(NSMenuItem(title: "About", action: #selector(showAboutPanel), keyEquivalent: ""))
contextMenu.addItem(enabledIndicator)
contextMenu.addItem(NSMenuItem(title: "Configure Shortcuts", action: #selector(openPreferencesWindow), keyEquivalent: ""))
contextMenu.addItem(NSMenuItem.separator())
contextMenu.addItem(NSMenuItem(title: "Shortcuts", action: #selector(openPreferencesWindow), keyEquivalent: ""))
contextMenu.addItem(NSMenuItem(title: "About", action: #selector(showAboutPanel), keyEquivalent: ""))
contextMenu.addItem(NSMenuItem.separator())
contextMenu.addItem(NSMenuItem(title: "Quit \(appName)", action: #selector(quitApplication), keyEquivalent: ""))

enable(true)
state.loadFromDisk()
viewController.reloadView()

Expand All @@ -59,6 +63,7 @@ let iconOff = NSImage(named: NSImage.Name(rawValue: "icon-off"))
func enable(_ flag: Bool) {
state.appIsEnabled = flag
menuBarItem?.image = flag ? iconOn : iconOff
enabledIndicator.title = "\(appName): \(flag ? "on" : "off")"
}

func setupIcon(_ image: NSImage?) {
Expand Down

0 comments on commit 226ffa9

Please sign in to comment.