auto-sync

This commit is contained in:
2023-07-05 18:19:53 +02:00
parent c1c0193dae
commit b7c9c8941b
5 changed files with 73 additions and 23 deletions

View File

@@ -1,7 +1,8 @@
<script>
import {serialPort} from "$lib/serial/connection.js"
import {serialPort, syncing} from "$lib/serial/connection.js"
import {browser} from "$app/environment"
import {base} from "$app/paths"
import {slide} from "svelte/transition"
</script>
<nav>
@@ -29,8 +30,11 @@
href="{base}/device-manager"
title="Device Manager"
class="icon connect"
class:error={$serialPort === undefined}>cable</a
class:error={$serialPort === undefined}
class:syncing={$syncing}
>
cable
</a>
<a href={base} title="Statistics" class="icon account">person</a>
</div>
</nav>
@@ -57,6 +61,8 @@
.icon {
cursor: pointer;
position: relative;
aspect-ratio: 1;
padding: 4px;
@@ -116,4 +122,38 @@
color: var(--md-sys-color-on-secondary-container);
background: var(--md-sys-color-secondary-container);
}
@keyframes sync {
from {
rotate: 0deg;
}
to {
rotate: -360deg;
}
}
.connect::after {
pointer-events: none;
content: "sync";
position: absolute;
bottom: 0;
left: 0;
font-size: 16px;
font-weight: 600;
color: var(--md-sys-color-on-background);
opacity: 0;
background: var(--md-sys-color-background);
border-radius: 50%;
transition: opacity 250ms ease;
animation: sync 1s linear infinite;
}
.connect.syncing::after {
opacity: 1;
}
</style>

View File

@@ -5,3 +5,9 @@ export const serialPort = writable()
/** @type {import('svelte/store').Writable<Array<{type: 'input' | 'output' | 'system'; value: string}>>} */
export const serialLog = writable([])
/** @type {import('svelte/store').Writable<Array<{actions: number[]; phrase: string}>>} */
export const chords = writable([])
/** @type {import('svelte/store').Writable<boolean>} */
export const syncing = writable(false)

View File

@@ -61,6 +61,7 @@ export class CharaDevice {
*/
async #read() {
return this.#reader.then(async it => {
/** @type {string} */
const result = await it.read().then(({value}) => value)
serialLog.update(it => {
it.push({