Migrate updater LAN and devkit features from old repo

This commit is contained in:
lenn
2026-04-27 16:37:40 +08:00
parent b33c952eb6
commit 26533f6916
29 changed files with 5207 additions and 55 deletions

View File

@@ -3,9 +3,12 @@
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { LogicalSize, currentMonitor, getCurrentWindow } from "@tauri-apps/api/window";
import { relaunch } from "@tauri-apps/plugin-process";
import { check } from "@tauri-apps/plugin-updater";
import HudPanel from "$lib/components/HudPanel.svelte";
import CenterStage from "$lib/components/CenterStage.svelte";
import FileExplorerModal from "$lib/components/FileExplorerModal.svelte";
import DevKitConfigPanel from "$lib/components/DevKitConfigPanel.svelte";
import { DEFAULT_PRESSURE_RANGE_MAX, DEFAULT_PRESSURE_RANGE_MIN } from "$lib/config/pressure-range";
import { pressureColorPalettes } from "$lib/config/color-map";
import "$lib/styles/theme.css";
@@ -203,6 +206,9 @@
let isRefreshingPorts = false;
let connectionNotice = "";
let connectionNoticeTone: HudNoticeTone = "info";
let updateNoticeVisible = false;
let updateInstallBusy = false;
let pendingUpdate: Awaited<ReturnType<typeof check>> | null = null;
let isExporting = false;
let deviceValue = "JE-Skin-F";
let sampleRateValue = "100Hz";
@@ -238,6 +244,22 @@
let fileExplorerRoots: FileExplorerRoot[] = [];
let fileExplorerSelectedPath = "";
let fileExplorerFileName = "";
let isDevKitConfigOpen = false;
let devkitEnabled = false;
let devkitRunning = false;
let devkitPort = 50051;
let devkitFramesSent = 0;
let devkitFilterLift = true;
let devkitSaveXlsx = false;
let devkitLastResult: {
outputPath: string;
groupsUsed: number;
meanValue: number;
threshold: number;
rowsTotal: number;
rowsKept: number;
} | null = null;
let devkitStatusTimer: number | null = null;
$: uiCopy = copyByLocale[locale];
$: configLinks = buildConfigLinks(locale, activeConfigLinkId, isConfigPanelOpen, isPrecisionTestOpen);
@@ -1012,7 +1034,7 @@
settings: "Setup"
};
return [
const links: HudConfigLink[] = [
{
id: "stream-on",
label: labels.streamOn,
@@ -1044,6 +1066,17 @@
active: isSettingsOpen
}
];
if (devkitEnabled) {
links.push({
id: "devkit",
label: "DevKit",
tone: "cyan",
active: isDevKitConfigOpen
});
}
return links;
}
async function ensureDefaultWindowSize(): Promise<void> {
@@ -1097,6 +1130,71 @@
const context = canvas.getContext("webgl2");
}
async function checkForAppUpdate(): Promise<void> {
if (!isTauriRuntime()) {
return;
}
const updateDismissKey = "je-skin-update-dismissed-version";
try {
const update = await check();
if (!update) {
return;
}
if (window.sessionStorage.getItem(updateDismissKey) === update.version) {
return;
}
const message =
locale === "zh-CN"
? `发现新版本 ${update.version},是否现在下载并安装?`
: `Version ${update.version} is available. Download and install now?`;
pendingUpdate = update;
updateNoticeVisible = true;
updateInstallBusy = false;
connectionNotice = message;
connectionNoticeTone = "info";
} catch (error) {
console.error("App update check failed:", error);
}
}
async function handleUpdateConfirm(): Promise<void> {
if (!pendingUpdate || updateInstallBusy) {
return;
}
updateInstallBusy = true;
connectionNotice = locale === "zh-CN" ? "正在下载并安装更新..." : "Downloading and installing update...";
connectionNoticeTone = "info";
try {
await pendingUpdate.downloadAndInstall();
await relaunch();
} catch (error) {
updateInstallBusy = false;
updateNoticeVisible = false;
pendingUpdate = null;
connectionNotice = locale === "zh-CN" ? "更新安装失败,请稍后重试。" : "Update failed. Please try again later.";
connectionNoticeTone = "warn";
console.error("App update install failed:", error);
}
}
function handleUpdateCancel(): void {
if (pendingUpdate) {
window.sessionStorage.setItem("je-skin-update-dismissed-version", pendingUpdate.version);
}
pendingUpdate = null;
updateNoticeVisible = false;
updateInstallBusy = false;
connectionNotice = "";
}
function handleLocaleChange(event: CustomEvent<LocaleCode>): void {
locale = event.detail;
}
@@ -1318,6 +1416,57 @@
? await invoke<SerialExportResult>("serial_export_csv_to_path", { filePath })
: await invoke<SerialExportResult>("serial_export_csv");
if (devkitEnabled && devkitRunning && devkitFilterLift) {
try {
const processResult = await invoke<{
ok: boolean;
outputPath: string;
groupsUsed: number;
meanValue: number;
threshold: number;
rowsTotal: number;
rowsKept: number;
message: string;
}>("devkit_process_export", {
csvPath: result.path,
saveAsXlsx: devkitSaveXlsx
});
if (processResult.ok) {
devkitLastResult = {
outputPath: processResult.outputPath,
groupsUsed: processResult.groupsUsed,
meanValue: processResult.meanValue,
threshold: processResult.threshold,
rowsTotal: processResult.rowsTotal,
rowsKept: processResult.rowsKept
};
connectionNotice =
locale === "zh-CN"
? `CSV 已导出并完成 DevKit 处理(${result.frameCount} 帧):${processResult.outputPath}`
: `CSV exported and processed by DevKit (${result.frameCount} frames): ${processResult.outputPath}`;
connectionNoticeTone = "ok";
return true;
}
connectionNotice =
locale === "zh-CN"
? `CSV 已导出,但 DevKit 处理失败:${processResult.message}`
: `CSV exported, but DevKit processing failed: ${processResult.message}`;
connectionNoticeTone = "warn";
return true;
} catch (error) {
connectionNotice =
locale === "zh-CN"
? "CSV 已导出,但 DevKit 后处理调用失败。"
: "CSV exported, but DevKit post-processing failed.";
connectionNoticeTone = "warn";
console.error("DevKit export post-process failed:", error);
return true;
}
}
connectionNotice =
locale === "zh-CN"
? `CSV 导出成功(${result.frameCount} 帧):${result.path}`
@@ -1477,17 +1626,27 @@
if (event.detail === "precision-test") {
isPrecisionTestOpen = !isPrecisionTestOpen;
isConfigPanelOpen = false;
isDevKitConfigOpen = false;
return;
}
if (event.detail === "settings") {
isPrecisionTestOpen = false;
isConfigPanelOpen = !isConfigPanelOpen;
isDevKitConfigOpen = false;
return;
}
if (event.detail === "devkit") {
isPrecisionTestOpen = false;
isConfigPanelOpen = false;
isDevKitConfigOpen = !isDevKitConfigOpen;
return;
}
isPrecisionTestOpen = false;
isConfigPanelOpen = false;
isDevKitConfigOpen = false;
activeConfigLinkId = event.detail;
console.info("[hud] config link clicked:", event.detail);
}
@@ -1511,6 +1670,55 @@
}
}
// ── DevKit Functions ────────────────────────────────────────────
async function pollDevKitStatus(): Promise<void> {
if (!isTauriRuntime()) return;
try {
const status = await invoke<{
enabled: boolean;
running: boolean;
port: number;
framesSent: number;
config: { filterLiftEnabled: boolean; saveAsXlsx: boolean };
}>("devkit_status");
devkitEnabled = status.enabled;
devkitRunning = status.running;
devkitPort = status.port;
devkitFramesSent = status.framesSent;
devkitFilterLift = status.config.filterLiftEnabled;
devkitSaveXlsx = status.config.saveAsXlsx;
} catch {
devkitEnabled = false;
devkitRunning = false;
isDevKitConfigOpen = false;
}
}
async function handleDevKitToggleFilterLift(): Promise<void> {
if (!isTauriRuntime()) return;
try {
const newConfig = { filterLiftEnabled: !devkitFilterLift, saveAsXlsx: devkitSaveXlsx };
const result = await invoke<{ filterLiftEnabled: boolean; saveAsXlsx: boolean }>("devkit_set_config", { config: newConfig });
devkitFilterLift = result.filterLiftEnabled;
devkitSaveXlsx = result.saveAsXlsx;
} catch (error) {
console.error("DevKit config update failed:", error);
}
}
async function handleDevKitToggleXlsx(): Promise<void> {
if (!isTauriRuntime()) return;
try {
const newConfig = { filterLiftEnabled: devkitFilterLift, saveAsXlsx: !devkitSaveXlsx };
const result = await invoke<{ filterLiftEnabled: boolean; saveAsXlsx: boolean }>("devkit_set_config", { config: newConfig });
devkitFilterLift = result.filterLiftEnabled;
devkitSaveXlsx = result.saveAsXlsx;
} catch (error) {
console.error("DevKit config update failed:", error);
}
}
function handleMatrixDisplayToggle(event: CustomEvent<boolean>): void {
matrixDisplayMode = event.detail ? "dots" : "numeric";
}
@@ -1526,6 +1734,9 @@
if (isTauriRuntime()) {
void refreshSerialPorts();
void checkForAppUpdate();
void pollDevKitStatus();
devkitStatusTimer = window.setInterval(() => void pollDevKitStatus(), 3000);
void startTauriHudStream(applyPacket)
.then((unlisten) => {
if (disposed) {
@@ -1547,6 +1758,10 @@
pauseReplayPlayback();
stopMockFeed?.();
unlistenHudStream?.();
if (devkitStatusTimer != null) {
window.clearInterval(devkitStatusTimer);
devkitStatusTimer = null;
}
};
});
</script>
@@ -1591,6 +1806,10 @@
importActionLabel={uiCopy.importActionLabel}
{connectionNotice}
{connectionNoticeTone}
noticeConfirmLabel={locale === "zh-CN" ? "确定" : "Confirm"}
noticeCancelLabel={locale === "zh-CN" ? "取消" : "Cancel"}
noticeShowActions={updateNoticeVisible}
noticeActionBusy={updateInstallBusy}
{configLinks}
{isRefreshingPorts}
{isExporting}
@@ -1606,7 +1825,12 @@
on:serialconnect={handleSerialConnect}
on:serialexport={handleSerialExportRequest}
on:csvimport={handleReplayImportRequest}
on:noticeclear={() => (connectionNotice = "")}
on:noticeclear={() => {
connectionNotice = "";
updateNoticeVisible = false;
}}
on:noticeconfirm={handleUpdateConfirm}
on:noticecancel={handleUpdateCancel}
/>
<CenterStage
@@ -1693,6 +1917,25 @@
on:navigate={handleFileExplorerNavigate}
on:confirm={handleFileExplorerConfirm}
/>
{#if isDevKitConfigOpen && devkitEnabled}
<div class="devkit-overlay" role="dialog" aria-label="DevKit Config">
<div class="devkit-float">
<DevKitConfigPanel
running={devkitRunning}
port={devkitPort}
framesSent={devkitFramesSent}
filterLiftEnabled={devkitFilterLift}
saveAsXlsx={devkitSaveXlsx}
locale={locale}
lastProcessResult={devkitLastResult}
on:close={() => (isDevKitConfigOpen = false)}
on:togglefilterlift={handleDevKitToggleFilterLift}
on:togglexlsx={handleDevKitToggleXlsx}
/>
</div>
</div>
{/if}
</main>
<style>
@@ -1871,4 +2114,20 @@
grid-template-columns: 1fr;
}
}
.devkit-overlay {
position: fixed;
inset: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
background: rgb(0 0 0 / 0.5);
backdrop-filter: blur(6px);
}
.devkit-float {
position: relative;
z-index: 1;
}
</style>