Skip to content

Commit 2a41aca

Browse files
Никита ТимофеевНикита Тимофеев
authored andcommitted
Added update timer
1 parent 444207f commit 2a41aca

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

NarodMonWidget/Base.lproj/MainMenu.xib

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2657" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
56
</dependencies>
67
<objects>
78
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -43,17 +44,17 @@
4344
<point key="canvasLocation" x="75" y="145"/>
4445
</menu>
4546
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="Sw7-fe-Eoh">
46-
<rect key="frame" x="0.0" y="0.0" width="144" height="45"/>
47+
<rect key="frame" x="0.0" y="0.0" width="151" height="45"/>
4748
<autoresizingMask key="autoresizingMask"/>
4849
<clipView key="contentView" id="KEO-HK-EM0">
49-
<rect key="frame" x="1" y="1" width="142" height="43"/>
50+
<rect key="frame" x="1" y="1" width="134" height="43"/>
5051
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
5152
<subviews>
5253
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" findStyle="panel" quoteSubstitution="YES" dashSubstitution="YES" smartInsertDelete="YES" id="sT5-qx-W03" customClass="WeatherView" customModule="NarodMonWidget" customModuleProvider="target">
53-
<rect key="frame" x="0.0" y="0.0" width="142" height="43"/>
54-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
54+
<rect key="frame" x="0.0" y="0.0" width="134" height="43"/>
55+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" heightSizable="YES"/>
5556
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
56-
<size key="minSize" width="142" height="43"/>
57+
<size key="minSize" width="134" height="43"/>
5758
<size key="maxSize" width="463" height="10000000"/>
5859
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
5960
</textView>
@@ -65,10 +66,10 @@
6566
<autoresizingMask key="autoresizingMask"/>
6667
</scroller>
6768
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="oxT-7l-Ji3">
68-
<rect key="frame" x="127" y="1" width="16" height="43"/>
69+
<rect key="frame" x="135" y="1" width="15" height="43"/>
6970
<autoresizingMask key="autoresizingMask"/>
7071
</scroller>
71-
<point key="canvasLocation" x="339" y="47.5"/>
72+
<point key="canvasLocation" x="74.5" y="257.5"/>
7273
</scrollView>
7374
</objects>
7475
</document>

NarodMonWidget/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>2.0.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>129</string>
22+
<string>140</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.weather</string>
2525
<key>LSMinimumSystemVersion</key>

NarodMonWidget/StatusMenuController.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
1717
var weatherMenuItem: NSMenuItem!
1818
var narodMonAPI: NarodMonAPI!
1919
var sensorsList: [Int:Type] = [:]
20+
var updateTimer: Timer!
2021

2122
override func awakeFromNib() {
2223
narodMonAPI = NarodMonAPI(delegate: self)
@@ -37,7 +38,14 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
3738
sensorsList.updateValue(sensor.type, forKey: sensor.id)
3839
sensList.append(sensor.id)
3940
}
40-
narodMonAPI.sensorsValues(sensors: sensList)
41+
//narodMonAPI.sensorsValues(sensors: sensList)
42+
43+
if (updateTimer != nil) {
44+
updateTimer.invalidate()
45+
}
46+
updateTimer = Timer.init(timeInterval: 3 * 60, target: self, selector: #selector(StatusMenuController.performUpdateValues), userInfo:nil , repeats: true)
47+
RunLoop.main.add(updateTimer, forMode: RunLoopMode.commonModes)
48+
updateTimer.fire()
4149
}
4250

4351
func gotSensorsValues(rdgs: [Reading]) {
@@ -80,6 +88,10 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
8088

8189
}
8290

91+
func performUpdateValues() -> Void {
92+
narodMonAPI.sensorsValues(sensors: Array(sensorsList.keys))
93+
}
94+
8395
func appInitiated(app: App) {
8496
if app.latest > Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String {
8597
let alert = NSAlert()

0 commit comments

Comments
 (0)