@@ -25,6 +25,7 @@ class StatusMenuController: NSObject {
2525 var location : CLLocation ?
2626 var fetchTimer : Timer ?
2727 var retryCount : Int = 0
28+ var sensorsNearbyUpdateInterval : Double = 450
2829 var querySensors : [ Int ] = [ ]
2930
3031 var wake : Date ? = nil
@@ -51,7 +52,7 @@ class StatusMenuController: NSObject {
5152 statusMenu. addItem ( NSMenuItem . separator ( ) )
5253 statusMenu. addItem ( withTitle: " Выйти " , action: #selector( StatusMenuController . quitBtnPress ( sender: ) ) , keyEquivalent: " " )
5354
54- narodMon = NarodMonAPI ( withAPIKey: " 40MHsctSKi4y6 " )
55+ narodMon = NarodMonAPI ( withAPIKey: " 4Pk1qAgMhSyPc " )
5556
5657 super. init ( )
5758
@@ -101,7 +102,7 @@ class StatusMenuController: NSObject {
101102 }
102103
103104 func requestSensorsValuesUpdate( force: Bool = true ) {
104- if !( force || Date ( ) . timeIntervalSince ( latestValues ?? Date ( timeIntervalSince1970: 0 ) ) > userDefaults . double ( forKey : " UpdateSensorsValues " ) ) { return }
105+ if !( force || Date ( ) . timeIntervalSince ( latestValues ?? Date ( timeIntervalSince1970: 0 ) ) > sensorsNearbyUpdateInterval ) { return }
105106 narodMon. sensorsValues ( sensors: self . querySensors)
106107 }
107108
@@ -122,9 +123,10 @@ extension StatusMenuController: NarodMonAPIDelegate {
122123 if ( app == nil ) {
123124 goOffline ( )
124125
125- NSLog ( " Will retry \" appInit \" # \( retryCount + 1 ) " )
126+ let retryInterval = TimeInterval ( self . retryCount < 3 ? 10 : ( 10 * 60 ) )
127+ NSLog ( " Will retry \" appInit \" # \( retryCount + 1 ) in \( retryInterval) s " )
126128 DispatchQueue . main. async {
127- Timer . scheduledTimer ( withTimeInterval: self . retryCount < 3 ? 10 : ( 10 * 60 ) , repeats: false , block: { _ in
129+ Timer . scheduledTimer ( withTimeInterval: retryInterval , repeats: false , block: { _ in
128130 _ = self . requestAppInitUpdate ( )
129131 } )
130132 }
@@ -222,8 +224,7 @@ extension StatusMenuController: NarodMonAPIDelegate {
222224
223225 if delta != 0.0 {
224226 NSLog ( " \" sensorsValues \" interval: \( currentInterval) s, new interval: \( newInterval) s, delta: \( delta) " )
225- userDefaults. set ( newInterval, forKey: " UpdateSensorsValues " )
226- userDefaults. synchronize ( )
227+ sensorsNearbyUpdateInterval = newInterval
227228 }
228229 }
229230
@@ -268,6 +269,7 @@ extension StatusMenuController: NarodMonAPIDelegate {
268269 func gotLocation( location: CLLocation ? ) {
269270 if location == nil {
270271 NSLog ( " Failed to get new location " )
272+ return
271273 }
272274
273275 NSLog ( " Got new location: \( location!. debugDescription) " )
0 commit comments