Skip to content

Commit

Permalink
self closing success alerts
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Kootz <[email protected]>
  • Loading branch information
Austin Kootz committed Apr 20, 2018
1 parent d1791e9 commit 48f7622
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Binary file not shown.
19 changes: 15 additions & 4 deletions EjectionSeat/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSUserNotifi
let menu: NSMenu = NSMenu()
var aboutWindow: NSWindow?
var lastVolume: String = ""
let version: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String

let version: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String

func delay(_ seconds: Double, codeBlock: @escaping () -> Void){
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3), execute: codeBlock)
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
//statusItem.title = "EjectionSeat"
statusItem.image = NSImage(named: NSImage.Name("USBIcon"))
statusItem.image?.isTemplate = true
statusItem.menu = menu
statusItem.menu?.delegate = self
makeMenu()
makeAboutWindow()
}

Expand Down Expand Up @@ -73,7 +75,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSUserNotifi
aboutTextBody.textColor = NSColor.gray
aboutTextBody.alignment = NSTextAlignment.center
aboutTextBody.backgroundColor = NSColor.clear
aboutTextBody.insertText("Developed by Åustin Kootz\nVersion \(version!)")
aboutTextBody.insertText("Developed by Åustin Kootz\nVersion \(version)")
aboutTextBody.isEditable = false

aboutWindow = NSWindow.init(contentRect: aboutView.frame, styleMask: [.titled, .closable], backing: NSWindow.BackingStoreType.buffered, defer:false)
Expand Down Expand Up @@ -169,6 +171,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSUserNotifi
NSUserNotificationCenter.default.deliver(notification)
}

func userNotificationCenter(_ center: NSUserNotificationCenter, didDeliver notification: NSUserNotification) {
if !notification.hasActionButton {
delay(3) {
print(notification)
NSUserNotificationCenter.default.removeDeliveredNotification(notification)
}
}
}

func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) {
eject(NSMenuItem(title: notification.title!, action: nil, keyEquivalent: ""))
}
Expand Down
2 changes: 1 addition & 1 deletion EjectionSeat/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>1.4.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 48f7622

Please sign in to comment.