summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Services/ChangelogService.qml
blob: 562a513a8eb327669451fb499e77d6299a4c2d8c (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pragma Singleton
pragma ComponentBehavior: Bound

import QtCore
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Common

Singleton {
    id: root

    readonly property string currentVersion: "1.4"
    readonly property bool changelogEnabled: false

    readonly property string configDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation)) + "/DankMaterialShell"
    readonly property string changelogMarkerPath: configDir + "/.changelog-" + currentVersion

    property bool checkComplete: false
    property bool changelogDismissed: false

    readonly property bool shouldShowChangelog: {
        if (!checkComplete)
            return false;
        if (!changelogEnabled)
            return false;
        if (changelogDismissed)
            return false;
        if (typeof FirstLaunchService !== "undefined" && FirstLaunchService.isFirstLaunch)
            return false;
        return true;
    }

    signal changelogRequested
    signal changelogCompleted

    Component.onCompleted: {
        if (!changelogEnabled)
            return;
        if (FirstLaunchService.checkComplete)
            handleFirstLaunchResult();
    }

    function handleFirstLaunchResult() {
        if (FirstLaunchService.isFirstLaunch) {
            checkComplete = true;
            changelogDismissed = true;
            touchMarkerProcess.running = true;
        } else {
            changelogCheckProcess.running = true;
        }
    }

    Connections {
        target: FirstLaunchService

        function onCheckCompleteChanged() {
            if (FirstLaunchService.checkComplete && root.changelogEnabled && !root.checkComplete)
                root.handleFirstLaunchResult();
        }
    }

    function showChangelog() {
        changelogRequested();
    }

    function dismissChangelog() {
        changelogDismissed = true;
        touchMarkerProcess.running = true;
        changelogCompleted();
    }

    Process {
        id: changelogCheckProcess

        command: ["sh", "-c", "[ -f '" + changelogMarkerPath + "' ] && echo 'seen' || echo 'show'"]
        running: false

        stdout: SplitParser {
            onRead: data => {
                const result = data.trim();
                root.checkComplete = true;

                switch (result) {
                case "seen":
                    root.changelogDismissed = true;
                    break;
                case "show":
                    root.changelogRequested();
                    break;
                }
            }
        }
    }

    Process {
        id: touchMarkerProcess

        command: ["sh", "-c", "mkdir -p '" + configDir + "' && touch '" + changelogMarkerPath + "'"]
        running: false

        onExited: exitCode => {
            if (exitCode !== 0) {
                console.warn("ChangelogService: Failed to create changelog marker");
            }
        }
    }
}