702 lines
20 KiB
TypeScript
702 lines
20 KiB
TypeScript
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
|
|
type RecordingState =
|
|
| "WaitingForGame"
|
|
| "Buffering"
|
|
| "RecordingSession"
|
|
| "Clipping"
|
|
| "Processing"
|
|
| "StorageLow";
|
|
|
|
type ClipSource = "Auto Event" | "Manual Hotkey" | "Bookmark" | "Imported";
|
|
type UploadState = "Local only" | "Uploaded" | "Failed" | "Queued";
|
|
|
|
type Clip = {
|
|
id: string;
|
|
title: string;
|
|
game: string;
|
|
event: string;
|
|
source: ClipSource;
|
|
duration: string;
|
|
createdAt: string;
|
|
uploadState: UploadState;
|
|
path: string;
|
|
thumbnailPath: string | null;
|
|
videoUrl: string | null;
|
|
thumbnailUrl: string | null;
|
|
tags: string[];
|
|
colorClass: string;
|
|
};
|
|
|
|
type AutoEvent = {
|
|
id: string;
|
|
game: string;
|
|
event: string;
|
|
enabled: boolean;
|
|
};
|
|
|
|
type DesktopStatus = {
|
|
recording_state: RecordingState;
|
|
detected_game: string | null;
|
|
replay_buffer_seconds: number;
|
|
mic_enabled: boolean;
|
|
upload_enabled: boolean;
|
|
session_recording: boolean;
|
|
capture_active: boolean;
|
|
capture_path: string | null;
|
|
clip_count: number;
|
|
library_root: string;
|
|
ffmpeg_available: boolean;
|
|
ffmpeg_path: string | null;
|
|
};
|
|
|
|
type ClipDto = {
|
|
id: string;
|
|
title: string;
|
|
game: string;
|
|
event: string;
|
|
source: ClipSource;
|
|
duration: string;
|
|
created_at: string;
|
|
upload_state: UploadState;
|
|
path: string;
|
|
thumbnail_path: string | null;
|
|
tags: string[];
|
|
color_class: string;
|
|
};
|
|
|
|
type AppState = {
|
|
activeView: "Library" | "Recording" | "Auto Clip" | "Uploads" | "Settings";
|
|
recordingState: RecordingState;
|
|
detectedGame: string;
|
|
replayBufferSeconds: number;
|
|
sessionRecording: boolean;
|
|
captureActive: boolean;
|
|
capturePath: string | null;
|
|
ffmpegAvailable: boolean;
|
|
ffmpegPath: string | null;
|
|
micEnabled: boolean;
|
|
autoUpload: boolean;
|
|
selectedClipId: string;
|
|
clips: Clip[];
|
|
autoEvents: AutoEvent[];
|
|
};
|
|
|
|
type TauriGlobal = {
|
|
core?: {
|
|
invoke?: <T>(command: string, args?: Record<string, unknown>) => Promise<T>;
|
|
};
|
|
};
|
|
|
|
declare global {
|
|
interface Window {
|
|
__TAURI__?: TauriGlobal;
|
|
__TAURI_INTERNALS__?: unknown;
|
|
}
|
|
}
|
|
|
|
let tauriInvoke: (<T>(command: string, args?: Record<string, unknown>) => Promise<T>) | null = null;
|
|
|
|
const state: AppState = {
|
|
activeView: "Library",
|
|
recordingState: "Buffering",
|
|
detectedGame: "Counter-Strike 2",
|
|
replayBufferSeconds: 60,
|
|
sessionRecording: false,
|
|
captureActive: false,
|
|
capturePath: null,
|
|
ffmpegAvailable: false,
|
|
ffmpegPath: null,
|
|
micEnabled: false,
|
|
autoUpload: false,
|
|
selectedClipId: "clip-1",
|
|
clips: [
|
|
{
|
|
id: "clip-1",
|
|
title: "Dust II clutch",
|
|
game: "Counter-Strike 2",
|
|
event: "Kill",
|
|
source: "Auto Event",
|
|
duration: "0:18",
|
|
createdAt: "Today 12:08",
|
|
uploadState: "Local only",
|
|
path: "",
|
|
thumbnailPath: null,
|
|
videoUrl: null,
|
|
thumbnailUrl: null,
|
|
tags: ["clutch", "kill"],
|
|
colorClass: "kill",
|
|
},
|
|
{
|
|
id: "clip-2",
|
|
title: "Baron steal",
|
|
game: "League of Legends",
|
|
event: "Objective",
|
|
source: "Auto Event",
|
|
duration: "0:22",
|
|
createdAt: "Today 11:44",
|
|
uploadState: "Queued",
|
|
path: "",
|
|
thumbnailPath: null,
|
|
videoUrl: null,
|
|
thumbnailUrl: null,
|
|
tags: ["objective"],
|
|
colorClass: "objective",
|
|
},
|
|
{
|
|
id: "clip-3",
|
|
title: "Manual save",
|
|
game: "Dota 2",
|
|
event: "Manual",
|
|
source: "Manual Hotkey",
|
|
duration: "1:00",
|
|
createdAt: "Yesterday 22:15",
|
|
uploadState: "Uploaded",
|
|
path: "",
|
|
thumbnailPath: null,
|
|
videoUrl: null,
|
|
thumbnailUrl: null,
|
|
tags: ["teamfight"],
|
|
colorClass: "manual",
|
|
},
|
|
],
|
|
autoEvents: [
|
|
{ id: "cs2-kill", game: "Counter-Strike 2", event: "Kill", enabled: true },
|
|
{ id: "cs2-round", game: "Counter-Strike 2", event: "Round win", enabled: true },
|
|
{ id: "lol-kill", game: "League of Legends", event: "Champion kill", enabled: true },
|
|
{ id: "lol-objective", game: "League of Legends", event: "Objective", enabled: true },
|
|
{ id: "dota-objective", game: "Dota 2", event: "Roshan/objective", enabled: false },
|
|
],
|
|
};
|
|
|
|
const root = document.querySelector<HTMLDivElement>("#app");
|
|
|
|
if (!root) {
|
|
throw new Error("Missing #app root");
|
|
}
|
|
|
|
const appRoot = root;
|
|
|
|
function render() {
|
|
const selectedClip = state.clips.find((clip) => clip.id === state.selectedClipId) ?? state.clips[0];
|
|
appRoot.innerHTML = `
|
|
<main class="app-shell">
|
|
<aside class="sidebar" aria-label="Primary">
|
|
<div class="brand">
|
|
<span class="brand-mark">CF</span>
|
|
<span>ClipForge</span>
|
|
</div>
|
|
<nav>${["Library", "Recording", "Auto Clip", "Uploads", "Settings"]
|
|
.map(
|
|
(view) => `
|
|
<button class="nav-item ${state.activeView === view ? "active" : ""}" data-view="${view}">
|
|
${view}
|
|
</button>
|
|
`,
|
|
)
|
|
.join("")}</nav>
|
|
</aside>
|
|
|
|
<section class="workspace">
|
|
${renderRecordingBar()}
|
|
${renderActiveView(selectedClip)}
|
|
</section>
|
|
</main>
|
|
`;
|
|
bindEvents();
|
|
}
|
|
|
|
function renderRecordingBar() {
|
|
const statusText = state.captureActive
|
|
? "Recording to disk"
|
|
: state.sessionRecording
|
|
? "Recording session"
|
|
: `${state.recordingState} ${state.replayBufferSeconds}s`;
|
|
return `
|
|
<header class="recording-bar">
|
|
<div>
|
|
<p class="eyebrow">Detected game</p>
|
|
<h1>${state.detectedGame}</h1>
|
|
</div>
|
|
<div class="meter-group" aria-label="Audio levels">
|
|
<span class="meter"><i style="width: 72%"></i></span>
|
|
<span class="meter"><i style="width: ${state.micEnabled ? 34 : 0}%"></i></span>
|
|
</div>
|
|
<div class="status-pill">${statusText}</div>
|
|
<button class="icon-button" data-action="clip">Clip</button>
|
|
<button class="record-button" data-action="toggle-record">${state.captureActive || state.sessionRecording ? "Stop" : "Record"}</button>
|
|
</header>
|
|
`;
|
|
}
|
|
|
|
function renderActiveView(selectedClip: Clip) {
|
|
switch (state.activeView) {
|
|
case "Recording":
|
|
return renderRecordingView();
|
|
case "Auto Clip":
|
|
return renderAutoClipView();
|
|
case "Uploads":
|
|
return renderUploadsView();
|
|
case "Settings":
|
|
return renderSettingsView();
|
|
case "Library":
|
|
default:
|
|
return renderLibraryView(selectedClip);
|
|
}
|
|
}
|
|
|
|
function renderLibraryView(selectedClip: Clip | undefined) {
|
|
return `
|
|
<section class="content-grid">
|
|
<section class="library-panel">
|
|
<div class="section-heading">
|
|
<div>
|
|
<p class="eyebrow">Local library</p>
|
|
<h2>Recent Clips</h2>
|
|
</div>
|
|
<div class="segmented">
|
|
<button class="selected">Grid</button>
|
|
<button>List</button>
|
|
</div>
|
|
</div>
|
|
<div class="filters">
|
|
<button class="selected">All</button>
|
|
<button>Kills</button>
|
|
<button>Wins</button>
|
|
<button>Uploaded</button>
|
|
</div>
|
|
<div class="clip-grid">
|
|
${state.clips.length > 0 ? state.clips.map(renderClipCard).join("") : `<div class="empty-state">No clips saved yet</div>`}
|
|
</div>
|
|
</section>
|
|
${renderClipDetails(selectedClip)}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function clipFromDto(dto: ClipDto): Clip {
|
|
return {
|
|
id: dto.id,
|
|
title: dto.title,
|
|
game: dto.game,
|
|
event: dto.event,
|
|
source: dto.source,
|
|
duration: dto.duration,
|
|
createdAt: dto.created_at,
|
|
uploadState: dto.upload_state,
|
|
path: dto.path,
|
|
thumbnailPath: dto.thumbnail_path,
|
|
videoUrl: dto.path ? convertFileSrc(dto.path) : null,
|
|
thumbnailUrl: dto.thumbnail_path ? convertFileSrc(dto.thumbnail_path) : null,
|
|
tags: dto.tags,
|
|
colorClass: dto.color_class,
|
|
};
|
|
}
|
|
|
|
function renderClipCard(clip: Clip) {
|
|
return `
|
|
<article class="clip-card ${state.selectedClipId === clip.id ? "selected" : ""}" data-clip-id="${clip.id}">
|
|
<div class="thumb ${clip.colorClass}">
|
|
${clip.thumbnailUrl ? `<img src="${clip.thumbnailUrl}" alt="" />` : clip.event}
|
|
</div>
|
|
<h3>${clip.title}</h3>
|
|
<p>${clip.game} · ${clip.source} · ${clip.duration}</p>
|
|
</article>
|
|
`;
|
|
}
|
|
|
|
function renderClipDetails(clip: Clip | undefined) {
|
|
if (!clip) {
|
|
return `
|
|
<aside class="detail-panel">
|
|
<div class="preview"><span>Preview</span></div>
|
|
<h2>No clip selected</h2>
|
|
<p class="muted">Start recording or press Clip to create the first local clip.</p>
|
|
</aside>
|
|
`;
|
|
}
|
|
|
|
return `
|
|
<aside class="detail-panel">
|
|
<div class="preview">
|
|
${
|
|
clip.videoUrl
|
|
? `<video controls preload="metadata" src="${clip.videoUrl}" poster="${clip.thumbnailUrl ?? ""}"></video>`
|
|
: `<span>Preview</span>`
|
|
}
|
|
</div>
|
|
<h2>${clip.title}</h2>
|
|
<p class="muted">${clip.game} · ${clip.event} · ${clip.createdAt} · ${clip.uploadState}</p>
|
|
<div class="tag-row">${clip.tags.map((tag) => `<span>${tag}</span>`).join("")}</div>
|
|
<p class="muted file-path">${clip.path || "Demo clip; no local file yet"}</p>
|
|
<div class="trim-row">
|
|
<label>Start <input value="00:00" data-action="trim-start" /></label>
|
|
<label>End <input value="${clip.duration}" data-action="trim-end" /></label>
|
|
</div>
|
|
<div class="actions">
|
|
<button data-action="process">Trim</button>
|
|
<button data-action="reveal">Reveal</button>
|
|
<button data-action="upload">Upload</button>
|
|
<button data-action="delete">Delete</button>
|
|
</div>
|
|
<section class="auto-box">
|
|
<h3>Auto clip policy</h3>
|
|
<p>10s pre-roll · 8s post-roll · 12s merge window</p>
|
|
</section>
|
|
</aside>
|
|
`;
|
|
}
|
|
|
|
function renderRecordingView() {
|
|
return `
|
|
<section class="settings-grid">
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Replay buffer</p>
|
|
<h2>${state.replayBufferSeconds} seconds</h2>
|
|
<input type="range" min="15" max="600" step="15" value="${state.replayBufferSeconds}" data-action="buffer-length" />
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Capture</p>
|
|
<h2>720p30 Performance</h2>
|
|
<p class="muted">Lightweight desktop capture uses bundled FFmpeg when system FFmpeg is missing.</p>
|
|
<p class="muted">${state.ffmpegAvailable ? "FFmpeg ready" : "FFmpeg missing"}${state.ffmpegPath ? ` · ${state.ffmpegPath}` : ""}</p>
|
|
<p class="muted">${state.capturePath ? `Writing ${state.capturePath}` : "No active capture file"}</p>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Audio</p>
|
|
<h2>System audio on</h2>
|
|
<label class="toggle"><input type="checkbox" ${state.micEnabled ? "checked" : ""} data-action="toggle-mic" /> Mic capture</label>
|
|
</article>
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderAutoClipView() {
|
|
return `
|
|
<section class="table-panel">
|
|
<div class="section-heading">
|
|
<div>
|
|
<p class="eyebrow">Game events</p>
|
|
<h2>Auto Clip Rules</h2>
|
|
</div>
|
|
<div class="status-pill">Local APIs only</div>
|
|
</div>
|
|
<div class="event-list">
|
|
${state.autoEvents
|
|
.map(
|
|
(event) => `
|
|
<label class="event-row">
|
|
<span><strong>${event.game}</strong><small>${event.event}</small></span>
|
|
<input type="checkbox" ${event.enabled ? "checked" : ""} data-event-id="${event.id}" />
|
|
</label>
|
|
`,
|
|
)
|
|
.join("")}
|
|
</div>
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderUploadsView() {
|
|
return `
|
|
<section class="settings-grid">
|
|
${["Catbox", "Litterbox", "Custom HTTP", "Lustful"].map((provider) => `
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Provider</p>
|
|
<h2>${provider}</h2>
|
|
<p class="muted">${provider === "Lustful" ? "Stubbed until API details are confirmed." : "Optional; local clips remain available if upload fails."}</p>
|
|
<button>${provider === "Custom HTTP" ? "Configure" : "Enable"}</button>
|
|
</article>
|
|
`).join("")}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderSettingsView() {
|
|
return `
|
|
<section class="settings-grid">
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Privacy</p>
|
|
<h2>Local-first</h2>
|
|
<label class="toggle"><input type="checkbox" ${state.autoUpload ? "checked" : ""} data-action="toggle-auto-upload" /> Auto-upload after clipping</label>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Storage</p>
|
|
<h2>50 GB cap</h2>
|
|
<p class="muted">Old temporary buffer segments are removed automatically; saved clips are kept.</p>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Hotkeys</p>
|
|
<h2>F8 saves last 60s</h2>
|
|
<p class="muted">Shift+F8 saves 30s · Alt+F7 toggles session recording.</p>
|
|
</article>
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function bindEvents() {
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-view]").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
state.activeView = button.dataset.view as AppState["activeView"];
|
|
render();
|
|
});
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLElement>("[data-clip-id]").forEach((card) => {
|
|
card.addEventListener("click", () => {
|
|
state.selectedClipId = card.dataset.clipId ?? state.selectedClipId;
|
|
render();
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='clip']")?.addEventListener("click", () => {
|
|
void saveClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='toggle-record']")?.addEventListener("click", () => {
|
|
void toggleRecording();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='process']")?.addEventListener("click", () => {
|
|
void trimSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='reveal']")?.addEventListener("click", () => {
|
|
void revealSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='upload']")?.addEventListener("click", () => {
|
|
void uploadSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='delete']")?.addEventListener("click", () => {
|
|
void deleteSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='buffer-length']")?.addEventListener("input", (event) => {
|
|
state.replayBufferSeconds = Number((event.target as HTMLInputElement).value);
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-mic']")?.addEventListener("change", (event) => {
|
|
state.micEnabled = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-auto-upload']")?.addEventListener("change", (event) => {
|
|
state.autoUpload = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLInputElement>("[data-event-id]").forEach((input) => {
|
|
input.addEventListener("change", () => {
|
|
const eventRule = state.autoEvents.find((event) => event.id === input.dataset.eventId);
|
|
if (eventRule) {
|
|
eventRule.enabled = input.checked;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async function saveClip() {
|
|
state.recordingState = "Clipping";
|
|
render();
|
|
|
|
if (tauriInvoke) {
|
|
try {
|
|
const dto = await tauriInvoke<ClipDto>("save_manual_clip", { seconds: state.replayBufferSeconds });
|
|
const clip = clipFromDto(dto);
|
|
state.clips.unshift(clip);
|
|
state.selectedClipId = clip.id;
|
|
state.activeView = "Library";
|
|
state.recordingState = "Processing";
|
|
await refreshClips();
|
|
render();
|
|
return;
|
|
} catch (error) {
|
|
console.error("Could not save desktop clip", error);
|
|
}
|
|
}
|
|
|
|
state.clips.unshift({
|
|
id: `manual-${Date.now()}`,
|
|
title: "Manual clip",
|
|
game: state.detectedGame,
|
|
event: "Manual",
|
|
source: "Manual Hotkey",
|
|
duration: "1:00",
|
|
createdAt: "Just now",
|
|
uploadState: "Local only",
|
|
path: "",
|
|
thumbnailPath: null,
|
|
videoUrl: null,
|
|
thumbnailUrl: null,
|
|
tags: ["manual"],
|
|
colorClass: "manual",
|
|
});
|
|
state.selectedClipId = state.clips[0].id;
|
|
state.activeView = "Library";
|
|
render();
|
|
}
|
|
|
|
async function toggleRecording() {
|
|
if (tauriInvoke) {
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>(state.captureActive ? "stop_capture" : "start_capture");
|
|
applyDesktopStatus(status);
|
|
await refreshClips();
|
|
render();
|
|
return;
|
|
} catch (error) {
|
|
console.error("Could not toggle desktop recording", error);
|
|
}
|
|
}
|
|
|
|
state.sessionRecording = !state.sessionRecording;
|
|
state.recordingState = state.sessionRecording ? "RecordingSession" : "Buffering";
|
|
render();
|
|
}
|
|
|
|
function applyDesktopStatus(status: DesktopStatus) {
|
|
state.recordingState = status.recording_state;
|
|
state.detectedGame = status.detected_game ?? "Waiting for game";
|
|
state.replayBufferSeconds = status.replay_buffer_seconds;
|
|
state.micEnabled = status.mic_enabled;
|
|
state.autoUpload = status.upload_enabled;
|
|
state.sessionRecording = status.session_recording;
|
|
state.captureActive = status.capture_active;
|
|
state.capturePath = status.capture_path;
|
|
state.ffmpegAvailable = status.ffmpeg_available;
|
|
state.ffmpegPath = status.ffmpeg_path;
|
|
}
|
|
|
|
async function trimSelectedClip() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
const clip = state.clips.find((candidate) => candidate.id === state.selectedClipId);
|
|
if (!clip) {
|
|
return;
|
|
}
|
|
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
const startSeconds = parseTimestamp(startInput?.value ?? "0");
|
|
const endSeconds = parseTimestamp(endInput?.value ?? clip.duration);
|
|
|
|
try {
|
|
const dto = await tauriInvoke<ClipDto>("trim_clip", {
|
|
clipId: clip.id,
|
|
startSeconds,
|
|
endSeconds,
|
|
});
|
|
const trimmed = clipFromDto(dto);
|
|
state.clips.unshift(trimmed);
|
|
state.selectedClipId = trimmed.id;
|
|
await refreshClips();
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not trim clip", error);
|
|
}
|
|
}
|
|
|
|
async function revealSelectedClip() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await tauriInvoke("reveal_clip", { clipId: state.selectedClipId });
|
|
} catch (error) {
|
|
console.error("Could not reveal clip", error);
|
|
}
|
|
}
|
|
|
|
async function uploadSelectedClip() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const dto = await tauriInvoke<ClipDto>("upload_clip", { clipId: state.selectedClipId });
|
|
const updated = clipFromDto(dto);
|
|
state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip));
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not queue upload", error);
|
|
}
|
|
}
|
|
|
|
async function deleteSelectedClip() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const clips = await tauriInvoke<ClipDto[]>("delete_clip", { clipId: state.selectedClipId });
|
|
state.clips = clips.map(clipFromDto);
|
|
state.selectedClipId = state.clips[0]?.id ?? "";
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not delete clip", error);
|
|
}
|
|
}
|
|
|
|
async function refreshClips() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
const clips = await tauriInvoke<ClipDto[]>("list_clips");
|
|
state.clips = clips.map(clipFromDto);
|
|
if (!state.clips.some((clip) => clip.id === state.selectedClipId)) {
|
|
state.selectedClipId = state.clips[0]?.id ?? "";
|
|
}
|
|
}
|
|
|
|
function parseTimestamp(value: string) {
|
|
const parts = value.trim().split(":").map(Number);
|
|
if (parts.some((part) => Number.isNaN(part))) {
|
|
return 0;
|
|
}
|
|
if (parts.length === 1) {
|
|
return parts[0];
|
|
}
|
|
if (parts.length === 2) {
|
|
return parts[0] * 60 + parts[1];
|
|
}
|
|
return parts[0] * 3600 + parts[1] * 60 + parts[2];
|
|
}
|
|
|
|
async function loadDesktopBridge() {
|
|
const hasTauri = "__TAURI_INTERNALS__" in window;
|
|
if (!hasTauri) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
tauriInvoke = window.__TAURI__?.core?.invoke ?? null;
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
const invoke = tauriInvoke;
|
|
const status = await invoke<DesktopStatus>("get_status");
|
|
applyDesktopStatus(status);
|
|
const clips = await invoke<ClipDto[]>("list_clips");
|
|
state.clips = clips.map(clipFromDto);
|
|
state.selectedClipId = state.clips[0]?.id ?? "";
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Tauri bridge unavailable", error);
|
|
}
|
|
}
|
|
|
|
render();
|
|
void loadDesktopBridge();
|
|
|
|
|
|
|
|
|
|
|