Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Tiny bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jariz committed Jul 13, 2016
1 parent bfbc352 commit 8eea1c6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Noti/AuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AuthViewController: NSViewController, WebFrameLoadDelegate {
appDelegate.loadPushManager()

self.view.window?.close()
NSNotificationCenter.defaultCenter().postNotificationName("AuthStateChange", object: true)
NSNotificationCenter.defaultCenter().postNotificationName("AuthSuccess", object: nil)
}
}
}
Expand Down
49 changes: 23 additions & 26 deletions Noti/IntroViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,31 @@ class IntroViewController: NSViewController {
@IBOutlet weak var authImg:NSImageView!;

func authSuccess(notification: NSNotification) {
if notification.object as! Bool {
//we are authorized now
authBtn.enabled = false
self.authTxt.alphaValue = 1
self.authTxt.alphaValue = self.authBtn.alphaValue
self.view.window!.styleMask -= NSClosableWindowMask
authBtn.enabled = false
self.authTxt.alphaValue = 1
self.authTxt.alphaValue = self.authBtn.alphaValue
self.view.window!.styleMask -= NSClosableWindowMask

NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = 0.25
self.authTxt.animator().alphaValue = 0
self.authBtn.animator().alphaValue = 0

NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = 0.25
self.authTxt.animator().alphaValue = 0
self.authBtn.animator().alphaValue = 0
}, completionHandler: { () -> Void in
self.authTxt.hidden = true
self.authBtn.hidden = true
self.authImg.hidden = false
self.authImg.alphaValue = 0

}, completionHandler: { () -> Void in
self.authTxt.hidden = true
self.authBtn.hidden = true
self.authImg.hidden = false
self.authImg.alphaValue = 0

NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = 0.25
self.authImg.animator().alphaValue = 1
}, completionHandler: nil)

})

NSTimer.scheduledTimerWithTimeInterval(1.5, target: NSBlockOperation(block: self.view.window!.close), selector: #selector(NSOperation.main), userInfo: nil, repeats: false)

}
NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = 0.25
self.authImg.animator().alphaValue = 1
}, completionHandler: nil)

})

NSTimer.scheduledTimerWithTimeInterval(1.5, target: NSBlockOperation(block: self.view.window!.close), selector: #selector(NSOperation.main), userInfo: nil, repeats: false)

}

@IBAction func startAuth(sender: AnyObject) {
Expand Down
30 changes: 18 additions & 12 deletions Noti/PushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate

internal func disconnect() {
//stops attempts to reconnect
killed = true
self.killed = true

//disconnect now!
self.socket!.disconnect(forceTimeout: 0)
Expand Down Expand Up @@ -106,9 +106,12 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
break;
case .ContentsClicked:
//check if this is the encryption warning notification
if(notification.identifier == "noti_encrypt") {
displayPasswordForm()
return
if notification.identifier?.characters.count > 12 {
let index = notification.identifier!.startIndex.advancedBy(12)
if notification.identifier?.substringToIndex(index) == "noti_encrypt" {
displayPasswordForm()
return
}
}

Alamofire.request(.GET, "https://update.pushbullet.com/android_mapping.json")
Expand Down Expand Up @@ -182,7 +185,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
internal func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
print("PushManager", "Is disconnected: \(error?.localizedDescription)")

if(killed) {
if(!self.killed) {
print("Reconnecting in 5 sec");
NSTimer.scheduledTimerWithTimeInterval(5, target: NSBlockOperation(block: self.connect), selector: #selector(NSOperation.main), userInfo: nil, repeats: false)
} else {
Expand All @@ -203,7 +206,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
alert.addButtonWithTitle("Apply")
alert.addButtonWithTitle("Cancel")
alert.messageText = "Enter your PushBullet password"
alert.informativeText = "Leave blank to disable encryption.\nMake sure you set the same password on your other devices as well.\nSaving your password might take a few seconds."
alert.informativeText = "Leave blank to disable encryption.\nMake sure you set the same password on your other devices as well."
let button = alert.runModal()

if button == NSAlertFirstButtonReturn {
Expand Down Expand Up @@ -244,10 +247,10 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
if push["encrypted"].isExists() && push["encrypted"].bool! {
func warnUser() {
let noti = NSUserNotification()
noti.title = "I'm not sure what to make of this!"
noti.title = "I received data I couldn't understand!"
noti.informativeText = "It appears you're using encryption, click to set password."
noti.actionButtonTitle = "Enter password"
noti.identifier = "noti_encrypt"
noti.identifier = "noti_encrypt" + String(arc4random())
center.deliverNotification(noti)
}

Expand Down Expand Up @@ -278,10 +281,13 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
notification.identifier = push["notification_id"].string
notification.subtitle = push["application_name"].string // todo: keep or remove?

let data = NSData(base64EncodedString: push["icon"].string!, options: NSDataBase64DecodingOptions(rawValue: 0))!
let img = RoundedImage(data: data)
notification.setValue(img?.withRoundCorners(Int(img!.size.width) / 2), forKeyPath: "_identityImage")
notification.setValue(false, forKeyPath: "_identityImageHasBorder")
if let icon = push["icon"].string {
let data = NSData(base64EncodedString: icon, options: NSDataBase64DecodingOptions(rawValue: 0))!
let img = RoundedImage(data: data)
notification.setValue(img?.withRoundCorners(Int(img!.size.width) / 2), forKeyPath: "_identityImage")
notification.setValue(false, forKeyPath: "_identityImageHasBorder")
}

notification.setValue(true, forKeyPath: "_showsButtons")

if push["conversation_iden"].isExists() {
Expand Down

0 comments on commit 8eea1c6

Please sign in to comment.