Skip to content

Commit feae50d

Browse files
authored
v3.0.4
2 parents c36d642 + 22ac51f commit feae50d

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

NarodMonMenubarApp/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2121
locationManager!.desiredAccuracy = kCLLocationAccuracyHundredMeters
2222
locationManager!.distanceFilter = 1000
2323

24-
userDefaults.register(defaults: ["UpdateAfterWake": 15,
25-
"UpdateSensorsValues": 7.5 * 60])
24+
userDefaults.register(defaults: ["UpdateAfterWake": 15])
2625

2726
controller = StatusMenuController()
2827

@@ -59,6 +58,7 @@ extension AppDelegate: CLLocationManagerDelegate {
5958
}
6059

6160
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
61+
locationManager!.stopUpdatingLocation()
6262
NSLog("\"locationManager\" error: \(error), calling controller's \"updateLocation\" with nil argument")
6363
controller!.updateLocation(location: nil)
6464
}

NarodMonMenubarApp/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>3.0.3</string>
20+
<string>3.0.4</string>
2121
<key>CFBundleVersion</key>
22-
<string>474</string>
22+
<string>485</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.weather</string>
2525
<key>LSMinimumSystemVersion</key>

NarodMonMenubarApp/NarodMonAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ public class NarodMonAPI {
9292
///
9393
/// - Returns: generated or saved UUID
9494
private func uuid() -> String {
95-
var uuid = keychain.get("UUID")
95+
var uuid = keychain.get("NarodMon Widget UUID")
9696

9797
if (uuid == nil) {
9898
uuid = UUID().uuidString
99-
keychain.set(uuid!, forKey: "UUID", withAccess: .accessibleAlways)
99+
keychain.set(uuid!, forKey: "NarodMon Widget UUID", withAccess: .accessibleAlways)
100100
}
101101

102102
return MD5(string: uuid!)

NarodMonMenubarApp/StatusMenuController.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)