summaryrefslogtreecommitdiff
path: root/app/qml/pebble.qml
blob: 0643f79bb26f82fdbfa37381d1a58a2806b8d654 (plain)
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
64
65
66
67
68
69
import QtQuick 2.0
import Sailfish.Silica 1.0
import "pages"
import org.pebbled 0.1

ApplicationWindow
{
    id: app

    property string firmwareVersion
    property string recoveryVersion
    property string hardwareVersion
    property string firmwareLatest

    initialPage: Component { ManagerPage { } }
    cover: Qt.resolvedUrl("cover/CoverPage.qml")

    function parseInfo() {
        if (pebbled.info.firmware && pebbled.info.firmware.length) {
            pebbled.info.firmware.forEach(function(firmware){
                if (firmware.recovery) {
                    recoveryVersion = firmware.version
                } else {
                    firmwareVersion = firmware.version
                }
                if (firmware.hardware) {
                    hardwareVersion = firmware.hardware
                }
            })
        } else {
            firmwareVersion = recoveryVersion = hardwareVersion = ""
        }
    }

    function notifyNewFirmware() {
        firmwareLatest = pebbleFirmware.latest.friendlyVersion || ""
        if (firmwareLatest && firmwareVersion) {
            pebbled.notifyFirmware(firmwareVersion === firmwareLatest);
        }
    }

    Component.onCompleted: {
        parseInfo()
    }

    Connections {
        target: pebbled
        onInfoChanged: {
            parseInfo()
        }
    }

    onHardwareVersionChanged: {
        if (hardwareVersion) {
            pebbleFirmware.updateLatest(hardwareVersion)
        }
    }

    onFirmwareVersionChanged: {
        notifyNewFirmware()
    }

    Connections {
        target: pebbleFirmware
        onLatestChanged: {
            notifyNewFirmware()
        }
    }
}