refactor: cleanup

This commit is contained in:
2023-11-15 01:46:23 +01:00
parent c5d9defc9d
commit 561300de64
10 changed files with 33 additions and 69 deletions

6
src/env.d.ts vendored
View File

@@ -7,11 +7,11 @@ interface ImportMetaEnv {
readonly TAURI_ARCH?: string readonly TAURI_ARCH?: string
readonly TAURI_DEBUG?: boolean readonly TAURI_DEBUG?: boolean
readonly TAURI_PLATFORM_TYPE?: string readonly TAURI_PLATFORM_TYPE?: string
readonly VITE_HOMEPAGE_URL: string
readonly VITE_BUGS_URL: string
} }
interface ImportMeta { interface ImportMeta {
readonly env: ImportMetaEnv readonly env: ImportMetaEnv
} }
declare const HOMEPAGE_URL: string
declare const BUGS_URL: string

View File

@@ -1,13 +1,10 @@
<script lang="ts"> <script lang="ts">
import {deviceLayout, serialPort} from "$lib/serial/connection" import {serialPort} from "$lib/serial/connection"
import {action} from "$lib/title" import {action} from "$lib/title"
import GenericLayout from "$lib/components/layout/GenericLayout.svelte" import GenericLayout from "$lib/components/layout/GenericLayout.svelte"
import {getContext} from "svelte" import {getContext} from "svelte"
import type {Writable} from "svelte/store" import type {Writable} from "svelte/store"
import {csvLayoutToJson, isCsvLayout} from "$lib/backup/compat/legacy-layout" import type {VisualLayout} from "$lib/serialization/visual-layout"
import type {CharaLayoutFile} from "$lib/share/chara-file"
export let layoutOverride: "ONE" | "LITE" | undefined = undefined
$: device = $serialPort?.device ?? "ONE" $: device = $serialPort?.device ?? "ONE"
const activeLayer = getContext<Writable<number>>("active-layer") const activeLayer = getContext<Writable<number>>("active-layer")
@@ -19,20 +16,10 @@
] as const ] as const
const layouts = { const layouts = {
ONE: () => import("$lib/assets/layouts/one.yml"), ONE: () => import("$lib/assets/layouts/one.yml").then(it => it.default as VisualLayout),
LITE: () => import("$lib/assets/layouts/lite.yml"), LITE: () => import("$lib/assets/layouts/lite.yml").then(it => it.default as VisualLayout),
X: () => import("$lib/assets/layouts/generic/103-key.yml"), X: () => import("$lib/assets/layouts/generic/103-key.yml").then(it => it.default as VisualLayout),
} }
async function importLayout() {
const file = await fileInput.files?.item(0)?.text()
if (!file) return
const importedLayout = isCsvLayout(file) ? csvLayoutToJson(file) : (JSON.parse(file) as CharaLayoutFile)
if (importedLayout.type === "layout" && importedLayout.charaVersion === 1)
$deviceLayout = importedLayout.layout
}
let fileInput: HTMLInputElement
</script> </script>
<div class="container"> <div class="container">
@@ -49,21 +36,12 @@
{/each} {/each}
</fieldset> </fieldset>
{#await layouts[layoutOverride || device]() then { default: visualLayout }} {#await layouts[device]() then visualLayout}
<GenericLayout {visualLayout} /> <GenericLayout {visualLayout} />
{/await} {/await}
</div> </div>
<style lang="scss"> <style lang="scss">
.controls {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
justify-content: center;
width: 100%;
}
.container { .container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -27,26 +27,9 @@
text-align: center; text-align: center;
} }
dialog {
min-width: 300px;
max-width: 512px;
color: var(--md-sys-color-on-background);
background: var(--md-sys-color-background);
border: none;
border-radius: 38px;
box-shadow: 0 0 48px rgba(0 0 0 / 60%);
}
.buttons { .buttons {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
width: 100%; width: 100%;
} }
dialog::backdrop {
opacity: 0.5;
background: black;
}
</style> </style>

View File

@@ -15,7 +15,6 @@ export async function askForConfirmation(
abortTitle, abortTitle,
}, },
}) })
dialog.show()
let resolvePromise: (value: boolean) => void let resolvePromise: (value: boolean) => void
const resultPromise = new Promise<boolean>(resolve => { const resultPromise = new Promise<boolean>(resolve => {

View File

@@ -6,9 +6,9 @@ export const prerender = true
export const trailingSlash = "always" export const trailingSlash = "always"
export const load = (async ({url, data, fetch}) => { export const load = (async ({url, data, fetch}) => {
const importFile = new URLSearchParams(url.search).get("import") const importFile = browser && new URLSearchParams(url.search).get("import")
return { return {
...data, ...data,
importFile: browser && importFile ? await charaFileFromUriComponent(importFile, fetch) : undefined, importFile: importFile ? await charaFileFromUriComponent(importFile, fetch) : undefined,
} }
}) satisfies LayoutLoad }) satisfies LayoutLoad

View File

@@ -57,7 +57,16 @@
</div> </div>
</div> </div>
{#if powerDialog} {#if powerDialog}
<div class="backdrop" transition:fade={{duration: 250}} on:click={() => (powerDialog = !powerDialog)} /> <div
class="backdrop"
role="button"
tabindex="-1"
transition:fade={{duration: 250}}
on:click={() => (powerDialog = !powerDialog)}
on:keypress={event => {
if (event.key === "Enter") powerDialog = !powerDialog
}}
/>
<dialog open transition:slide={{duration: 250}}> <dialog open transition:slide={{duration: 250}}>
<h3>{$LL.deviceManager.bootMenu.TITLE()}</h3> <h3>{$LL.deviceManager.bootMenu.TITLE()}</h3>
<button <button

View File

@@ -34,10 +34,13 @@
<footer> <footer>
<ul> <ul>
<li> <li>
<a href={HOMEPAGE_URL} rel="noreferrer" target="_blank"><span class="icon">commit</span> v{version}</a> <!-- svelte-ignore not-defined -->
<a href={import.meta.env.VITE_HOMEPAGE_URL} rel="noreferrer" target="_blank"
><span class="icon">commit</span> v{version}</a
>
</li> </li>
<li> <li>
<a href={BUGS_URL} rel="noreferrer" target="_blank" <a href={import.meta.env.VITE_BUGS_URL} rel="noreferrer" target="_blank"
><span class="icon">bug_report</span> File an issue</a ><span class="icon">bug_report</span> File an issue</a
> >
</li> </li>

View File

@@ -65,8 +65,4 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
input[type="file"] {
display: none;
}
</style> </style>

View File

@@ -97,7 +97,7 @@
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend><label>Device</label></legend> <legend>Device</legend>
<label>Boot message<input type="checkbox" use:setting={{id: 93}} /></label> <label>Boot message<input type="checkbox" use:setting={{id: 93}} /></label>
<label>Realtime Feedback<input type="checkbox" use:setting={{id: 92}} /></label> <label>Realtime Feedback<input type="checkbox" use:setting={{id: 92}} /></label>
<label> <label>
@@ -118,7 +118,7 @@
<fieldset> <fieldset>
<legend><label><input type="checkbox" />RGB</label></legend> <legend><label><input type="checkbox" />RGB</label></legend>
<label>Brightness<input type="range" min="0" max="50" step="1" /></label> <label>Brightness<input type="range" min="0" max="50" step="1" /></label>
<label>Color</label> Color
<label>Reactive Keys<input type="checkbox" /></label> <label>Reactive Keys<input type="checkbox" /></label>
</fieldset> </fieldset>
{/if} {/if}
@@ -141,10 +141,6 @@
legend > label { legend > label {
font-size: 24px; font-size: 24px;
font-weight: bold; font-weight: bold;
> input {
font-size: 12px;
}
} }
fieldset { fieldset {
@@ -230,6 +226,7 @@
} }
} }
// stylelint-disable-next-line
form label:has(:global(.pending-changes)) { form label:has(:global(.pending-changes)) {
color: var(--md-sys-color-tertiary); color: var(--md-sys-color-tertiary);
} }

View File

@@ -13,6 +13,9 @@ const {homepage, bugs} = JSON.parse(
await readFile(fileURLToPath(new URL("package.json", import.meta.url)), "utf8"), await readFile(fileURLToPath(new URL("package.json", import.meta.url)), "utf8"),
) )
process.env.VITE_HOMEPAGE_URL = homepage
process.env.VITE_BUGS_URL = bugs.url
export default defineConfig({ export default defineConfig({
build: { build: {
// we rely on the serial api, so just chrome is fine // we rely on the serial api, so just chrome is fine
@@ -21,11 +24,7 @@ export default defineConfig({
external: isTauri ? [/virtual:pwa.*/] : [], external: isTauri ? [/virtual:pwa.*/] : [],
}, },
}, },
define: { envPrefix: ["TAURI_", "VITE_"],
HOMEPAGE_URL: `"${homepage}"`,
BUGS_URL: `"${bugs.url}"`,
},
envPrefix: "TAURI_",
plugins: [ plugins: [
ViteYaml(), ViteYaml(),
sveltekit(), sveltekit(),