mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-02-28 03:52:05 +00:00
add backup feature
This commit is contained in:
@@ -38,6 +38,8 @@ const config: IconsConfig = {
|
|||||||
"close",
|
"close",
|
||||||
"arrow_back",
|
"arrow_back",
|
||||||
"arrow_back_ios_new",
|
"arrow_back_ios_new",
|
||||||
|
"save",
|
||||||
|
"settings_backup_restore",
|
||||||
],
|
],
|
||||||
codePoints: {
|
codePoints: {
|
||||||
speed: "e9e4",
|
speed: "e9e4",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import {serialPort, syncStatus} from "$lib/serial/connection"
|
import {serialPort, syncStatus} from "$lib/serial/connection"
|
||||||
import {browser} from "$app/environment"
|
import {browser} from "$app/environment"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
|
import {slide} from "svelte/transition"
|
||||||
|
|
||||||
const training = [
|
const training = [
|
||||||
{slug: "cpm", title: "CPM - Characters Per Minute", icon: "music_note"},
|
{slug: "cpm", title: "CPM - Characters Per Minute", icon: "music_note"},
|
||||||
@@ -39,13 +40,20 @@
|
|||||||
warning
|
warning
|
||||||
</abbr>
|
</abbr>
|
||||||
{/if}
|
{/if}
|
||||||
|
<a
|
||||||
|
title="Backup & Restore"
|
||||||
|
href="/backup/"
|
||||||
|
class="icon {$syncStatus}"
|
||||||
|
class:active={$page.url.pathname.startsWith("/backup/")}
|
||||||
|
>
|
||||||
{#if $syncStatus === "downloading"}
|
{#if $syncStatus === "downloading"}
|
||||||
<abbr title="Backing up settings" class="icon sync backup">backup</abbr>
|
backup
|
||||||
{:else if $syncStatus === "uploading"}
|
{:else if $syncStatus === "uploading"}
|
||||||
<abbr title="Saving settings" class="icon sync save">cloud_download</abbr>
|
cloud_download
|
||||||
{:else if $syncStatus === "done"}
|
{:else}
|
||||||
<abbr title="Device settings are up-to-date" class="icon">cloud_done</abbr>
|
cloud_done
|
||||||
{/if}
|
{/if}
|
||||||
|
</a>
|
||||||
<a
|
<a
|
||||||
href="/config/"
|
href="/config/"
|
||||||
title="Device Manager"
|
title="Device Manager"
|
||||||
@@ -82,7 +90,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sync::after {
|
.uploading::after,
|
||||||
|
.downloading::after {
|
||||||
content: "";
|
content: "";
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -99,9 +108,14 @@
|
|||||||
animation: sync 1s linear infinite;
|
animation: sync 1s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sync.save::after {
|
.downloading.active::after,
|
||||||
transform-origin: bottom;
|
.uploading.active::after {
|
||||||
|
background: var(--md-sys-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sync.downloading::after {
|
||||||
top: 10px;
|
top: 10px;
|
||||||
|
transform-origin: bottom;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/routes/backup/+page.svelte
Normal file
23
src/routes/backup/+page.svelte
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
import {getSharableUrl, stringifyCompressed} from "$lib/serial/serialization"
|
||||||
|
import {chords} from "$lib/serial/connection"
|
||||||
|
|
||||||
|
async function downloadBackup() {
|
||||||
|
const downloadUrl = URL.createObjectURL(await stringifyCompressed($chords))
|
||||||
|
const element = document.createElement("a")
|
||||||
|
element.setAttribute("download", "chords.chl")
|
||||||
|
element.href = downloadUrl
|
||||||
|
element.setAttribute("target", "_blank")
|
||||||
|
element.click()
|
||||||
|
URL.revokeObjectURL(downloadUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createShareUrl() {
|
||||||
|
console.log(await getSharableUrl("chords", $chords))
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Backup & Restore</h1>
|
||||||
|
|
||||||
|
<button on:click={downloadBackup}><span class="icon">save</span> Backup</button>
|
||||||
|
<button><span class="icon">settings_backup_restore</span> Restore</button>
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
import type {Index} from "flexsearch"
|
import type {Index} from "flexsearch"
|
||||||
import {tick} from "svelte"
|
import {tick} from "svelte"
|
||||||
import type {Chord} from "$lib/serial/chord"
|
import type {Chord} from "$lib/serial/chord"
|
||||||
import {getSharableUrl, stringifyCompressed} from "$lib/serial/serialization"
|
|
||||||
|
|
||||||
$: searchIndex = $chords?.length > 0 ? buildIndex($chords) : undefined
|
$: searchIndex = $chords?.length > 0 ? buildIndex($chords) : undefined
|
||||||
|
|
||||||
@@ -30,20 +29,6 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadBackup() {
|
|
||||||
const downloadUrl = URL.createObjectURL(await stringifyCompressed($chords))
|
|
||||||
const element = document.createElement("a")
|
|
||||||
element.setAttribute("download", "chords.json.gz")
|
|
||||||
element.href = downloadUrl
|
|
||||||
element.setAttribute("target", "_blank")
|
|
||||||
element.click()
|
|
||||||
URL.revokeObjectURL(downloadUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createShareUrl() {
|
|
||||||
console.log(await getSharableUrl("chords", $chords))
|
|
||||||
}
|
|
||||||
|
|
||||||
$: items = searchFilter?.map(it => [$chords[it], it]) ?? $chords.map((it, i) => [it, i])
|
$: items = searchFilter?.map(it => [$chords[it], it]) ?? $chords.map((it, i) => [it, i])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -77,12 +62,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</table>
|
</table>
|
||||||
<div class="backup">
|
|
||||||
<button class="icon" title="Sharable URL" on:click={createShareUrl()}>share</button>
|
|
||||||
<div class="icon" title="Chords have been backed up to this browser.">cloud_done</div>
|
|
||||||
<button class="icon" title="Restore local chord backup">backup</button>
|
|
||||||
<button class="icon" title="Download local chord backup" on:click={downloadBackup}>cloud_download</button>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@@ -113,11 +92,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.backup {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
section {
|
section {
|
||||||
--scrollbar-color: var(--md-sys-color-surface-variant);
|
--scrollbar-color: var(--md-sys-color-surface-variant);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user