mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 17:03:42 +00:00
@@ -6,6 +6,8 @@ import type { CharaLayout } from "$lib/serialization/layout";
|
||||
import { persistentWritable } from "$lib/storage";
|
||||
import { userPreferences } from "$lib/preferences";
|
||||
import settingInfo from "$lib/assets/settings.yml";
|
||||
import { getMeta } from "$lib/meta/meta-storage";
|
||||
import type { VersionMeta } from "$lib/meta/types/meta";
|
||||
|
||||
export const serialPort = writable<CharaDevice | undefined>();
|
||||
|
||||
@@ -47,6 +49,8 @@ export const syncStatus: Writable<
|
||||
"done" | "error" | "downloading" | "uploading"
|
||||
> = writable("done");
|
||||
|
||||
export const deviceMeta = writable<VersionMeta | undefined>(undefined);
|
||||
|
||||
export interface ProgressInfo {
|
||||
max: number;
|
||||
current: number;
|
||||
@@ -65,6 +69,12 @@ export async function initSerial(manual = false, withSync = true) {
|
||||
export async function sync() {
|
||||
const device = get(serialPort);
|
||||
if (!device) return;
|
||||
getMeta(
|
||||
`${device.device}_${device.chipset}`.toLowerCase(),
|
||||
device.version.toString(),
|
||||
).then((meta) => {
|
||||
deviceMeta.set(meta);
|
||||
});
|
||||
const chordCount = await device.getChordCount();
|
||||
syncStatus.set("downloading");
|
||||
|
||||
|
||||
@@ -1,38 +1,64 @@
|
||||
import type { ActionInfo, KeymapCategory } from "$lib/assets/keymaps/keymap";
|
||||
import { derived, type Readable } from "svelte/store";
|
||||
import { deviceMeta } from "./connection";
|
||||
|
||||
export interface KeyInfo extends Partial<ActionInfo> {
|
||||
code: number;
|
||||
category?: KeymapCategory;
|
||||
}
|
||||
|
||||
export const KEYMAP_CATEGORIES = (await Promise.all(
|
||||
const fallbackActions = await Promise.all<KeymapCategory>(
|
||||
Object.values(import.meta.glob("$lib/assets/keymaps/*.yml")).map(
|
||||
async (load) => load().then((it) => (it as any).default),
|
||||
),
|
||||
)) as KeymapCategory[];
|
||||
|
||||
export const KEYMAP_CODES = new Map<number, KeyInfo>(
|
||||
KEYMAP_CATEGORIES.flatMap((category) =>
|
||||
Object.entries(category.actions).map(([code, action]) => [
|
||||
Number(code),
|
||||
{ ...action, code: Number(code), category },
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
export const KEYMAP_KEYCODES = new Map<string, number>(
|
||||
KEYMAP_CATEGORIES.flatMap((category) =>
|
||||
Object.entries(category.actions).map(
|
||||
([code, action]) => [action.keyCode!, Number(code)] as const,
|
||||
export let KEYMAP_CATEGORIES: Readable<KeymapCategory[]> = derived(
|
||||
deviceMeta,
|
||||
(deviceMeta) => deviceMeta?.actions ?? fallbackActions,
|
||||
);
|
||||
|
||||
export const KEYMAP_CODES: Readable<Map<number, KeyInfo>> = derived(
|
||||
KEYMAP_CATEGORIES,
|
||||
(categories) =>
|
||||
new Map<number, KeyInfo>(
|
||||
categories.flatMap((category) =>
|
||||
Object.entries(category.actions).map(([code, action]) => [
|
||||
Number(code),
|
||||
{ ...action, code: Number(code), category },
|
||||
]),
|
||||
),
|
||||
),
|
||||
).filter(([keyCode]) => keyCode !== undefined),
|
||||
);
|
||||
|
||||
export const KEYMAP_IDS = new Map<string, KeyInfo>(
|
||||
KEYMAP_CATEGORIES.flatMap((category) =>
|
||||
Object.entries(category.actions).map(
|
||||
([code, action]) =>
|
||||
[action.id!, { ...action, code: Number(code), category }] as const,
|
||||
export const KEYMAP_KEYCODES: Readable<Map<string, number>> = derived(
|
||||
KEYMAP_CATEGORIES,
|
||||
(categories) =>
|
||||
new Map<string, number>(
|
||||
categories
|
||||
.flatMap((category) =>
|
||||
Object.entries(category.actions).map(
|
||||
([code, action]) => [action.keyCode!, Number(code)] as const,
|
||||
),
|
||||
)
|
||||
.filter(([keyCode]) => keyCode !== undefined),
|
||||
),
|
||||
);
|
||||
|
||||
export const KEYMAP_IDS: Readable<Map<string, KeyInfo>> = derived(
|
||||
KEYMAP_CATEGORIES,
|
||||
(categories) =>
|
||||
new Map<string, KeyInfo>(
|
||||
categories
|
||||
.flatMap((category) =>
|
||||
Object.entries(category.actions).map(
|
||||
([code, action]) =>
|
||||
[
|
||||
action.id!,
|
||||
{ ...action, code: Number(code), category },
|
||||
] as const,
|
||||
),
|
||||
)
|
||||
.filter(([id]) => id !== undefined),
|
||||
),
|
||||
).filter(([id]) => id !== undefined),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user