- Bump all versions to 0.1.1 and harden the auto-updater so a newer release is only offered when an installer asset actually exists. - Add clip-folder relocation, an auto-prune toggle, cached free-disk checks, and a 512 MB RAM clip buffer that reduces I/O for manual, auto, and hotkey clips. - Move clip-related UI actions off the main thread, add optimistic toggling, and switch to event-driven library and screenshot refresh. - Add a modal clip viewer with a fallback path/reveal UI when the local MP4 cannot load, plus a bitrate preset dropdown, an auto-clip rule grid, and per-game enable/disable controls. - Replace placeholder icons with an SVG source and regenerate raster assets from a 1024x1024 render of the new ClipForge logo. - Update the implementation-status notes for v0.1.1.
2615 lines
96 KiB
TypeScript
2615 lines
96 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" | "Screenshot";
|
|
type UploadState = "Local only" | "Uploaded" | "Failed" | "Queued";
|
|
type UploadProvider = "catbox" | "litterbox" | "custom_http" | "lustful";
|
|
|
|
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;
|
|
gameId: string;
|
|
eventType: string;
|
|
game: string;
|
|
event: string;
|
|
enabled: boolean;
|
|
};
|
|
|
|
type AutoClipEventDto = {
|
|
game_id: string;
|
|
event_type: string;
|
|
enabled: boolean;
|
|
};
|
|
|
|
type DesktopStatus = {
|
|
recording_state: RecordingState;
|
|
detected_game: string | null;
|
|
replay_buffer_seconds: number;
|
|
system_audio_enabled: boolean;
|
|
mic_enabled: boolean;
|
|
mic_device: string | null;
|
|
auto_record_enabled: boolean;
|
|
upload_enabled: boolean;
|
|
upload_provider: UploadProvider;
|
|
catbox_userhash: string | null;
|
|
litterbox_expiry_hours: number;
|
|
custom_upload_endpoint: string | null;
|
|
custom_upload_response_url_path: string;
|
|
custom_upload_headers: string[];
|
|
session_recording: boolean;
|
|
capture_active: boolean;
|
|
capture_backend: string | null;
|
|
capture_path: string | null;
|
|
clip_count: number;
|
|
library_root: string;
|
|
ffmpeg_available: boolean;
|
|
ffmpeg_path: string | null;
|
|
system_audio_available: boolean;
|
|
desktop_duplication_available: boolean;
|
|
auto_clip_enabled_events: AutoClipEventDto[];
|
|
auto_clip_disabled_games: string[];
|
|
hotkey_clip_last_60s: string;
|
|
hotkey_clip_last_30s: string;
|
|
hotkey_toggle_session_recording: string;
|
|
hotkey_screenshot: string;
|
|
free_disk_gb: number;
|
|
capture_fps: number;
|
|
capture_bitrate_kbps: number;
|
|
capture_resolution: string;
|
|
storage_limit_gb: number;
|
|
clip_directory: string;
|
|
storage_limit_exceeded: boolean;
|
|
auto_prune_old_clips: boolean;
|
|
excluded_window_titles: string[];
|
|
separate_audio_tracks: boolean;
|
|
game_quality_overrides: GameQualityOverrideDto[];
|
|
effective_quality_applied: boolean;
|
|
app_version: string;
|
|
onboarding_complete: boolean;
|
|
minimize_to_tray: boolean;
|
|
};
|
|
|
|
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 UploadHistoryEntry = {
|
|
id: number;
|
|
clip_id: string;
|
|
provider: string;
|
|
status: string;
|
|
url: string | null;
|
|
error: string | null;
|
|
attempted_at: string;
|
|
};
|
|
|
|
type GsiConfigDto = {
|
|
game_id: string;
|
|
path: string;
|
|
};
|
|
|
|
type AudioDeviceDto = {
|
|
name: string;
|
|
kind: "input" | "system_loopback";
|
|
};
|
|
|
|
type UpdateInfo = {
|
|
checked: boolean;
|
|
updateAvailable: boolean;
|
|
latestVersion: string;
|
|
installerFile: string;
|
|
downloadUrl: string;
|
|
message: string;
|
|
applying: boolean;
|
|
};
|
|
|
|
type GameQualityOverrideDto = {
|
|
game_id: string;
|
|
name: string;
|
|
width: number;
|
|
height: number;
|
|
fps: number;
|
|
bitrate_kbps: number;
|
|
};
|
|
|
|
type AppState = {
|
|
activeView: "Library" | "Recording" | "Auto Clip" | "Uploads" | "Settings";
|
|
recordingState: RecordingState;
|
|
detectedGame: string;
|
|
replayBufferSeconds: number;
|
|
systemAudioEnabled: boolean;
|
|
sessionRecording: boolean;
|
|
captureActive: boolean;
|
|
captureBackend: string | null;
|
|
capturePath: string | null;
|
|
ffmpegAvailable: boolean;
|
|
ffmpegPath: string | null;
|
|
systemAudioAvailable: boolean;
|
|
desktopDuplicationAvailable: boolean;
|
|
micEnabled: boolean;
|
|
micDevice: string;
|
|
audioDevices: AudioDeviceDto[];
|
|
autoRecordEnabled: boolean;
|
|
autoUpload: boolean;
|
|
uploadProvider: UploadProvider;
|
|
catboxUserhash: string;
|
|
litterboxExpiryHours: 1 | 12 | 24 | 72;
|
|
customUploadEndpoint: string;
|
|
customUploadResponsePath: string;
|
|
customUploadHeaders: string;
|
|
gsiConfigStatus: string;
|
|
libraryFilter: "all" | "kills" | "wins" | "uploaded" | "failed";
|
|
libraryQuery: string;
|
|
libraryViewMode: "grid" | "list";
|
|
notice: string;
|
|
selectedClipId: string;
|
|
clips: Clip[];
|
|
screenshots: string[];
|
|
uploadHistory: UploadHistoryEntry[];
|
|
autoEvents: AutoEvent[];
|
|
disabledGames: string[];
|
|
hotkeyClipLast60s: string;
|
|
hotkeyClipLast30s: string;
|
|
hotkeyToggleRecording: string;
|
|
hotkeyScreenshot: string;
|
|
freeDiskGb: number;
|
|
captureFps: number;
|
|
captureBitrateKbps: number;
|
|
captureResolution: string;
|
|
storageLimitGb: number;
|
|
clipDirectory: string;
|
|
storageLimitExceeded: boolean;
|
|
autoPruneOldClips: boolean;
|
|
excludedWindowTitles: string[];
|
|
excludedWindowText: string;
|
|
separateAudioTracks: boolean;
|
|
appVersion: string;
|
|
onboardingComplete: boolean;
|
|
minimizeToTray: boolean;
|
|
onboardingStep: number;
|
|
gameQualityOverrides: GameQualityOverrideDto[];
|
|
effectiveQualityApplied: boolean;
|
|
update: UpdateInfo;
|
|
modal: {
|
|
open: boolean;
|
|
kind: "clip" | "screenshot";
|
|
clipId: string;
|
|
screenshotPath: string;
|
|
videoFailed: boolean;
|
|
videoError: string;
|
|
};
|
|
};
|
|
|
|
type TauriGlobal = {
|
|
core?: {
|
|
invoke?: <T>(command: string, args?: Record<string, unknown>) => Promise<T>;
|
|
};
|
|
event?: {
|
|
listen?: <T>(eventName: string, handler: (event: { payload: T }) => void) => Promise<() => void>;
|
|
};
|
|
};
|
|
|
|
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: "WaitingForGame",
|
|
detectedGame: "Waiting for game",
|
|
replayBufferSeconds: 60,
|
|
systemAudioEnabled: true,
|
|
sessionRecording: false,
|
|
captureActive: false,
|
|
captureBackend: null,
|
|
capturePath: null,
|
|
ffmpegAvailable: false,
|
|
ffmpegPath: null,
|
|
systemAudioAvailable: false,
|
|
desktopDuplicationAvailable: false,
|
|
micEnabled: false,
|
|
micDevice: "",
|
|
audioDevices: [],
|
|
autoRecordEnabled: false,
|
|
autoUpload: false,
|
|
uploadProvider: "catbox",
|
|
catboxUserhash: "",
|
|
litterboxExpiryHours: 24,
|
|
customUploadEndpoint: "",
|
|
customUploadResponsePath: "url",
|
|
customUploadHeaders: "",
|
|
gsiConfigStatus: "",
|
|
libraryFilter: "all",
|
|
libraryQuery: "",
|
|
libraryViewMode: "grid",
|
|
notice: "",
|
|
selectedClipId: "",
|
|
clips: [],
|
|
screenshots: [],
|
|
uploadHistory: [],
|
|
autoEvents: [
|
|
{ id: "cs2-kill", gameId: "counter-strike-2", eventType: "kill", game: "Counter-Strike 2", event: "Kill", enabled: true },
|
|
{ id: "cs2-death", gameId: "counter-strike-2", eventType: "death", game: "Counter-Strike 2", event: "Death", enabled: true },
|
|
{ id: "cs2-round", gameId: "counter-strike-2", eventType: "round_win", game: "Counter-Strike 2", event: "Round win", enabled: true },
|
|
{ id: "cs2-multi", gameId: "counter-strike-2", eventType: "multi_kill", game: "Counter-Strike 2", event: "Multi-kill", enabled: true },
|
|
{ id: "cs2-bomb-planted", gameId: "counter-strike-2", eventType: "bomb_planted", game: "Counter-Strike 2", event: "Bomb planted", enabled: true },
|
|
{ id: "cs2-bomb-defused", gameId: "counter-strike-2", eventType: "bomb_defused", game: "Counter-Strike 2", event: "Bomb defused", enabled: true },
|
|
{ id: "cs2-bomb-exploded", gameId: "counter-strike-2", eventType: "bomb_exploded", game: "Counter-Strike 2", event: "Bomb exploded", enabled: true },
|
|
{ id: "cs2-mvp", gameId: "counter-strike-2", eventType: "mvp", game: "Counter-Strike 2", event: "MVP", enabled: true },
|
|
{ id: "lol-kill", gameId: "league-of-legends", eventType: "kill", game: "League of Legends", event: "Champion kill", enabled: true },
|
|
{ id: "lol-death", gameId: "league-of-legends", eventType: "death", game: "League of Legends", event: "Death", enabled: true },
|
|
{ id: "lol-assist", gameId: "league-of-legends", eventType: "assist", game: "League of Legends", event: "Assist", enabled: true },
|
|
{ id: "lol-objective", gameId: "league-of-legends", eventType: "objective", game: "League of Legends", event: "Objective", enabled: true },
|
|
{ id: "dota-kill", gameId: "dota-2", eventType: "kill", game: "Dota 2", event: "Kill", enabled: true },
|
|
{ id: "dota-death", gameId: "dota-2", eventType: "death", game: "Dota 2", event: "Death", enabled: true },
|
|
{ id: "dota-assist", gameId: "dota-2", eventType: "assist", game: "Dota 2", event: "Assist", enabled: true },
|
|
{ id: "dota-objective", gameId: "dota-2", eventType: "objective", game: "Dota 2", event: "Roshan/objective", enabled: true },
|
|
{ id: "dota-multi", gameId: "dota-2", eventType: "multi_kill", game: "Dota 2", event: "Multi-kill", enabled: true },
|
|
{ id: "dota-mvp", gameId: "dota-2", eventType: "mvp", game: "Dota 2", event: "MVP", enabled: true },
|
|
],
|
|
disabledGames: [],
|
|
hotkeyClipLast60s: "F8",
|
|
hotkeyClipLast30s: "Shift+F8",
|
|
hotkeyToggleRecording: "Alt+F7",
|
|
hotkeyScreenshot: "F9",
|
|
freeDiskGb: 0,
|
|
captureFps: 30,
|
|
captureBitrateKbps: 6000,
|
|
captureResolution: "1280x720",
|
|
storageLimitGb: 50,
|
|
clipDirectory: "",
|
|
storageLimitExceeded: false,
|
|
autoPruneOldClips: false,
|
|
excludedWindowTitles: [],
|
|
excludedWindowText: "",
|
|
separateAudioTracks: false,
|
|
appVersion: "0.1.1",
|
|
modal: {
|
|
open: false,
|
|
kind: "clip",
|
|
clipId: "",
|
|
screenshotPath: "",
|
|
videoFailed: false,
|
|
videoError: "",
|
|
},
|
|
onboardingComplete: true,
|
|
minimizeToTray: false,
|
|
onboardingStep: 0,
|
|
gameQualityOverrides: [],
|
|
effectiveQualityApplied: false,
|
|
update: {
|
|
checked: false,
|
|
updateAvailable: false,
|
|
latestVersion: "",
|
|
installerFile: "",
|
|
downloadUrl: "",
|
|
message: "Updates have not been checked yet.",
|
|
applying: false,
|
|
},
|
|
};
|
|
|
|
const root = document.querySelector<HTMLDivElement>("#app");
|
|
|
|
if (!root) {
|
|
throw new Error("Missing #app root");
|
|
}
|
|
|
|
const appRoot = root;
|
|
|
|
function render() {
|
|
if (!state.onboardingComplete) {
|
|
appRoot.innerHTML = renderOnboardingWizard();
|
|
bindEvents();
|
|
return;
|
|
}
|
|
|
|
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()}
|
|
${state.notice ? `<div class="notice" role="status">${escapeHtml(state.notice)}</div>` : ""}
|
|
${renderActiveView(selectedClip)}
|
|
</section>
|
|
</main>
|
|
${renderModal()}
|
|
`;
|
|
bindEvents();
|
|
}
|
|
|
|
function openClipModal(clipId: string) {
|
|
state.selectedClipId = clipId;
|
|
state.modal.open = true;
|
|
state.modal.kind = "clip";
|
|
state.modal.clipId = clipId;
|
|
state.modal.videoFailed = false;
|
|
state.modal.videoError = "";
|
|
render();
|
|
}
|
|
|
|
function openScreenshotModal(path: string) {
|
|
state.modal.open = true;
|
|
state.modal.kind = "screenshot";
|
|
state.modal.screenshotPath = path;
|
|
state.modal.videoFailed = false;
|
|
state.modal.videoError = "";
|
|
render();
|
|
}
|
|
|
|
function closeModal() {
|
|
state.modal.open = false;
|
|
render();
|
|
}
|
|
|
|
function renderModal() {
|
|
if (!state.modal.open) {
|
|
return "";
|
|
}
|
|
|
|
if (state.modal.kind === "screenshot") {
|
|
const path = state.modal.screenshotPath;
|
|
return `
|
|
<div class="modal-overlay" data-action="modal-backdrop">
|
|
<div class="modal" role="dialog" aria-modal="true" aria-label="Screenshot preview">
|
|
<div class="modal-header">
|
|
<h2>Screenshot preview</h2>
|
|
<button class="modal-close" data-action="modal-close" aria-label="Close">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<img src="${convertFileSrc(path)}" alt="Screenshot preview" />
|
|
<p class="muted file-path">${escapeHtml(path)}</p>
|
|
<div class="actions">
|
|
<button data-action="reveal-screenshot" data-screenshot-path="${escapeHtml(path)}">Open in Explorer</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
const clip = state.clips.find((candidate) => candidate.id === state.modal.clipId);
|
|
if (!clip) {
|
|
return "";
|
|
}
|
|
const durationDisplay = formatDuration(parseTimestamp(clip.duration));
|
|
const canPlay = Boolean(clip.videoUrl) && !state.modal.videoFailed;
|
|
return `
|
|
<div class="modal-overlay" data-action="modal-backdrop">
|
|
<div class="modal" role="dialog" aria-modal="true" aria-label="Clip preview">
|
|
<div class="modal-header">
|
|
<h2>${escapeHtml(clip.title)}</h2>
|
|
<button class="modal-close" data-action="modal-close" aria-label="Close">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
${
|
|
canPlay
|
|
? `<video controls preload="metadata" autoplay src="${clip.videoUrl}" poster="${clip.thumbnailUrl ?? ""}" id="modal-video"></video>`
|
|
: `
|
|
<div class="video-error">
|
|
<h3>Preview could not load</h3>
|
|
<p class="muted">${escapeHtml(state.modal.videoError || "No preview is available for this clip.")}</p>
|
|
<p class="muted file-path">${escapeHtml(clip.path || "No file path on record.")}</p>
|
|
<div class="actions">
|
|
<button data-action="modal-reveal">Reveal in Explorer</button>
|
|
<button data-action="modal-retry">Try loading again</button>
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|
|
<p class="muted">${escapeHtml(clip.game)} · ${escapeHtml(clip.event)} · ${escapeHtml(clip.createdAt)} · ${escapeHtml(clip.uploadState)}</p>
|
|
<label>Trim start <input value="00:00" data-action="modal-trim-start" /></label>
|
|
<label>Trim end <input value="${escapeHtml(durationDisplay)}" data-action="modal-trim-end" /></label>
|
|
<div class="actions">
|
|
<button data-action="modal-trim">Trim</button>
|
|
<button data-action="modal-upload">Upload</button>
|
|
<button data-action="modal-reveal">Reveal</button>
|
|
<button data-action="modal-delete">Delete</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function renderOnboardingWizard() {
|
|
const step = state.onboardingStep;
|
|
const steps = ["Privacy", "Capture source", "Storage", "Hotkeys"];
|
|
const stepBody = (() => {
|
|
switch (step) {
|
|
case 0:
|
|
return `
|
|
<h2>What should ClipForge record?</h2>
|
|
<p class="muted">You can change any of these later in Settings. Audio is mixed into
|
|
your clips; enable separate tracks to keep system and mic audio in distinct tracks.</p>
|
|
<div class="wizard-options">
|
|
<label class="toggle"><input type="checkbox" ${state.systemAudioEnabled ? "checked" : ""} data-action="onboard-system-audio" /> Capture system audio</label>
|
|
<label class="toggle"><input type="checkbox" ${state.micEnabled ? "checked" : ""} data-action="onboard-mic" /> Capture microphone</label>
|
|
<label class="toggle"><input type="checkbox" ${state.separateAudioTracks ? "checked" : ""} data-action="onboard-separate-tracks" /> Keep system and mic in separate tracks</label>
|
|
</div>`;
|
|
case 1:
|
|
return `
|
|
<h2>When should recording start?</h2>
|
|
<p class="muted">Auto-clipping keeps a rolling buffer and saves highlights when
|
|
supported games detect events. Continuous recording saves the full session.</p>
|
|
<div class="wizard-options">
|
|
<label class="toggle"><input type="checkbox" ${state.autoRecordEnabled ? "checked" : ""} data-action="onboard-auto-record" /> Start recording automatically when a game is detected</label>
|
|
</div>
|
|
<div class="field-row">
|
|
<label>Replay buffer
|
|
<select data-action="onboard-buffer">
|
|
${[30, 60, 120, 240, 300]
|
|
.map(
|
|
(seconds) =>
|
|
`<option value="${seconds}" ${state.replayBufferSeconds === seconds ? "selected" : ""}>${seconds < 60 ? `${seconds}s` : `${seconds / 60} min`}</option>`,
|
|
)
|
|
.join("")}
|
|
</select>
|
|
</label>
|
|
</div>`;
|
|
case 2:
|
|
return `
|
|
<h2>How much disk space is ClipForge allowed to use?</h2>
|
|
<p class="muted">The rolling buffer shrinks automatically to fit this limit.
|
|
Finished clips are saved to your library and are never pruned.</p>
|
|
<div class="field-row">
|
|
<label>Storage limit (GB)
|
|
<input type="number" min="5" max="5000" step="5" value="${state.storageLimitGb}" data-action="onboard-storage" />
|
|
</label>
|
|
</div>`;
|
|
case 3:
|
|
return `
|
|
<h2>You're almost set</h2>
|
|
<p class="muted">These hotkeys are active while the app is running. You can
|
|
customize them anytime in Settings.</p>
|
|
<ul class="hotkey-list">
|
|
<li><span>Save last ${state.replayBufferSeconds}s clip</span><kbd>${escapeHtml(state.hotkeyClipLast60s)}</kbd></li>
|
|
<li><span>Save last 30s clip</span><kbd>${escapeHtml(state.hotkeyClipLast30s)}</kbd></li>
|
|
<li><span>Toggle recording</span><kbd>${escapeHtml(state.hotkeyToggleRecording)}</kbd></li>
|
|
<li><span>Take screenshot</span><kbd>${escapeHtml(state.hotkeyScreenshot)}</kbd></li>
|
|
</ul>`;
|
|
default:
|
|
return "";
|
|
}
|
|
})();
|
|
|
|
return `
|
|
<main class="app-shell onboarding-shell">
|
|
<section class="workspace onboarding-workspace">
|
|
<div class="wizard-card">
|
|
<div class="wizard-header">
|
|
<span class="brand-mark">CF</span>
|
|
<div>
|
|
<h1>Welcome to ClipForge</h1>
|
|
<p class="muted">Set up capture in a few quick steps.</p>
|
|
</div>
|
|
</div>
|
|
<ol class="wizard-steps">
|
|
${steps
|
|
.map(
|
|
(name, index) => `
|
|
<li class="${index === step ? "active" : ""} ${index < step ? "done" : ""}">${name}</li>
|
|
`,
|
|
)
|
|
.join("")}
|
|
</ol>
|
|
<div class="wizard-body">${stepBody}</div>
|
|
<div class="wizard-actions">
|
|
${step === 0 ? `<button class="ghost-button" data-action="onboarding-skip">Skip setup</button>` : `<button class="ghost-button" data-action="onboarding-back">Back</button>`}
|
|
${step < steps.length - 1 ? `<button class="primary-button" data-action="onboarding-next">Continue</button>` : `<button class="primary-button" data-action="onboarding-finish">Get clipping</button>`}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
`;
|
|
}
|
|
|
|
function renderRecordingBar() {
|
|
const lowDisk = state.freeDiskGb < 2 && state.freeDiskGb > 0;
|
|
const statusText = lowDisk
|
|
? `Low disk (${state.freeDiskGb.toFixed(1)} GB free)`
|
|
: 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 ${lowDisk ? "warn" : ""}">${statusText}</div>
|
|
${lowDisk ? "" : `<button class="icon-button" data-action="clip">Clip</button>`}
|
|
${lowDisk ? "" : `<button class="icon-button" data-action="screenshot">Screenshot</button>`}
|
|
<button class="record-button" data-action="toggle-record">${state.captureActive || state.sessionRecording ? "Stop" : "Record"}</button>
|
|
</header>
|
|
`;
|
|
}
|
|
|
|
function renderActiveView(selectedClip: Clip | undefined) {
|
|
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) {
|
|
const clips = filteredClips();
|
|
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="${state.libraryViewMode === "grid" ? "selected" : ""}" data-view-mode="grid">Grid</button>
|
|
<button class="${state.libraryViewMode === "list" ? "selected" : ""}" data-view-mode="list">List</button>
|
|
</div>
|
|
</div>
|
|
<input class="search-input" placeholder="Search clips, games, events, tags" value="${escapeHtml(state.libraryQuery)}" data-action="library-search" />
|
|
<div class="filters">
|
|
${[
|
|
["all", "All"],
|
|
["kills", "Kills"],
|
|
["wins", "Wins"],
|
|
["uploaded", "Uploaded"],
|
|
["failed", "Failed"],
|
|
]
|
|
.map(
|
|
([filter, label]) =>
|
|
`<button class="${state.libraryFilter === filter ? "selected" : ""}" data-library-filter="${filter}">${label}</button>`,
|
|
)
|
|
.join("")}
|
|
</div>
|
|
<div class="${state.libraryViewMode === "list" ? "clip-list" : "clip-grid"}">
|
|
${clips.length > 0 ? clips.map(renderClipCard).join("") : `<div class="empty-state">No matching clips</div>`}
|
|
</div>
|
|
</section>
|
|
|
|
<section class="screenshots-panel">
|
|
<div class="section-heading">
|
|
<div>
|
|
<p class="eyebrow">Screenshots</p>
|
|
<h2>Recent Screenshots</h2>
|
|
</div>
|
|
<div class="segmented">
|
|
<button class="${state.libraryViewMode === "grid" ? "selected" : ""}" data-view-mode="grid">Grid</button>
|
|
<button class="${state.libraryViewMode === "list" ? "selected" : ""}" data-view-mode="list">List</button>
|
|
</div>
|
|
</div>
|
|
<input class="search-input" placeholder="Search screenshots" value="${escapeHtml(state.libraryQuery)}" data-action="library-search" />
|
|
<div class="${state.libraryViewMode === "list" ? "screenshot-list" : "screenshot-grid"}">
|
|
${state.screenshots.length > 0 ? state.screenshots.map(renderScreenshotCard).join("") : `<div class="empty-state">No screenshots</div>`}
|
|
</div>
|
|
</section>
|
|
|
|
${renderClipDetails(selectedClip)}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderScreenshotCard(path: string) {
|
|
const filename = path.split(/[/\\]/).pop() ?? path;
|
|
const url = convertFileSrc(path);
|
|
return `
|
|
<article class="clip-card screenshot-card" data-screenshot-path="${escapeHtml(path)}">
|
|
<div class="thumb screenshot-thumb">
|
|
<img src="${url}" alt="${escapeHtml(filename)}" />
|
|
</div>
|
|
<h3>${escapeHtml(filename)}</h3>
|
|
<p class="muted">${escapeHtml(path)}</p>
|
|
<div class="actions">
|
|
<button data-action="open-modal-screenshot" data-screenshot-path="${escapeHtml(path)}">Preview</button>
|
|
<button data-action="reveal-screenshot" data-screenshot-path="${escapeHtml(path)}">Open</button>
|
|
</div>
|
|
</article>
|
|
`;
|
|
}
|
|
|
|
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="" />` : escapeHtml(clip.event)}
|
|
</div>
|
|
<h3>${escapeHtml(clip.title)}</h3>
|
|
<p>${escapeHtml(clip.game)} · ${escapeHtml(clip.source)} · ${escapeHtml(clip.duration)}</p>
|
|
<div class="actions">
|
|
<button data-action="open-modal-clip" data-clip-id="${clip.id}">Preview</button>
|
|
</div>
|
|
</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>
|
|
`;
|
|
}
|
|
|
|
const durationSeconds = parseTimestamp(clip.duration);
|
|
const durationDisplay = formatDuration(durationSeconds);
|
|
|
|
return `
|
|
<aside class="detail-panel">
|
|
<div class="preview">
|
|
${
|
|
clip.videoUrl
|
|
? `<video controls preload="metadata" src="${clip.videoUrl}" poster="${clip.thumbnailUrl ?? ""}" id="clip-preview"></video>`
|
|
: `<span>Preview</span>`
|
|
}
|
|
</div>
|
|
<label>Title <input value="${escapeHtml(clip.title)}" data-action="clip-title" /></label>
|
|
<p class="muted">${escapeHtml(clip.game)} · ${escapeHtml(clip.event)} · ${escapeHtml(clip.createdAt)} · ${escapeHtml(clip.uploadState)}</p>
|
|
<label>Tags <input value="${escapeHtml(clip.tags.join(", "))}" data-action="clip-tags" /></label>
|
|
<div class="tag-row">${clip.tags.map((tag) => `<span>${escapeHtml(tag)}</span>`).join("")}</div>
|
|
<p class="muted file-path">${escapeHtml(clip.path || "Clip file unavailable")}</p>
|
|
<div class="trim-section">
|
|
<h4>Trim</h4>
|
|
<div class="timeline-container">
|
|
<div class="timeline-track" data-action="timeline-track" role="slider" aria-label="Trim timeline" tabindex="0">
|
|
<div class="timeline-fill" id="timeline-fill"></div>
|
|
<div class="timeline-handle" id="timeline-handle-start" data-handle="start" role="slider" aria-label="Trim start" tabindex="0"></div>
|
|
<div class="timeline-handle" id="timeline-handle-end" data-handle="end" role="slider" aria-label="Trim end" tabindex="0"></div>
|
|
</div>
|
|
<div class="timeline-labels">
|
|
<span id="timeline-label-start">00:00</span>
|
|
<span id="timeline-label-end">${escapeHtml(durationDisplay)}</span>
|
|
</div>
|
|
</div>
|
|
<div class="trim-row">
|
|
<label>Start <input value="00:00" data-action="trim-start" /></label>
|
|
<label>End <input value="${escapeHtml(durationDisplay)}" data-action="trim-end" /></label>
|
|
</div>
|
|
</div>
|
|
<div class="actions">
|
|
<button data-action="save-metadata">Save Info</button>
|
|
<button data-action="process">Trim</button>
|
|
<button data-action="reveal">Reveal</button>
|
|
<button data-action="export-copy">Export</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() {
|
|
const override = state.gameQualityOverrides.find((candidate) => candidate.game_id === state.detectedGame) ?? null;
|
|
const baseResolution = state.captureResolution || "1280x720";
|
|
const overrideResolution = override ? `${override.width}x${override.height}` : baseResolution;
|
|
const presetOptions = ["1280x720", "1920x1080", "2560x1440", "3840x2160"];
|
|
const resolutionOptions = presetOptions.includes(overrideResolution)
|
|
? presetOptions
|
|
: [overrideResolution, ...presetOptions];
|
|
const fpsOptions = [30, 60, 120];
|
|
const overrideFps = override?.fps ?? state.captureFps;
|
|
const overrideBitrate = override?.bitrate_kbps ?? state.captureBitrateKbps;
|
|
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>${escapeHtml(state.captureResolution)} @ ${state.captureFps} fps</h2>
|
|
<p class="muted">${state.effectiveQualityApplied ? `A quality override is active for ${escapeHtml(state.detectedGame)}.` : "Using the global quality settings."}</p>
|
|
<p class="muted">Lightweight desktop capture uses bundled FFmpeg when system FFmpeg is missing.</p>
|
|
<p class="muted">${state.desktopDuplicationAvailable ? "Desktop Duplication capture available" : "Using GDI capture fallback"}</p>
|
|
<p class="muted">${state.captureBackend ? `Active backend: ${state.captureBackend}` : "Active backend: idle"}</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>
|
|
<p class="muted">${state.freeDiskGb > 0 ? `${state.freeDiskGb.toFixed(1)} GB free on recording drive` : "Disk space unknown"}</p>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Quality override</p>
|
|
<h2>Per-game capture settings</h2>
|
|
${state.detectedGame === "Waiting for game" ? `
|
|
<p class="muted">Start a supported game and you can give it its own resolution, FPS, and bitrate here.</p>
|
|
` : `
|
|
<p class="muted">Override quality for ${escapeHtml(state.detectedGame)}${override ? ` (currently ${override.width}x${override.height} @ ${override.fps} fps)` : ""}.</p>
|
|
<div class="field-row">
|
|
<label>Resolution
|
|
<select data-action="override-preset">
|
|
${resolutionOptions.map((option) => `<option value="${option}" ${option === overrideResolution ? "selected" : ""}>${option}</option>`).join("")}
|
|
</select>
|
|
</label>
|
|
<label>FPS
|
|
<select data-action="override-fps">
|
|
${fpsOptions.map((option) => `<option value="${option}" ${option === overrideFps ? "selected" : ""}>${option} fps</option>`).join("")}
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<label>Bitrate (kbps) <input type="number" min="500" max="50000" step="500" value="${overrideBitrate}" data-action="override-bitrate" /></label>
|
|
<button data-action="save-override">Save override for ${escapeHtml(state.detectedGame)}</button>
|
|
<button data-action="clear-override" ${override ? "" : "disabled"}>Revert to global settings</button>
|
|
`}
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Audio</p>
|
|
<h2>${state.systemAudioAvailable ? "System audio ready" : "System audio unavailable"}</h2>
|
|
<p class="muted">${state.systemAudioAvailable ? "Native WASAPI or FFmpeg audio capture is available." : "No system loopback device is available; video recording still works."}</p>
|
|
<label class="toggle"><input type="checkbox" ${state.systemAudioEnabled ? "checked" : ""} data-action="toggle-system-audio" /> System audio</label>
|
|
<label class="toggle"><input type="checkbox" ${state.micEnabled ? "checked" : ""} data-action="toggle-mic" /> Mic capture</label>
|
|
<label>Mic device
|
|
<select data-action="mic-device">
|
|
<option value="">Default microphone</option>
|
|
${state.audioDevices
|
|
.filter((device) => device.kind === "input")
|
|
.map(
|
|
(device) =>
|
|
`<option value="${escapeHtml(device.name)}" ${state.micDevice === device.name ? "selected" : ""}>${escapeHtml(device.name)}</option>`,
|
|
)
|
|
.join("")}
|
|
</select>
|
|
</label>
|
|
</article>
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderAutoClipView() {
|
|
const games: Array<{ gameId: string; game: string }> = [];
|
|
for (const event of state.autoEvents) {
|
|
if (!games.some((game) => game.gameId === event.gameId)) {
|
|
games.push({ gameId: event.gameId, game: event.game });
|
|
}
|
|
}
|
|
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="actions auto-clip-global-actions">
|
|
<button data-action="auto-clip-enable-all">Enable all games</button>
|
|
<button data-action="auto-clip-disable-all">Disable all games</button>
|
|
<button data-action="auto-clip-restore">Restore defaults</button>
|
|
</div>
|
|
${games
|
|
.map((game) => {
|
|
const gameEvents = state.autoEvents.filter((event) => event.gameId === game.gameId);
|
|
const gameEnabled = !state.disabledGames.includes(game.gameId);
|
|
return `
|
|
<section class="auto-clip-group ${gameEnabled ? "" : "disabled"}">
|
|
<div class="auto-clip-group-head">
|
|
<label class="toggle">
|
|
<input type="checkbox" ${gameEnabled ? "checked" : ""} data-game-id="${escapeHtml(game.gameId)}" data-action="toggle-game-clips" />
|
|
<strong>${escapeHtml(game.game)}</strong>
|
|
</label>
|
|
<span class="status-pill">${gameEnabled ? "Clipping enabled" : "Clipping disabled"}</span>
|
|
</div>
|
|
<div class="event-list">
|
|
${gameEvents
|
|
.map(
|
|
(event) => `
|
|
<label class="event-row">
|
|
<span><strong>${escapeHtml(event.event)}</strong></span>
|
|
<input type="checkbox" ${event.enabled ? "checked" : ""} data-event-id="${event.id}" ${gameEnabled ? "" : "disabled"} />
|
|
</label>
|
|
`,
|
|
)
|
|
.join("")}
|
|
</div>
|
|
</section>
|
|
`;
|
|
})
|
|
.join("")}
|
|
<div class="actions">
|
|
<button data-action="write-gsi-configs">Write GSI Configs</button>
|
|
</div>
|
|
${state.gsiConfigStatus ? `<p class="muted file-path">${state.gsiConfigStatus}</p>` : ""}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderUploadsView() {
|
|
const providers: Array<{ id: UploadProvider; title: string; body: string }> = [
|
|
{ id: "catbox", title: "Catbox", body: "Anonymous or userhash-backed permanent uploads." },
|
|
{ id: "litterbox", title: "Litterbox", body: "Temporary uploads with a selectable expiry." },
|
|
{ id: "custom_http", title: "Custom HTTP", body: "POST multipart clip files to your own endpoint." },
|
|
{ id: "lustful", title: "Lustful", body: "Blocked until API details are confirmed." },
|
|
];
|
|
return `
|
|
<section class="settings-grid">
|
|
${providers.map((provider) => `
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Provider</p>
|
|
<h2>${provider.title}</h2>
|
|
<p class="muted">${provider.body}</p>
|
|
<button class="${state.uploadProvider === provider.id ? "selected" : ""}" data-upload-provider="${provider.id}">
|
|
${state.uploadProvider === provider.id ? "Selected" : "Select"}
|
|
</button>
|
|
</article>
|
|
`).join("")}
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Automation</p>
|
|
<h2>Upload Rules</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">Catbox</p>
|
|
<h2>Userhash</h2>
|
|
<label>Optional userhash <input value="${escapeHtml(state.catboxUserhash)}" data-action="catbox-userhash" /></label>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Litterbox</p>
|
|
<h2>Expiry</h2>
|
|
<select data-action="litterbox-expiry">
|
|
${[1, 12, 24, 72].map((hours) => `<option value="${hours}" ${state.litterboxExpiryHours === hours ? "selected" : ""}>${hours} hour${hours === 1 ? "" : "s"}</option>`).join("")}
|
|
</select>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Custom HTTP</p>
|
|
<h2>Endpoint</h2>
|
|
<label>URL <input value="${escapeHtml(state.customUploadEndpoint)}" data-action="custom-upload-endpoint" /></label>
|
|
<label>Response path <input value="${escapeHtml(state.customUploadResponsePath)}" data-action="custom-upload-response-path" /></label>
|
|
<label>Headers <textarea data-action="custom-upload-headers">${escapeHtml(state.customUploadHeaders)}</textarea></label>
|
|
</article>
|
|
</section>
|
|
<section class="table-panel">
|
|
<div class="section-heading">
|
|
<div>
|
|
<p class="eyebrow">Upload history</p>
|
|
<h2>Recent Uploads</h2>
|
|
</div>
|
|
<button data-action="refresh-upload-history">Refresh</button>
|
|
</div>
|
|
${state.uploadHistory.length > 0
|
|
? `<div class="upload-history">${state.uploadHistory.map(renderUploadHistoryRow).join("")}</div>`
|
|
: `<p class="muted">No upload attempts recorded yet.</p>`}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderUploadHistoryRow(entry: UploadHistoryEntry) {
|
|
const failed = entry.status === "failed";
|
|
const uploaded = entry.status === "uploaded";
|
|
return `
|
|
<div class="upload-row ${failed ? "failed" : uploaded ? "uploaded" : ""}">
|
|
<div class="upload-row-main">
|
|
<strong>${escapeHtml(entry.provider)}</strong>
|
|
<span class="muted">${escapeHtml(entry.clip_id)}</span>
|
|
<span class="status-pill">${escapeHtml(entry.status)}</span>
|
|
${entry.url ? `<a class="muted" href="${escapeHtml(entry.url)}" target="_blank" rel="noreferrer">${escapeHtml(entry.url)}</a>` : ""}
|
|
${entry.error ? `<p class="muted">${escapeHtml(entry.error)}</p>` : ""}
|
|
<p class="muted">${escapeHtml(entry.attempted_at)}</p>
|
|
</div>
|
|
${failed ? `<button data-action="retry-upload" data-clip-id="${escapeHtml(entry.clip_id)}">Retry</button>` : ""}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function renderSettingsView() {
|
|
const resolutionPresets = ["1280x720", "1920x1080", "2560x1440", "3840x2160"];
|
|
const resolutionOptions = resolutionPresets.includes(state.captureResolution)
|
|
? resolutionPresets
|
|
: [state.captureResolution, ...resolutionPresets];
|
|
const fpsPresets = [30, 60, 120, 144];
|
|
const fpsOptions = fpsPresets.includes(state.captureFps)
|
|
? fpsPresets
|
|
: [state.captureFps, ...fpsPresets];
|
|
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.autoRecordEnabled ? "checked" : ""} data-action="toggle-auto-record" /> Start recording when a supported game is detected</label>
|
|
<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">Capture</p>
|
|
<h2>Quality & rights</h2>
|
|
<p class="muted">Current: ${escapeHtml(state.captureResolution)} @ ${state.captureFps} fps (${state.captureBitrateKbps.toLocaleString()} kbps). New settings apply the next time capture starts.</p>
|
|
<div class="field-row">
|
|
<label>Resolution
|
|
<select data-action="capture-resolution">
|
|
${resolutionOptions.map((option) => `<option value="${option}" ${option === state.captureResolution ? "selected" : ""}>${option}</option>`).join("")}
|
|
</select>
|
|
</label>
|
|
<label>FPS
|
|
<select data-action="capture-fps">
|
|
${fpsOptions.map((option) => `<option value="${option}" ${option === state.captureFps ? "selected" : ""}>${option} fps</option>`).join("")}
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<label>Video bitrate preset
|
|
<select data-action="capture-bitrate-preset" aria-label="Bitrate preset">
|
|
<option value="2500" ${state.captureBitrateKbps <= 3500 ? "selected" : ""}>Low (2500)</option>
|
|
<option value="4500" ${state.captureBitrateKbps > 3500 && state.captureBitrateKbps <= 5500 ? "selected" : ""}>Medium (4500)</option>
|
|
<option value="6000" ${state.captureBitrateKbps > 5500 && state.captureBitrateKbps <= 8000 ? "selected" : ""}>Stream-ready (6000)</option>
|
|
<option value="10000" ${state.captureBitrateKbps > 8000 && state.captureBitrateKbps <= 12000 ? "selected" : ""}>High (10000)</option>
|
|
<option value="14000" ${state.captureBitrateKbps > 12000 ? "selected" : ""}>Ultra (14000)</option>
|
|
<option value="custom" ${state.captureBitrateKbps < 2500 || state.captureBitrateKbps > 14000 ? "selected" : ""}>Custom…</option>
|
|
</select>
|
|
</label>
|
|
<label>Custom bitrate (kbps) <input type="number" min="500" max="50000" step="500" value="${state.captureBitrateKbps}" data-action="capture-bitrate" /></label>
|
|
<label>Buffer storage cap (GB) <input type="number" min="5" max="5000" step="1" value="${state.storageLimitGb}" data-action="capture-storage-gb" /></label>
|
|
<label>Excluded window titles
|
|
<textarea rows="2" placeholder="comma separated, e.g. Brave, Discord - Settings" data-action="excluded-windows">${escapeHtml(state.excludedWindowText)}</textarea>
|
|
</label>
|
|
<label class="toggle"><input type="checkbox" ${state.separateAudioTracks ? "checked" : ""} data-action="toggle-separate-audio" /> Record separate audio tracks for game and mic</label>
|
|
<button data-action="save-capture-settings">Save Capture Settings</button>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Storage</p>
|
|
<h2>Clips & replay buffer</h2>
|
|
<label>Clip folder
|
|
<input value="${escapeHtml(state.clipDirectory)}" data-action="clip-directory" spellcheck="false" placeholder="C:\\Users\\You\\Videos\\Clips" />
|
|
</label>
|
|
<button data-action="change-clip-dir">Apply Clip Folder</button>
|
|
${state.storageLimitExceeded ? `<p class="warn">The saved library is currently above the ${state.storageLimitGb} GB limit.</p>` : ""}
|
|
<label class="toggle"><input type="checkbox" ${state.autoPruneOldClips ? "checked" : ""} data-action="toggle-auto-prune" /> Auto-delete oldest clips when the library exceeds the ${state.storageLimitGb} GB limit</label>
|
|
<p class="muted">${state.autoPruneOldClips ? "When the limit is exceeded, the oldest automatic/event/session clips are deleted (oldest first) until you are back under it. Clips you saved manually are never auto-deleted." : "Up to the limit, the rolling replay buffer is always pruned automatically to keep it from growing. Saved clips are kept. Enable auto-cleanup above to also trim oldest clips when the limit is exceeded."}</p>
|
|
<p class="muted">This limit is set in Capture Settings (buffer storage cap).</p>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Tray</p>
|
|
<h2>Close behavior</h2>
|
|
<label class="toggle"><input type="checkbox" ${state.minimizeToTray ? "checked" : ""} data-action="toggle-minimize-to-tray" /> Keep running in the system tray when I close the window</label>
|
|
<p class="muted">When enabled, closing the ClipForge window hides it to the tray and it keeps recording. Use "Quit ClipForge" from the tray icon to exit fully.</p>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">About & support</p>
|
|
<h2>ClipForge ${escapeHtml(state.appVersion)}</h2>
|
|
<p class="muted">${escapeHtml(state.update.message)}</p>
|
|
${state.update.updateAvailable ? `
|
|
<button data-action="download-update" ${state.update.applying ? "disabled" : ""}>Download & install v${escapeHtml(state.update.latestVersion)}</button>
|
|
` : ""}
|
|
<button data-action="check-updates" ${state.update.applying ? "disabled" : ""}>${state.update.checked ? "Check for updates again" : "Check for updates"}</button>
|
|
<button data-action="reveal-crash-logs">Reveal Crash Logs</button>
|
|
</article>
|
|
<article class="settings-panel">
|
|
<p class="eyebrow">Hotkeys</p>
|
|
<h2>Customizable</h2>
|
|
<label>Clip last 60s <input value="${escapeHtml(state.hotkeyClipLast60s)}" data-action="hotkey-clip-60s" placeholder="e.g. F8" /></label>
|
|
<label>Clip last 30s <input value="${escapeHtml(state.hotkeyClipLast30s)}" data-action="hotkey-clip-30s" placeholder="e.g. Shift+F8" /></label>
|
|
<label>Toggle recording <input value="${escapeHtml(state.hotkeyToggleRecording)}" data-action="hotkey-toggle-recording" placeholder="e.g. Alt+F7" /></label>
|
|
<label>Screenshot <input value="${escapeHtml(state.hotkeyScreenshot)}" data-action="hotkey-screenshot" placeholder="e.g. F9" /></label>
|
|
<p class="muted">Format: [Modifier+]Key (e.g. Ctrl+Shift+F1, Alt+F7, F8). Modifiers: Ctrl, Shift, Alt, Meta.</p>
|
|
<button data-action="save-hotkeys">Save Hotkeys</button>
|
|
</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.querySelectorAll<HTMLButtonElement>("[data-view-mode]").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
state.libraryViewMode = button.dataset.viewMode === "list" ? "list" : "grid";
|
|
render();
|
|
});
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-library-filter]").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
state.libraryFilter = (button.dataset.libraryFilter as AppState["libraryFilter"]) ?? "all";
|
|
render();
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='library-search']")?.addEventListener("input", (event) => {
|
|
state.libraryQuery = (event.target as HTMLInputElement).value;
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='clip']")?.addEventListener("click", () => {
|
|
void saveClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='screenshot']")?.addEventListener("click", () => {
|
|
void takeScreenshot();
|
|
});
|
|
|
|
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='save-metadata']")?.addEventListener("click", () => {
|
|
void saveSelectedClipMetadata();
|
|
});
|
|
|
|
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='export-copy']")?.addEventListener("click", () => {
|
|
void exportSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='write-gsi-configs']")?.addEventListener("click", () => {
|
|
void writeGsiConfigs();
|
|
});
|
|
|
|
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='buffer-length']")?.addEventListener("change", (event) => {
|
|
void saveReplayBufferSetting(Number((event.target as HTMLInputElement).value));
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-mic']")?.addEventListener("change", (event) => {
|
|
state.micEnabled = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
void saveMicSetting(state.micEnabled);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-system-audio']")?.addEventListener("change", (event) => {
|
|
state.systemAudioEnabled = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
void saveSystemAudioSetting(state.systemAudioEnabled);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='mic-device']")?.addEventListener("change", (event) => {
|
|
state.micDevice = (event.target as HTMLSelectElement).value;
|
|
void saveMicDevice(state.micDevice);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-auto-upload']")?.addEventListener("change", (event) => {
|
|
state.autoUpload = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-auto-record']")?.addEventListener("change", (event) => {
|
|
state.autoRecordEnabled = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
void saveAutoRecordSetting(state.autoRecordEnabled);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-minimize-to-tray']")?.addEventListener("change", (event) => {
|
|
state.minimizeToTray = (event.target as HTMLInputElement).checked;
|
|
render();
|
|
void saveMinimizeToTraySetting(state.minimizeToTray);
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-upload-provider]").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
state.uploadProvider = button.dataset.uploadProvider as UploadProvider;
|
|
render();
|
|
void saveUploadSettings();
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='catbox-userhash']")?.addEventListener("change", (event) => {
|
|
state.catboxUserhash = (event.target as HTMLInputElement).value;
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='litterbox-expiry']")?.addEventListener("change", (event) => {
|
|
state.litterboxExpiryHours = Number((event.target as HTMLSelectElement).value) as AppState["litterboxExpiryHours"];
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-endpoint']")?.addEventListener("input", (event) => {
|
|
state.customUploadEndpoint = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-endpoint']")?.addEventListener("change", () => {
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-response-path']")?.addEventListener("input", (event) => {
|
|
state.customUploadResponsePath = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='custom-upload-response-path']")?.addEventListener("change", () => {
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLTextAreaElement>("[data-action='custom-upload-headers']")?.addEventListener("input", (event) => {
|
|
state.customUploadHeaders = (event.target as HTMLTextAreaElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLTextAreaElement>("[data-action='custom-upload-headers']")?.addEventListener("change", () => {
|
|
void saveUploadSettings();
|
|
});
|
|
|
|
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;
|
|
void saveAutoClipEventSetting(eventRule);
|
|
}
|
|
});
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLInputElement>("[data-action='toggle-game-clips']").forEach((input) => {
|
|
input.addEventListener("change", () => {
|
|
const gameId = input.dataset.gameId;
|
|
if (gameId) {
|
|
state.disabledGames = input.checked
|
|
? state.disabledGames.filter((game) => game !== gameId)
|
|
: [...state.disabledGames, gameId];
|
|
void invokeSetGameAutoClipEnabled(gameId, input.checked);
|
|
}
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='auto-clip-enable-all']")?.addEventListener("click", () => {
|
|
void invokeAutoClipBulk("enable_all_auto_clips");
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='auto-clip-disable-all']")?.addEventListener("click", () => {
|
|
void invokeAutoClipBulk("disable_all_auto_clips");
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='auto-clip-restore']")?.addEventListener("click", () => {
|
|
void invokeAutoClipBulk("restore_default_auto_clips");
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='hotkey-clip-60s']")?.addEventListener("change", (event) => {
|
|
state.hotkeyClipLast60s = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='hotkey-clip-30s']")?.addEventListener("change", (event) => {
|
|
state.hotkeyClipLast30s = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='hotkey-toggle-recording']")?.addEventListener("change", (event) => {
|
|
state.hotkeyToggleRecording = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='hotkey-screenshot']")?.addEventListener("change", (event) => {
|
|
state.hotkeyScreenshot = (event.target as HTMLInputElement).value;
|
|
});
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='save-hotkeys']")?.addEventListener("click", () => {
|
|
void saveHotkeys();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='capture-resolution']")?.addEventListener("change", (event) => {
|
|
state.captureResolution = (event.target as HTMLSelectElement).value;
|
|
});
|
|
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='capture-fps']")?.addEventListener("change", (event) => {
|
|
state.captureFps = Number((event.target as HTMLSelectElement).value);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='capture-bitrate']")?.addEventListener("input", (event) => {
|
|
state.captureBitrateKbps = Number((event.target as HTMLInputElement).value);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='capture-bitrate-preset']")?.addEventListener("change", (event) => {
|
|
const preset = (event.target as HTMLSelectElement).value;
|
|
if (preset !== "custom") {
|
|
const value = Number(preset);
|
|
state.captureBitrateKbps = value;
|
|
const input = appRoot.querySelector<HTMLInputElement>("[data-action='capture-bitrate']");
|
|
if (input) {
|
|
input.value = String(value);
|
|
}
|
|
}
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='capture-storage-gb']")?.addEventListener("input", (event) => {
|
|
state.storageLimitGb = Number((event.target as HTMLInputElement).value);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLTextAreaElement>("[data-action='excluded-windows']")?.addEventListener("input", (event) => {
|
|
state.excludedWindowText = (event.target as HTMLTextAreaElement).value;
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-separate-audio']")?.addEventListener("change", (event) => {
|
|
state.separateAudioTracks = (event.target as HTMLInputElement).checked;
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='save-capture-settings']")?.addEventListener("click", () => {
|
|
void saveCaptureSettings();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='check-updates']")?.addEventListener("click", () => {
|
|
void checkForUpdates();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='clip-directory']")?.addEventListener("input", (event) => {
|
|
state.clipDirectory = (event.target as HTMLInputElement).value;
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='change-clip-dir']")?.addEventListener("click", () => {
|
|
void changeClipDirectory();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLInputElement>("[data-action='toggle-auto-prune']")?.addEventListener("change", (event) => {
|
|
void setAutoPruneEnabled((event.target as HTMLInputElement).checked);
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='save-override']")?.addEventListener("click", () => {
|
|
void saveGameQualityOverride();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='clear-override']")?.addEventListener("click", () => {
|
|
void clearGameQualityOverride();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='onboarding-next']")?.addEventListener("click", () => {
|
|
state.onboardingStep = Math.min(state.onboardingStep + 1, 3);
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='onboarding-back']")?.addEventListener("click", () => {
|
|
state.onboardingStep = Math.max(state.onboardingStep - 1, 0);
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='onboarding-finish']")?.addEventListener("click", () => {
|
|
void finishOnboarding();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='onboarding-skip']")?.addEventListener("click", () => {
|
|
void skipOnboarding();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='download-update']")?.addEventListener("click", () => {
|
|
void downloadUpdate();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='reveal-crash-logs']")?.addEventListener("click", () => {
|
|
void revealCrashLogs();
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-action='open-modal-clip']").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
const clipId = button.dataset.clipId;
|
|
if (clipId) {
|
|
openClipModal(clipId);
|
|
}
|
|
});
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-action='open-modal-screenshot']").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
const path = button.dataset.screenshotPath;
|
|
if (path) {
|
|
openScreenshotModal(path);
|
|
}
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-close']")?.addEventListener("click", closeModal);
|
|
|
|
appRoot.querySelector<HTMLElement>("[data-action='modal-backdrop']")?.addEventListener("click", (event) => {
|
|
if (event.target === event.currentTarget) {
|
|
closeModal();
|
|
}
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-trim']")?.addEventListener("click", () => {
|
|
void trimClipFromModal();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-upload']")?.addEventListener("click", () => {
|
|
state.selectedClipId = state.modal.clipId;
|
|
void uploadSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-reveal']")?.addEventListener("click", () => {
|
|
state.selectedClipId = state.modal.clipId;
|
|
void revealSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-delete']")?.addEventListener("click", () => {
|
|
state.selectedClipId = state.modal.clipId;
|
|
void deleteSelectedClip();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='modal-retry']")?.addEventListener("click", () => {
|
|
state.modal.videoFailed = false;
|
|
state.modal.videoError = "";
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelector<HTMLVideoElement>("#modal-video")?.addEventListener("error", () => {
|
|
state.modal.videoFailed = true;
|
|
state.modal.videoError = "The clip file could not be loaded as a preview. It may have been moved or deleted, or the media table of contents is unreadable.";
|
|
render();
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-action='reveal-screenshot']").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
const path = button.dataset.screenshotPath;
|
|
if (path) {
|
|
void revealScreenshot(path);
|
|
}
|
|
});
|
|
});
|
|
|
|
appRoot.querySelector<HTMLButtonElement>("[data-action='refresh-upload-history']")?.addEventListener("click", () => {
|
|
void refreshUploadHistory().then(() => render());
|
|
});
|
|
|
|
appRoot.querySelectorAll<HTMLButtonElement>("[data-action='retry-upload']").forEach((button) => {
|
|
button.addEventListener("click", () => {
|
|
const clipId = button.dataset.clipId;
|
|
if (clipId) {
|
|
const entry = state.uploadHistory.find((e) => e.clip_id === clipId);
|
|
if (entry) {
|
|
void retryUpload(entry);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// Timeline drag handlers
|
|
const timelineTrack = appRoot.querySelector<HTMLElement>("[data-action='timeline-track']");
|
|
const handleStart = appRoot.querySelector<HTMLElement>("#timeline-handle-start");
|
|
const handleEnd = appRoot.querySelector<HTMLElement>("#timeline-handle-end");
|
|
|
|
if (timelineTrack && handleStart && handleEnd) {
|
|
let draggingHandle: "start" | "end" | null = null;
|
|
const clip = state.clips.find((c) => c.id === state.selectedClipId);
|
|
const clipDuration = clip ? parseTimestamp(clip.duration) : 0;
|
|
|
|
const updateHandlePositions = () => {
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
const startLabel = appRoot.querySelector<HTMLElement>("#timeline-label-start");
|
|
const endLabel = appRoot.querySelector<HTMLElement>("#timeline-label-end");
|
|
const fill = appRoot.querySelector<HTMLElement>("#timeline-fill");
|
|
|
|
if (startInput && endInput && clipDuration > 0) {
|
|
const startPercent = (parseTimestamp(startInput.value) / clipDuration) * 100;
|
|
const endPercent = (parseTimestamp(endInput.value) / clipDuration) * 100;
|
|
|
|
handleStart.style.left = `${Math.max(0, Math.min(100, startPercent))}%`;
|
|
handleEnd.style.left = `${Math.max(0, Math.min(100, endPercent))}%`;
|
|
|
|
if (fill) {
|
|
fill.style.left = `${startPercent}%`;
|
|
fill.style.width = `${Math.max(0, endPercent - startPercent)}%`;
|
|
}
|
|
|
|
if (startLabel) startLabel.textContent = formatDuration(parseTimestamp(startInput.value));
|
|
if (endLabel) endLabel.textContent = formatDuration(parseTimestamp(endInput.value));
|
|
}
|
|
};
|
|
|
|
const startDrag = (handle: "start" | "end") => {
|
|
draggingHandle = handle;
|
|
document.body.style.cursor = "ew-resize";
|
|
document.body.style.userSelect = "none";
|
|
};
|
|
|
|
const onMouseMove = (e: MouseEvent) => {
|
|
if (!draggingHandle || clipDuration <= 0) return;
|
|
|
|
const rect = timelineTrack.getBoundingClientRect();
|
|
const percent = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100));
|
|
const seconds = (percent / 100) * clipDuration;
|
|
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
|
|
if (draggingHandle === "start" && startInput && endInput) {
|
|
const newStart = Math.min(seconds, parseTimestamp(endInput.value) - 1);
|
|
startInput.value = formatDuration(Math.max(0, newStart));
|
|
} else if (draggingHandle === "end" && startInput && endInput) {
|
|
const newEnd = Math.max(seconds, parseTimestamp(startInput.value) + 1);
|
|
endInput.value = formatDuration(Math.min(clipDuration, newEnd));
|
|
}
|
|
|
|
updateHandlePositions();
|
|
};
|
|
|
|
const onMouseUp = () => {
|
|
if (draggingHandle) {
|
|
draggingHandle = null;
|
|
document.body.style.cursor = "";
|
|
document.body.style.userSelect = "";
|
|
}
|
|
};
|
|
|
|
handleStart.addEventListener("mousedown", (e) => {
|
|
e.stopPropagation();
|
|
startDrag("start");
|
|
});
|
|
|
|
handleEnd.addEventListener("mousedown", (e) => {
|
|
e.stopPropagation();
|
|
startDrag("end");
|
|
});
|
|
|
|
timelineTrack.addEventListener("mousedown", (e) => {
|
|
const rect = timelineTrack.getBoundingClientRect();
|
|
const percent = ((e.clientX - rect.left) / rect.width) * 100;
|
|
const seconds = (percent / 100) * clipDuration;
|
|
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
|
|
if (startInput && endInput) {
|
|
const startVal = parseTimestamp(startInput.value);
|
|
const endVal = parseTimestamp(endInput.value);
|
|
const midPoint = (startVal + endVal) / 2;
|
|
|
|
if (seconds < midPoint) {
|
|
startInput.value = formatDuration(Math.max(0, seconds));
|
|
} else {
|
|
endInput.value = formatDuration(Math.min(clipDuration, seconds));
|
|
}
|
|
updateHandlePositions();
|
|
}
|
|
});
|
|
|
|
document.addEventListener("mousemove", onMouseMove);
|
|
document.addEventListener("mouseup", onMouseUp);
|
|
|
|
// Keyboard support for handles
|
|
[handleStart, handleEnd].forEach((handle, idx) => {
|
|
handle.addEventListener("keydown", (e) => {
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
if (!startInput || !endInput) return;
|
|
|
|
const step = 5; // 5 seconds
|
|
let changed = false;
|
|
|
|
if (e.key === "ArrowRight") {
|
|
if (idx === 0) { // start handle
|
|
const newVal = Math.min(parseTimestamp(startInput.value) + step, parseTimestamp(endInput.value) - 1);
|
|
startInput.value = formatDuration(newVal);
|
|
changed = true;
|
|
} else { // end handle
|
|
const newVal = Math.min(parseTimestamp(endInput.value) + step, clipDuration);
|
|
endInput.value = formatDuration(newVal);
|
|
changed = true;
|
|
}
|
|
} else if (e.key === "ArrowLeft") {
|
|
if (idx === 0) { // start handle
|
|
const newVal = Math.max(parseTimestamp(startInput.value) - step, 0);
|
|
startInput.value = formatDuration(newVal);
|
|
changed = true;
|
|
} else { // end handle
|
|
const newVal = Math.max(parseTimestamp(endInput.value) - step, parseTimestamp(startInput.value) + 1);
|
|
endInput.value = formatDuration(newVal);
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
if (changed) {
|
|
e.preventDefault();
|
|
updateHandlePositions();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Sync input changes to timeline
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
|
if (startInput) startInput.addEventListener("input", updateHandlePositions);
|
|
if (endInput) endInput.addEventListener("input", updateHandlePositions);
|
|
|
|
// Initial update
|
|
updateHandlePositions();
|
|
}
|
|
}
|
|
|
|
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();
|
|
showNotice("Clip saved");
|
|
render();
|
|
return;
|
|
} catch (error) {
|
|
console.error("Could not save desktop clip", error);
|
|
showNotice(`Could not save clip: ${String(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() {
|
|
const wasActive = state.captureActive;
|
|
// Optimistically flip the button so the UI reacts instantly; the real status
|
|
// returned by the backend reconciles it (or it is rolled back on error).
|
|
state.captureActive = !wasActive;
|
|
state.recordingState = state.captureActive ? "RecordingSession" : "Buffering";
|
|
render();
|
|
|
|
if (tauriInvoke) {
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>(wasActive ? "stop_capture" : "start_capture");
|
|
applyDesktopStatus(status);
|
|
await refreshClips();
|
|
showNotice(state.captureActive ? "Recording started" : "Recording stopped");
|
|
render();
|
|
return;
|
|
} catch (error) {
|
|
state.captureActive = wasActive;
|
|
state.recordingState = wasActive ? "RecordingSession" : "Buffering";
|
|
console.error("Could not toggle desktop recording", error);
|
|
showNotice(`Could not toggle recording: ${String(error)}`);
|
|
render();
|
|
}
|
|
}
|
|
|
|
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.systemAudioEnabled = status.system_audio_enabled;
|
|
state.micEnabled = status.mic_enabled;
|
|
state.micDevice = status.mic_device ?? "";
|
|
state.autoRecordEnabled = status.auto_record_enabled;
|
|
state.autoUpload = status.upload_enabled;
|
|
state.uploadProvider = status.upload_provider;
|
|
state.catboxUserhash = status.catbox_userhash ?? "";
|
|
state.litterboxExpiryHours = validLitterboxExpiry(status.litterbox_expiry_hours);
|
|
state.customUploadEndpoint = status.custom_upload_endpoint ?? "";
|
|
state.customUploadResponsePath = status.custom_upload_response_url_path;
|
|
state.customUploadHeaders = status.custom_upload_headers.join("\n");
|
|
state.sessionRecording = status.session_recording;
|
|
state.captureActive = status.capture_active;
|
|
state.captureBackend = status.capture_backend;
|
|
state.capturePath = status.capture_path;
|
|
state.ffmpegAvailable = status.ffmpeg_available;
|
|
state.ffmpegPath = status.ffmpeg_path;
|
|
state.systemAudioAvailable = status.system_audio_available;
|
|
state.desktopDuplicationAvailable = status.desktop_duplication_available;
|
|
state.disabledGames = status.auto_clip_disabled_games ?? [];
|
|
for (const event of state.autoEvents) {
|
|
const enabled = status.auto_clip_enabled_events.find(
|
|
(candidate) => candidate.game_id === event.gameId && candidate.event_type === event.eventType,
|
|
);
|
|
if (enabled) {
|
|
event.enabled = enabled.enabled;
|
|
}
|
|
}
|
|
state.hotkeyClipLast60s = status.hotkey_clip_last_60s;
|
|
state.hotkeyClipLast30s = status.hotkey_clip_last_30s;
|
|
state.hotkeyToggleRecording = status.hotkey_toggle_session_recording;
|
|
state.hotkeyScreenshot = status.hotkey_screenshot;
|
|
state.freeDiskGb = status.free_disk_gb;
|
|
state.captureFps = status.capture_fps;
|
|
state.captureBitrateKbps = status.capture_bitrate_kbps;
|
|
state.captureResolution = status.capture_resolution;
|
|
state.storageLimitGb = status.storage_limit_gb;
|
|
state.clipDirectory = status.clip_directory ?? state.clipDirectory;
|
|
state.storageLimitExceeded = status.storage_limit_exceeded ?? false;
|
|
if (typeof status.auto_prune_old_clips === "boolean") {
|
|
state.autoPruneOldClips = status.auto_prune_old_clips;
|
|
}
|
|
state.excludedWindowTitles = status.excluded_window_titles ?? [];
|
|
state.excludedWindowText = (status.excluded_window_titles ?? []).join(", ");
|
|
state.separateAudioTracks = status.separate_audio_tracks ?? false;
|
|
state.appVersion = status.app_version ?? state.appVersion;
|
|
state.gameQualityOverrides = status.game_quality_overrides ?? [];
|
|
state.effectiveQualityApplied = status.effective_quality_applied ?? false;
|
|
if (typeof status.onboarding_complete === "boolean") {
|
|
state.onboardingComplete = status.onboarding_complete;
|
|
}
|
|
if (typeof status.minimize_to_tray === "boolean") {
|
|
state.minimizeToTray = status.minimize_to_tray;
|
|
}
|
|
}
|
|
|
|
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();
|
|
showNotice("Trimmed clip created");
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not trim clip", error);
|
|
showNotice(`Could not trim clip: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function trimClipFromModal() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
const clip = state.clips.find((candidate) => candidate.id === state.modal.clipId);
|
|
if (!clip) {
|
|
return;
|
|
}
|
|
|
|
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='modal-trim-start']");
|
|
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='modal-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();
|
|
showNotice("Trimmed clip created");
|
|
closeModal();
|
|
} catch (error) {
|
|
console.error("Could not trim clip", error);
|
|
showNotice(`Could not trim clip: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function saveSelectedClipMetadata() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
const title = appRoot.querySelector<HTMLInputElement>("[data-action='clip-title']")?.value ?? "";
|
|
const tags = (appRoot.querySelector<HTMLInputElement>("[data-action='clip-tags']")?.value ?? "")
|
|
.split(",")
|
|
.map((tag) => tag.trim())
|
|
.filter((tag) => tag.length > 0);
|
|
|
|
try {
|
|
const dto = await tauriInvoke<ClipDto>("update_clip_metadata", {
|
|
clipId: state.selectedClipId,
|
|
title,
|
|
tags,
|
|
});
|
|
const updated = clipFromDto(dto);
|
|
state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip));
|
|
showNotice("Clip info saved");
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not save clip info", error);
|
|
showNotice(`Could not save clip info: ${String(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);
|
|
showNotice(`Could not reveal clip: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function revealScreenshot(path: string) {
|
|
try {
|
|
await window.__TAURI__?.core?.invoke?.("reveal_screenshot", { path });
|
|
} catch (error) {
|
|
console.error("Could not reveal screenshot", error);
|
|
showNotice(`Could not reveal screenshot: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function revealCrashLogs() {
|
|
try {
|
|
await window.__TAURI__?.core?.invoke?.("reveal_crash_logs");
|
|
} catch (error) {
|
|
console.error("Could not reveal crash logs", error);
|
|
showNotice(`Could not reveal crash logs: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function uploadSelectedClip() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const dto = await tauriInvoke<ClipDto>("upload_clip", {
|
|
clipId: state.selectedClipId,
|
|
provider: state.uploadProvider,
|
|
customEndpoint: state.customUploadEndpoint,
|
|
customResponseUrlPath: state.customUploadResponsePath,
|
|
});
|
|
const updated = clipFromDto(dto);
|
|
state.clips = state.clips.map((clip) => (clip.id === updated.id ? updated : clip));
|
|
await refreshUploadHistory();
|
|
showNotice("Clip uploaded");
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not queue upload", error);
|
|
showNotice(`Could not upload clip: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function exportSelectedClip() {
|
|
if (!tauriInvoke || !state.selectedClipId) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const path = await tauriInvoke<string>("export_clip_copy", { clipId: state.selectedClipId });
|
|
showNotice(`Exported to ${path}`);
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not export clip", error);
|
|
showNotice(`Could not export clip: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function writeGsiConfigs() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const configs = await tauriInvoke<GsiConfigDto[]>("write_gsi_configs");
|
|
state.gsiConfigStatus = configs.map((config) => `${config.game_id}: ${config.path}`).join(" · ");
|
|
showNotice("GSI configs written");
|
|
render();
|
|
} catch (error) {
|
|
state.gsiConfigStatus = `Could not write GSI configs: ${String(error)}`;
|
|
render();
|
|
}
|
|
}
|
|
|
|
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 ?? "";
|
|
showNotice("Clip deleted");
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not delete clip", error);
|
|
showNotice(`Could not delete clip: ${String(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 ?? "";
|
|
}
|
|
}
|
|
|
|
async function saveReplayBufferSetting(seconds: number) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_replay_buffer", { seconds });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save replay buffer setting", error);
|
|
}
|
|
}
|
|
|
|
async function saveMicSetting(enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_mic_enabled", { enabled });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save mic setting", error);
|
|
}
|
|
}
|
|
|
|
async function saveSystemAudioSetting(enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_system_audio_enabled", { enabled });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save system audio setting", error);
|
|
}
|
|
}
|
|
|
|
async function saveMicDevice(device: string) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_mic_device", { device: device || null });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save mic device", error);
|
|
}
|
|
}
|
|
|
|
async function saveAutoRecordSetting(enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_auto_record_enabled", { enabled });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save auto-record setting", error);
|
|
}
|
|
}
|
|
|
|
async function saveMinimizeToTraySetting(enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_minimize_to_tray_enabled", { enabled });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save minimize-to-tray setting", error);
|
|
}
|
|
}
|
|
|
|
async function refreshStatus() {
|
|
if (!tauriInvoke || !state.onboardingComplete) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("refresh_detected_game");
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not refresh detected game", error);
|
|
}
|
|
}
|
|
|
|
async function refreshAudioDevices() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
state.audioDevices = await tauriInvoke<AudioDeviceDto[]>("list_audio_devices");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not load audio devices", error);
|
|
}
|
|
}
|
|
|
|
async function onClipSaved() {
|
|
if (!tauriInvoke || !state.onboardingComplete) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await refreshClips();
|
|
const newest = state.clips[0];
|
|
if (newest) {
|
|
state.selectedClipId = newest.id;
|
|
state.activeView = "Library";
|
|
render();
|
|
} else {
|
|
render();
|
|
}
|
|
} catch (error) {
|
|
console.warn("Could not refresh clips after save event", error);
|
|
}
|
|
}
|
|
|
|
async function onClipDeleted() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await refreshClips();
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not refresh clips after delete event", error);
|
|
}
|
|
}
|
|
|
|
async function saveUploadSettings() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_upload_settings", {
|
|
autoUploadEnabled: state.autoUpload,
|
|
provider: state.uploadProvider,
|
|
catboxUserhash: state.catboxUserhash || null,
|
|
litterboxExpiryHours: state.litterboxExpiryHours,
|
|
customEndpoint: state.customUploadEndpoint || null,
|
|
customResponseUrlPath: state.customUploadResponsePath,
|
|
customHeaders: state.customUploadHeaders
|
|
.split("\n")
|
|
.map((line) => line.trim())
|
|
.filter((line) => line.length > 0),
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice("Upload settings saved");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save upload settings", error);
|
|
showNotice(`Could not save upload settings: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function saveAutoClipEventSetting(eventRule: AutoEvent) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_auto_clip_event_enabled", {
|
|
gameId: eventRule.gameId,
|
|
eventType: eventRule.eventType,
|
|
enabled: eventRule.enabled,
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice("Auto-clip rule saved");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save auto-clip rule", error);
|
|
showNotice(`Could not save auto-clip rule: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function invokeSetGameAutoClipEnabled(gameId: string, enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_game_auto_clip_enabled", { gameId, enabled });
|
|
applyDesktopStatus(status);
|
|
showNotice(enabled ? "Auto-clipping enabled for game" : "Auto-clipping disabled for game");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not update per-game auto-clip setting", error);
|
|
showNotice(`Could not update per-game auto-clip setting: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function invokeAutoClipBulk(command: "enable_all_auto_clips" | "disable_all_auto_clips" | "restore_default_auto_clips") {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>(command);
|
|
applyDesktopStatus(status);
|
|
showNotice("Auto-clip rules updated");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not update auto-clip rules", error);
|
|
showNotice(`Could not update auto-clip rules: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function saveHotkeys() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_hotkeys", {
|
|
clip_last_60s: state.hotkeyClipLast60s,
|
|
clip_last_30s: state.hotkeyClipLast30s,
|
|
toggle_session_recording: state.hotkeyToggleRecording,
|
|
screenshot: state.hotkeyScreenshot,
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice("Hotkeys saved");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save hotkeys", error);
|
|
showNotice(`Could not save hotkeys: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function saveCaptureSettings() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
const [width, height] = parseResolution(state.captureResolution);
|
|
const excludedWindowTitles = state.excludedWindowText
|
|
.split(",")
|
|
.map((title) => title.trim())
|
|
.filter((title) => title.length > 0);
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_capture_settings", {
|
|
width,
|
|
height,
|
|
fps: state.captureFps,
|
|
bitrateKbps: state.captureBitrateKbps,
|
|
storageLimitGb: state.storageLimitGb,
|
|
excludedWindowTitles,
|
|
separateAudioTracks: state.separateAudioTracks,
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice("Capture settings saved. They will apply the next time capture starts.");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save capture settings", error);
|
|
showNotice(`Could not save capture settings: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function changeClipDirectory() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_clip_directory", {
|
|
clipDir: state.clipDirectory.trim(),
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice("Clip folder applied.");
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not set clip folder", error);
|
|
showNotice(`Could not set clip folder: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function setAutoPruneEnabled(enabled: boolean) {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_auto_prune_enabled", { enabled });
|
|
applyDesktopStatus(status);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not update auto-cleanup setting", error);
|
|
showNotice(`Could not update auto-cleanup setting: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
function parseResolution(value: string): [number, number] {
|
|
const [width, height] = value.split("x").map((part) => Number(part));
|
|
return [
|
|
Number.isFinite(width) ? width : 1280,
|
|
Number.isFinite(height) ? height : 720,
|
|
];
|
|
}
|
|
|
|
async function saveGameQualityOverride() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
if (state.detectedGame === "Waiting for game") {
|
|
return;
|
|
}
|
|
|
|
const preset =
|
|
appRoot.querySelector<HTMLSelectElement>("[data-action='override-preset']")?.value ?? "1280x720";
|
|
const fps = Number(appRoot.querySelector<HTMLSelectElement>("[data-action='override-fps']")?.value ?? 30);
|
|
const bitrate = Number(appRoot.querySelector<HTMLInputElement>("[data-action='override-bitrate']")?.value ?? 6000);
|
|
const [width, height] = parseResolution(preset);
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("set_game_quality_override", {
|
|
gameId: state.detectedGame,
|
|
name: `${preset} ${fps}fps`,
|
|
width,
|
|
height,
|
|
fps,
|
|
bitrateKbps: bitrate,
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice(`Quality override saved for ${state.detectedGame}.`);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not save quality override", error);
|
|
showNotice(`Could not save quality override: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function clearGameQualityOverride() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
if (state.detectedGame === "Waiting for game") {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("clear_game_quality_override", {
|
|
gameId: state.detectedGame,
|
|
});
|
|
applyDesktopStatus(status);
|
|
showNotice(`Quality override cleared for ${state.detectedGame}.`);
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not clear quality override", error);
|
|
showNotice(`Could not clear quality override: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function finishOnboarding() {
|
|
if (!tauriInvoke) {
|
|
state.onboardingComplete = true;
|
|
render();
|
|
return;
|
|
}
|
|
|
|
const systemAudio = document
|
|
.querySelector<HTMLInputElement>("[data-action='onboard-system-audio']")?.checked ?? state.systemAudioEnabled;
|
|
const mic = document
|
|
.querySelector<HTMLInputElement>("[data-action='onboard-mic']")?.checked ?? state.micEnabled;
|
|
const separate = document
|
|
.querySelector<HTMLInputElement>("[data-action='onboard-separate-tracks']")?.checked ?? state.separateAudioTracks;
|
|
const autoRecord = document
|
|
.querySelector<HTMLInputElement>("[data-action='onboard-auto-record']")?.checked ?? state.autoRecordEnabled;
|
|
const buffer = Number(
|
|
document.querySelector<HTMLSelectElement>("[data-action='onboard-buffer']")?.value ?? state.replayBufferSeconds,
|
|
);
|
|
const storage = Number(
|
|
document.querySelector<HTMLInputElement>("[data-action='onboard-storage']")?.value ?? state.storageLimitGb,
|
|
);
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("finish_onboarding", {
|
|
systemAudioEnabled: systemAudio,
|
|
micEnabled: mic,
|
|
separateAudioTracks: separate,
|
|
autoRecordEnabled: autoRecord,
|
|
replayBufferSeconds: buffer,
|
|
storageLimitGb: storage,
|
|
});
|
|
applyDesktopStatus(status);
|
|
state.onboardingStep = 0;
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not finish onboarding", error);
|
|
showNotice(`Could not finish setup: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function skipOnboarding() {
|
|
if (!tauriInvoke) {
|
|
state.onboardingComplete = true;
|
|
render();
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = await tauriInvoke<DesktopStatus>("finish_onboarding", {});
|
|
applyDesktopStatus(status);
|
|
state.onboardingStep = 0;
|
|
render();
|
|
} catch (error) {
|
|
console.warn("Could not skip onboarding", error);
|
|
showNotice(`Could not skip setup: ${String(error)}`);
|
|
}
|
|
}
|
|
|
|
async function checkForUpdates() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
state.update.applying = true;
|
|
state.update.message = "Checking for updates…";
|
|
render();
|
|
|
|
try {
|
|
const info = await tauriInvoke<{
|
|
update_available: boolean;
|
|
latest_version: string;
|
|
installer_file: string | null;
|
|
download_url: string | null;
|
|
message: string;
|
|
}>("check_for_updates");
|
|
state.update.checked = true;
|
|
state.update.updateAvailable = info.update_available;
|
|
state.update.latestVersion = info.latest_version;
|
|
state.update.installerFile = info.installer_file ?? "";
|
|
state.update.downloadUrl = info.download_url ?? "";
|
|
state.update.message = info.message;
|
|
} catch (error) {
|
|
console.warn("Could not check for updates", error);
|
|
state.update.message = `Could not check for updates: ${String(error)}`;
|
|
}
|
|
|
|
state.update.applying = false;
|
|
render();
|
|
}
|
|
|
|
async function downloadUpdate() {
|
|
if (!tauriInvoke || !state.update.downloadUrl || !state.update.installerFile) {
|
|
return;
|
|
}
|
|
|
|
state.update.applying = true;
|
|
state.update.message = "Downloading update…";
|
|
render();
|
|
|
|
try {
|
|
const message = await tauriInvoke<string>("download_and_apply_update", {
|
|
downloadUrl: state.update.downloadUrl,
|
|
installerFile: state.update.installerFile,
|
|
});
|
|
showNotice(message);
|
|
} catch (error) {
|
|
console.warn("Could not download the update", error);
|
|
state.update.applying = false;
|
|
state.update.message = `Could not download the update: ${String(error)}`;
|
|
render();
|
|
}
|
|
}
|
|
|
|
async function takeScreenshot() {
|
|
if (!tauriInvoke) {
|
|
return;
|
|
}
|
|
|
|
state.recordingState = "Processing";
|
|
render();
|
|
|
|
try {
|
|
await tauriInvoke("take_screenshot");
|
|
await refreshScreenshots();
|
|
showNotice("Screenshot saved");
|
|
render();
|
|
} catch (error) {
|
|
console.error("Could not take screenshot", error);
|
|
showNotice(`Could not take screenshot: ${String(error)}`);
|
|
render();
|
|
}
|
|
}
|
|
|
|
async function listScreenshots() {
|
|
if (!tauriInvoke) {
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
return await tauriInvoke<string[]>("list_screenshots");
|
|
} catch (error) {
|
|
console.warn("Could not list screenshots", error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
async function refreshScreenshots() {
|
|
const screenshots = await listScreenshots();
|
|
state.screenshots = screenshots;
|
|
}
|
|
|
|
async function refreshUploadHistory() {
|
|
if (!tauriInvoke) return;
|
|
try {
|
|
state.uploadHistory = await tauriInvoke<UploadHistoryEntry[]>("list_upload_history");
|
|
} catch (error) {
|
|
console.warn("Could not load upload history", error);
|
|
}
|
|
}
|
|
|
|
async function retryUpload(entry: UploadHistoryEntry) {
|
|
if (!tauriInvoke) return;
|
|
const clip = state.clips.find((c) => c.id === entry.clip_id);
|
|
if (!clip) {
|
|
showNotice(`Clip ${entry.clip_id} not found in library`);
|
|
return;
|
|
}
|
|
state.selectedClipId = clip.id;
|
|
state.activeView = "Library";
|
|
render();
|
|
await uploadSelectedClip();
|
|
}
|
|
|
|
function filteredClips() {
|
|
const query = state.libraryQuery.trim().toLowerCase();
|
|
return state.clips.filter((clip) => {
|
|
const matchesFilter =
|
|
state.libraryFilter === "all" ||
|
|
(state.libraryFilter === "kills" && clip.event.toLowerCase().includes("kill")) ||
|
|
(state.libraryFilter === "wins" && clip.event.toLowerCase().includes("win")) ||
|
|
(state.libraryFilter === "uploaded" && clip.uploadState === "Uploaded") ||
|
|
(state.libraryFilter === "failed" && clip.uploadState === "Failed");
|
|
if (!matchesFilter) {
|
|
return false;
|
|
}
|
|
if (!query) {
|
|
return true;
|
|
}
|
|
return [clip.title, clip.game, clip.event, clip.source, clip.uploadState, clip.path, ...clip.tags]
|
|
.join(" ")
|
|
.toLowerCase()
|
|
.includes(query);
|
|
});
|
|
}
|
|
|
|
function validLitterboxExpiry(value: number): AppState["litterboxExpiryHours"] {
|
|
return value === 1 || value === 12 || value === 24 || value === 72 ? value : 24;
|
|
}
|
|
|
|
function showNotice(message: string) {
|
|
state.notice = message;
|
|
window.setTimeout(() => {
|
|
if (state.notice === message) {
|
|
state.notice = "";
|
|
render();
|
|
}
|
|
}, 5_000);
|
|
}
|
|
|
|
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];
|
|
}
|
|
|
|
function formatDuration(seconds: number): string {
|
|
const hrs = Math.floor(seconds / 3600);
|
|
const mins = Math.floor((seconds % 3600) / 60);
|
|
const secs = Math.floor(seconds % 60);
|
|
if (hrs > 0) {
|
|
return `${hrs}:${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
|
|
}
|
|
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
}
|
|
|
|
function escapeHtml(value: string) {
|
|
return value
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """);
|
|
}
|
|
|
|
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 ?? "";
|
|
await refreshScreenshots();
|
|
await refreshUploadHistory();
|
|
render();
|
|
await refreshAudioDevices();
|
|
window.setInterval(() => {
|
|
void refreshStatus();
|
|
}, 3_000);
|
|
// Hotkey screenshots are taken behind Tauri's back, so keep a light poll to
|
|
// pick up new ones; clip/library changes arrive via backend events instead.
|
|
window.setInterval(() => {
|
|
void refreshScreenshots();
|
|
}, 5_000);
|
|
const listen = window.__TAURI__?.event?.listen;
|
|
if (listen) {
|
|
void listen("clip-saved", () => {
|
|
void onClipSaved();
|
|
});
|
|
void listen("clip-deleted", () => {
|
|
void onClipDeleted();
|
|
});
|
|
void listen("screenshots-changed", () => {
|
|
void refreshScreenshots();
|
|
});
|
|
}
|
|
|
|
window.addEventListener("keydown", (event) => {
|
|
if (event.key === "Escape" && state.modal.open) {
|
|
closeModal();
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.warn("Tauri bridge unavailable", error);
|
|
}
|
|
}
|
|
|
|
render();
|
|
void loadDesktopBridge();
|
|
|
|
|
|
|
|
|
|
|