Sha256: 56fd906bb195a3e2662d2ed253236b28c5fdd3e5fdc7db0d4250b0b1735d1196

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

class AppDelegate
  attr_accessor :status_menu

  def applicationDidFinishLaunching(notification)
    @app_name = NSBundle.mainBundle.infoDictionary['CFBundleDisplayName']

    @status_menu = NSMenu.new

    @status_item = NSStatusBar.systemStatusBar.statusItemWithLength(NSVariableStatusItemLength).init
    @status_item.setMenu(@status_menu)
    @status_item.setHighlightMode(true)
    @status_item.setTitle(@app_name)

    @status_menu.addItem createMenuItem("About #{@app_name}", 'orderFrontStandardAboutPanel:')
    @status_menu.addItem createMenuItem("Custom Action", 'pressAction')
    @status_menu.addItem createMenuItem("Quit", 'terminate:')
  end

  def createMenuItem(name, action)
    NSMenuItem.alloc.initWithTitle(name, action: action, keyEquivalent: '')
  end

  def pressAction
    alert = NSAlert.alloc.init
    alert.setMessageText "Action triggered from status bar menu"
    alert.addButtonWithTitle "OK"
    alert.runModal
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
osx-status-bar-app-template-0.0.3 template/osx-status-bar-app/files/app/app_delegate.rb
osx-status-bar-app-template-0.0.2 template/osx-status-bar-app/files/app/app_delegate.rb
osx-status-bar-app-template-0.0.1 template/osx-status-bar-app/files/app/app_delegate.rb