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

Commit

Permalink
Even more log data
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Jan 5, 2018
1 parent 5775f40 commit 678bc82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Binary file not shown.
11 changes: 9 additions & 2 deletions Noti/PushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
center.delegate = self
self.initCrypt()

log.debug("Getting user info...")
log.debug("Init Noti")
getUserInfo {
self.connect()
}
Expand All @@ -54,7 +54,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
}

@objc internal func disconnect(attemptReconnect: Bool = true) {
log.warning("Triggered disconnect attemptReconnect:\(attemptReconnect)")
log.warning("Triggered disconnect attemptReconnect:\(attemptReconnect), isConnected:\(self.socket!.isConnected)")
//stops attempts to reconnect
if !attemptReconnect {
self.killed = true
Expand Down Expand Up @@ -95,6 +95,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate

var _callback:(() -> Void)? = nil
func getUserInfo(_ callback: (() -> Void)?) {
log.debug("Getting user info...")
//todo: this is kinda dirty ...
self._callback = callback

Expand Down Expand Up @@ -267,6 +268,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
}

func connect() {
log.debug("Connecting to Pushbullet")
socket!.delegate = self
socket!.connect()
}
Expand Down Expand Up @@ -323,11 +325,13 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
case "tickle":
if let subtype = message["subtype"].string {
if(subtype == "account") {
log.debug("TICKLE -> account")
getUserInfo(nil)
}
else if(subtype == "push"){
// When you receive a tickle message, it means that a resource of the type push has changed.
// Request only the latest push: In this case can be a file, a link or just a simple note
log.debug("TICKLE -> push")
Alamofire.request("https://api.pushbullet.com/v2/pushes?limit=1", headers: ["Access-Token": token])
.responseString { response in
if let result = response.result.value {
Expand All @@ -346,10 +350,12 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
if let pushType = push["type"].string {
switch(pushType) {
case "mirror":
log.debug("PUSH -> mirror")
center.deliver(createNotification(push))
break;
case "dismissal":
//loop through current user notifications, if identifier matches, remove it
log.debug("PUSH -> dismiss")
for noti in center.deliveredNotifications {
if noti.identifier == push["notification_id"].string {
center.removeDeliveredNotification(noti)
Expand All @@ -370,6 +376,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate

break;
case "sms_changed":
log.debug("PUSH -> sms_changed")
if push["notifications"].exists() {
for sms in push["notifications"].array! {
let notification = NSUserNotification()
Expand Down

0 comments on commit 678bc82

Please sign in to comment.