aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/Settings/Version.svelte
blob: 35c8f969aa148b9950b6f9ff49961cfae82993db (plain) (blame)
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
<script>
    import { onMount } from 'svelte';
    import FloatingButton from "../../ComponentLib/Button/FloatingButton.svelte";
    import PrettyVar from "../../ComponentLib/PrettyVar.svelte";
    import { authorizedSocket } from "../../stores/socketStore.js";

    let version = "-";
    let branch = "-";
    let newVer = "-";
    
    authorizedSocket.on("version:branch", _branch => branch = _branch);
    authorizedSocket.on("version:current_number", _version => version = _version);
    authorizedSocket.on("version:newest_number", _version => newVer = _version);

    let checkVersionPromise;
    function checkForUpdate() {
        checkVersionPromise = new Promise((resolve, reject) => {
            authorizedSocket.emit("version:check_for_update", () => {
                resolve();
            });
        });
    }

    let updateVersionPromise;
    function doUpdate() {
        authorizedSocket.emit("system:update_version");
    }
    
    onMount(async() => {
        authorizedSocket.emit("version:branch");
        authorizedSocket.emit("version:current_number");
        authorizedSocket.emit("version:newest_number");
    });
</script>

<style>
    h1, p { margin: 0; }
    .label {
        font-weight: 100;
        font-style: italic;
        color: var(--grey-600);
    }
    .button-row {
        /* display: flex; */
        margin-top: 20px;
        width: 100%;
        /* justify-content: center; */
        /* align-items: center; */
    }
    .update-available {
        color: var(--green-300);
    }
</style>

<div>
    <h1>Version</h1>
    <p><span class="label">Current version</span> <PrettyVar varText={version}/></p>
    <p><span class="label">Current branch</span> <PrettyVar bind:varText={branch}/></p>
    {#if newVer != version}
    <p><span class="update-available">Version <PrettyVar bind:varText={newVer} /> available.</span></p>
    <FloatingButton on:click={doUpdate} bind:loadingPromise={updateVersionPromise} fullWidth=true>Update luxcena-neo</FloatingButton>
    {/if}
    <div class="button-row">
        <FloatingButton on:click={checkForUpdate} bind:loadingPromise={checkVersionPromise} fullWidth=true>Check for updates</FloatingButton>
    </div>
</div>