forked from oepi-loepi/AutoReboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoRebootApp.qml
More file actions
63 lines (51 loc) · 1.81 KB
/
Copy pathAutoRebootApp.qml
File metadata and controls
63 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import QtQuick 2.1
import qb.components 1.0
import qb.base 1.0
import BxtClient 1.0
App {
id: autoRebootApp
property url tileUrl : "AutoRebootTile.qml"
property url thumbnailIcon: "qrc:/tsc/refresh.png"
property string configMsgUuid : ""
property string timeStr
property string dateStr
property string lastStart
function init() {
registry.registerWidget("tile", tileUrl, autoRebootApp, null, {thumbLabel: qsTr("Auto Reboot"), thumbIcon: thumbnailIcon, thumbCategory: "general", thumbWeight: 30, baseTileWeight: 10, baseTileSolarWeight: 10, thumbIconVAlignment: "center"});
}
Component.onCompleted: {
var now = new Date()
var now2 = now.getTime()
timeStr = i18n.dateTime(now2, i18n.time_yes)
dateStr = i18n.dateTime(now2, i18n.date_yes)
lastStart = "(laatste start: " + dateStr + " " + timeStr + ")"
// calculate new restart interval to two days later at 03:30
var nowUtc = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(),now.getMilliseconds());
var nextRestartDate = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate() + 2, 3, 30, 0, 0);
timeStr = "03:00"
dateStr = i18n.dateTime(nextRestartDate , i18n.date_yes)
datetimeTimer.interval = nextRestartDate - nowUtc;
datetimeTimer.start();
console.log("Autorestart in:" + (nextRestartDate - nowUtc) + " ms from: " + now);
}
Timer {
id: datetimeTimer
triggeredOnStart: false
running: false
repeat: false
onTriggered: {
restartToon()
}
}
function restartToon() {
var restartToonMessage = bxtFactory.newBxtMessage(BxtMessage.ACTION_INVOKE, configMsgUuid, "specific1", "RequestReboot")
bxtClient.sendMsg(restartToonMessage)
}
BxtDiscoveryHandler {
id: configDiscoHandler
deviceType: "hcb_config"
onDiscoReceived: {
configMsgUuid = deviceUuid
}
}
}