2026-09-09 10:43:35 +02:00
import { convertFileSrc } from "@tauri-apps/api/core" ;
2026-09-09 10:21:29 +02:00
type RecordingState =
| "WaitingForGame"
| "Buffering"
| "RecordingSession"
| "Clipping"
| "Processing"
| "StorageLow" ;
2026-09-14 10:54:58 +02:00
type ClipSource = "Auto Event" | "Manual Hotkey" | "Bookmark" | "Imported" | "Screenshot" ;
2026-09-09 10:21:29 +02:00
type UploadState = "Local only" | "Uploaded" | "Failed" | "Queued" ;
2026-09-11 09:10:33 +02:00
type UploadProvider = "catbox" | "litterbox" | "custom_http" | "lustful" ;
2026-09-09 10:21:29 +02:00
type Clip = {
id : string ;
title : string ;
game : string ;
event : string ;
source : ClipSource ;
duration : string ;
createdAt : string ;
uploadState : UploadState ;
path : string ;
2026-09-09 10:43:35 +02:00
thumbnailPath : string | null ;
videoUrl : string | null ;
thumbnailUrl : string | null ;
2026-09-09 10:21:29 +02:00
tags : string [];
colorClass : string ;
};
type AutoEvent = {
id : string ;
2026-09-11 09:10:33 +02:00
gameId : string ;
eventType : string ;
2026-09-09 10:21:29 +02:00
game : string ;
event : string ;
enabled : boolean ;
};
2026-09-11 09:10:33 +02:00
type AutoClipEventDto = {
game_id : string ;
event_type : string ;
enabled : boolean ;
};
2026-09-09 10:21:29 +02:00
type DesktopStatus = {
recording_state : RecordingState ;
detected_game : string | null ;
replay_buffer_seconds : number ;
2026-09-10 13:55:32 +02:00
system_audio_enabled : boolean ;
2026-09-09 10:21:29 +02:00
mic_enabled : boolean ;
2026-09-10 08:38:02 +02:00
mic_device : string | null ;
2026-09-09 15:29:59 +02:00
auto_record_enabled : boolean ;
2026-09-09 10:21:29 +02:00
upload_enabled : boolean ;
2026-09-11 09:10:33 +02:00
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 [];
2026-09-09 10:21:29 +02:00
session_recording : boolean ;
capture_active : boolean ;
2026-09-10 08:52:03 +02:00
capture_backend : string | null ;
2026-09-09 10:21:29 +02:00
capture_path : string | null ;
clip_count : number ;
library_root : string ;
ffmpeg_available : boolean ;
ffmpeg_path : string | null ;
2026-09-09 15:27:30 +02:00
system_audio_available : boolean ;
2026-09-09 15:32:46 +02:00
desktop_duplication_available : boolean ;
2026-09-11 09:10:33 +02:00
auto_clip_enabled_events : AutoClipEventDto [];
2026-09-11 14:07:57 +02:00
hotkey_clip_last_60s : string ;
hotkey_clip_last_30s : string ;
hotkey_toggle_session_recording : string ;
hotkey_screenshot : string ;
2026-09-14 11:15:09 +02:00
free_disk_gb : number ;
2026-09-14 11:36:24 +02:00
capture_fps : number ;
capture_bitrate_kbps : number ;
capture_resolution : string ;
storage_limit_gb : number ;
excluded_window_titles : string [];
separate_audio_tracks : boolean ;
2026-09-14 12:08:31 +02:00
game_quality_overrides : GameQualityOverrideDto [];
effective_quality_applied : boolean ;
2026-09-14 11:51:40 +02:00
app_version : string ;
2026-09-09 10:21:29 +02:00
};
type ClipDto = {
id : string ;
title : string ;
game : string ;
event : string ;
source : ClipSource ;
duration : string ;
created_at : string ;
upload_state : UploadState ;
path : string ;
2026-09-09 10:43:35 +02:00
thumbnail_path : string | null ;
2026-09-09 10:21:29 +02:00
tags : string [];
color_class : string ;
};
2026-09-14 11:15:09 +02:00
type UploadHistoryEntry = {
id : number ;
clip_id : string ;
provider : string ;
status : string ;
url : string | null ;
error : string | null ;
attempted_at : string ;
};
2026-09-09 15:28:56 +02:00
type GsiConfigDto = {
game_id : string ;
path : string ;
};
2026-09-10 08:38:02 +02:00
type AudioDeviceDto = {
name : string ;
kind : "input" | "system_loopback" ;
};
2026-09-14 11:51:40 +02:00
type UpdateInfo = {
checked : boolean ;
updateAvailable : boolean ;
latestVersion : string ;
installerFile : string ;
downloadUrl : string ;
message : string ;
applying : boolean ;
};
2026-09-14 12:08:31 +02:00
type GameQualityOverrideDto = {
game_id : string ;
name : string ;
width : number ;
height : number ;
fps : number ;
bitrate_kbps : number ;
};
2026-09-09 10:21:29 +02:00
type AppState = {
activeView : "Library" | "Recording" | "Auto Clip" | "Uploads" | "Settings" ;
recordingState : RecordingState ;
detectedGame : string ;
replayBufferSeconds : number ;
2026-09-10 13:55:32 +02:00
systemAudioEnabled : boolean ;
2026-09-09 10:21:29 +02:00
sessionRecording : boolean ;
captureActive : boolean ;
2026-09-10 08:52:03 +02:00
captureBackend : string | null ;
2026-09-09 10:21:29 +02:00
capturePath : string | null ;
ffmpegAvailable : boolean ;
ffmpegPath : string | null ;
2026-09-09 15:27:30 +02:00
systemAudioAvailable : boolean ;
2026-09-09 15:32:46 +02:00
desktopDuplicationAvailable : boolean ;
2026-09-09 10:21:29 +02:00
micEnabled : boolean ;
2026-09-10 08:38:02 +02:00
micDevice : string ;
audioDevices : AudioDeviceDto [];
2026-09-09 15:29:59 +02:00
autoRecordEnabled : boolean ;
2026-09-09 10:21:29 +02:00
autoUpload : boolean ;
2026-09-11 09:10:33 +02:00
uploadProvider : UploadProvider ;
catboxUserhash : string ;
litterboxExpiryHours : 1 | 12 | 24 | 72 ;
2026-09-09 15:25:48 +02:00
customUploadEndpoint : string ;
customUploadResponsePath : string ;
2026-09-11 09:10:33 +02:00
customUploadHeaders : string ;
2026-09-09 15:28:56 +02:00
gsiConfigStatus : string ;
2026-09-11 09:10:33 +02:00
libraryFilter : "all" | "kills" | "wins" | "uploaded" | "failed" ;
libraryQuery : string ;
libraryViewMode : "grid" | "list" ;
notice : string ;
2026-09-09 10:21:29 +02:00
selectedClipId : string ;
clips : Clip [];
2026-09-14 10:54:58 +02:00
screenshots : string [];
2026-09-14 11:15:09 +02:00
uploadHistory : UploadHistoryEntry [];
2026-09-09 10:21:29 +02:00
autoEvents : AutoEvent [];
2026-09-11 14:07:57 +02:00
hotkeyClipLast60s : string ;
hotkeyClipLast30s : string ;
hotkeyToggleRecording : string ;
hotkeyScreenshot : string ;
2026-09-14 11:15:09 +02:00
freeDiskGb : number ;
2026-09-14 11:36:24 +02:00
captureFps : number ;
captureBitrateKbps : number ;
captureResolution : string ;
storageLimitGb : number ;
excludedWindowTitles : string [];
excludedWindowText : string ;
separateAudioTracks : boolean ;
2026-09-14 11:51:40 +02:00
appVersion : string ;
2026-09-14 12:08:31 +02:00
gameQualityOverrides : GameQualityOverrideDto [];
effectiveQualityApplied : boolean ;
2026-09-14 11:51:40 +02:00
update : UpdateInfo ;
2026-09-09 10:21:29 +02:00
};
type TauriGlobal = {
core ?: {
invoke ?: < T >( command : string , args? : Record < string , unknown >) => Promise < T >;
};
};
declare global {
interface Window {
__TAURI__? : TauriGlobal ;
__TAURI_INTERNALS__? : unknown ;
}
}
let tauriInvoke : (< T >( command : string , args? : Record < string , unknown >) => Promise < T >) | null = null ;
const state : AppState = {
2026-09-14 10:54:58 +02:00
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 : [],
2026-09-14 11:15:09 +02:00
screenshots : [],
uploadHistory : [],
autoEvents : [
2026-09-11 09:10:33 +02:00
{ 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 },
2026-09-11 15:58:16 +02:00
{ 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 },
2026-09-11 09:10:33 +02:00
{ 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 },
2026-09-11 15:58:16 +02:00
{ 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 },
2026-09-11 09:10:33 +02:00
{ 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 },
2026-09-11 15:58:16 +02:00
{ id : "dota-mvp" , gameId : "dota-2" , eventType : "mvp" , game : "Dota 2" , event : "MVP" , enabled : true },
2026-09-09 10:21:29 +02:00
],
2026-09-11 14:07:57 +02:00
hotkeyClipLast60s : "F8" ,
hotkeyClipLast30s : "Shift+F8" ,
hotkeyToggleRecording : "Alt+F7" ,
hotkeyScreenshot : "F9" ,
2026-09-14 11:15:09 +02:00
freeDiskGb : 0 ,
2026-09-14 11:36:24 +02:00
captureFps : 30 ,
captureBitrateKbps : 6000 ,
captureResolution : "1280x720" ,
storageLimitGb : 50 ,
excludedWindowTitles : [],
excludedWindowText : "" ,
separateAudioTracks : false ,
2026-09-14 11:51:40 +02:00
appVersion : "0.1.0" ,
2026-09-14 12:08:31 +02:00
gameQualityOverrides : [],
effectiveQualityApplied : false ,
2026-09-14 11:51:40 +02:00
update : {
checked : false ,
updateAvailable : false ,
latestVersion : "" ,
installerFile : "" ,
downloadUrl : "" ,
message : "Updates have not been checked yet." ,
applying : false ,
},
2026-09-09 10:21:29 +02:00
};
const root = document . querySelector < HTMLDivElement >( "#app" );
if ( ! root ) {
throw new Error ( "Missing #app root" );
}
const appRoot = root ;
function render() {
const selectedClip = state . clips . find (( clip ) => clip . id === state . selectedClipId ) ?? state . clips [ 0 ];
appRoot . innerHTML = `
<main class="app-shell">
<aside class="sidebar" aria-label="Primary">
<div class="brand">
<span class="brand-mark">CF</span>
<span>ClipForge</span>
</div>
<nav> ${ [ "Library" , "Recording" , "Auto Clip" , "Uploads" , "Settings" ]
. map (
( view ) => `
<button class="nav-item ${ state . activeView === view ? "active" : "" } " data-view=" ${ view } ">
${ view }
</button>
` ,
)
. join ( "" ) } </nav>
</aside>
<section class="workspace">
${ renderRecordingBar () }
2026-09-11 09:10:33 +02:00
${ state . notice ? `<div class="notice" role="status"> ${ escapeHtml ( state . notice ) } </div>` : "" }
2026-09-09 10:21:29 +02:00
${ renderActiveView ( selectedClip ) }
</section>
</main>
` ;
bindEvents ();
}
function renderRecordingBar() {
2026-09-14 11:15:09 +02:00
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` ;
2026-09-09 10:21:29 +02:00
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>
2026-09-14 11:15:09 +02:00
<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>` }
2026-09-09 10:21:29 +02:00
<button class="record-button" data-action="toggle-record"> ${ state . captureActive || state . sessionRecording ? "Stop" : "Record" } </button>
</header>
` ;
}
2026-09-10 14:00:50 +02:00
function renderActiveView ( selectedClip : Clip | undefined ) {
2026-09-09 10:21:29 +02:00
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 ) {
2026-09-14 10:54:58 +02:00
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 );
2026-09-09 10:21:29 +02:00
return `
2026-09-14 10:54:58 +02:00
<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="reveal-screenshot" data-screenshot-path=" ${ escapeHtml ( path ) } ">Open</button>
</div>
</article>
2026-09-09 10:21:29 +02:00
` ;
}
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 ,
2026-09-09 10:43:35 +02:00
thumbnailPath : dto.thumbnail_path ,
videoUrl : dto.path ? convertFileSrc ( dto . path ) : null ,
thumbnailUrl : dto.thumbnail_path ? convertFileSrc ( dto . thumbnail_path ) : null ,
2026-09-09 10:21:29 +02:00
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 } ">
2026-09-09 10:43:35 +02:00
<div class="thumb ${ clip . colorClass } ">
2026-09-11 09:10:33 +02:00
${ clip . thumbnailUrl ? `<img src=" ${ clip . thumbnailUrl } " alt="" />` : escapeHtml ( clip . event ) }
2026-09-09 10:43:35 +02:00
</div>
2026-09-11 09:10:33 +02:00
<h3> ${ escapeHtml ( clip . title ) } </h3>
<p> ${ escapeHtml ( clip . game ) } · ${ escapeHtml ( clip . source ) } · ${ escapeHtml ( clip . duration ) } </p>
2026-09-09 10:21:29 +02:00
</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>
` ;
}
2026-09-11 15:58:16 +02:00
const durationSeconds = parseTimestamp ( clip . duration );
const durationDisplay = formatDuration ( durationSeconds );
2026-09-09 10:21:29 +02:00
return `
<aside class="detail-panel">
2026-09-09 10:43:35 +02:00
<div class="preview">
${
clip . videoUrl
2026-09-11 15:58:16 +02:00
? `<video controls preload="metadata" src=" ${ clip . videoUrl } " poster=" ${ clip . thumbnailUrl ?? "" } " id="clip-preview"></video>`
2026-09-09 10:43:35 +02:00
: `<span>Preview</span>`
}
</div>
2026-09-11 09:10:33 +02:00
<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>
2026-09-11 15:58:16 +02:00
<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>
2026-09-09 10:21:29 +02:00
</div>
<div class="actions">
2026-09-11 09:10:33 +02:00
<button data-action="save-metadata">Save Info</button>
2026-09-09 10:21:29 +02:00
<button data-action="process">Trim</button>
<button data-action="reveal">Reveal</button>
2026-09-11 09:10:33 +02:00
<button data-action="export-copy">Export</button>
2026-09-09 10:21:29 +02:00
<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() {
2026-09-14 12:08:31 +02:00
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 ;
2026-09-09 10:21:29 +02:00
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>
2026-09-14 12:08:31 +02:00
<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>
2026-09-09 10:21:29 +02:00
<p class="muted">Lightweight desktop capture uses bundled FFmpeg when system FFmpeg is missing.</p>
2026-09-09 15:32:46 +02:00
<p class="muted"> ${ state . desktopDuplicationAvailable ? "Desktop Duplication capture available" : "Using GDI capture fallback" } </p>
2026-09-10 08:52:03 +02:00
<p class="muted"> ${ state . captureBackend ? `Active backend: ${ state . captureBackend } ` : "Active backend: idle" } </p>
2026-09-09 10:21:29 +02:00
<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>
2026-09-14 11:15:09 +02:00
<p class="muted"> ${ state . freeDiskGb > 0 ? ` ${ state . freeDiskGb . toFixed ( 1 ) } GB free on recording drive` : "Disk space unknown" } </p>
2026-09-09 10:21:29 +02:00
</article>
2026-09-14 12:08:31 +02:00
<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>
2026-09-09 10:21:29 +02:00
<article class="settings-panel">
<p class="eyebrow">Audio</p>
2026-09-09 15:27:30 +02:00
<h2> ${ state . systemAudioAvailable ? "System audio ready" : "System audio unavailable" } </h2>
2026-09-10 13:55:32 +02:00
<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>
2026-09-09 10:21:29 +02:00
<label class="toggle"><input type="checkbox" ${ state . micEnabled ? "checked" : "" } data-action="toggle-mic" /> Mic capture</label>
2026-09-10 08:38:02 +02:00
<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>
2026-09-09 10:21:29 +02:00
</article>
</section>
` ;
}
function renderAutoClipView() {
return `
<section class="table-panel">
<div class="section-heading">
<div>
<p class="eyebrow">Game events</p>
<h2>Auto Clip Rules</h2>
</div>
<div class="status-pill">Local APIs only</div>
</div>
<div class="event-list">
${ state . autoEvents
. map (
( event ) => `
<label class="event-row">
2026-09-11 09:10:33 +02:00
<span><strong> ${ escapeHtml ( event . game ) } </strong><small> ${ escapeHtml ( event . event ) } </small></span>
2026-09-09 10:21:29 +02:00
<input type="checkbox" ${ event . enabled ? "checked" : "" } data-event-id=" ${ event . id } " />
</label>
` ,
)
. join ( "" ) }
</div>
2026-09-09 15:28:56 +02:00
<div class="actions">
<button data-action="write-gsi-configs">Write GSI Configs</button>
</div>
${ state . gsiConfigStatus ? `<p class="muted file-path"> ${ state . gsiConfigStatus } </p>` : "" }
2026-09-09 10:21:29 +02:00
</section>
` ;
}
function renderUploadsView() {
2026-09-11 09:10:33 +02:00
const providers : Array < { id : UploadProvider ; title : string ; body : string } > = [
2026-09-09 15:25:48 +02:00
{ id : "catbox" , title : "Catbox" , body : "Anonymous or userhash-backed permanent uploads." },
2026-09-11 09:10:33 +02:00
{ id : "litterbox" , title : "Litterbox" , body : "Temporary uploads with a selectable expiry." },
2026-09-09 15:25:48 +02:00
{ 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." },
];
2026-09-09 10:21:29 +02:00
return `
<section class="settings-grid">
2026-09-09 15:25:48 +02:00
${ providers . map (( provider ) => `
2026-09-09 10:21:29 +02:00
<article class="settings-panel">
<p class="eyebrow">Provider</p>
2026-09-09 15:25:48 +02:00
<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>
2026-09-09 10:21:29 +02:00
</article>
` ). join ( "" ) }
2026-09-11 09:10:33 +02:00
<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>
2026-09-09 15:25:48 +02:00
<article class="settings-panel">
<p class="eyebrow">Custom HTTP</p>
<h2>Endpoint</h2>
2026-09-11 09:10:33 +02:00
<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>
2026-09-09 15:25:48 +02:00
</article>
2026-09-09 10:21:29 +02:00
</section>
2026-09-14 11:15:09 +02:00
<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>
2026-09-09 10:21:29 +02:00
` ;
}
function renderSettingsView() {
2026-09-14 11:36:24 +02:00
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 ];
2026-09-09 10:21:29 +02:00
return `
<section class="settings-grid">
<article class="settings-panel">
<p class="eyebrow">Privacy</p>
<h2>Local-first</h2>
2026-09-09 15:29:59 +02:00
<label class="toggle"><input type="checkbox" ${ state . autoRecordEnabled ? "checked" : "" } data-action="toggle-auto-record" /> Start recording when a supported game is detected</label>
2026-09-09 10:21:29 +02:00
<label class="toggle"><input type="checkbox" ${ state . autoUpload ? "checked" : "" } data-action="toggle-auto-upload" /> Auto-upload after clipping</label>
</article>
2026-09-14 11:36:24 +02:00
<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 (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>
2026-09-09 10:21:29 +02:00
<article class="settings-panel">
<p class="eyebrow">Storage</p>
2026-09-14 11:36:24 +02:00
<h2> ${ state . storageLimitGb } GB buffer cap</h2>
<p class="muted">Old temporary buffer segments are removed automatically once the buffer reaches the cap; saved clips are kept.</p>
2026-09-09 10:21:29 +02:00
</article>
2026-09-14 11:20:45 +02:00
<article class="settings-panel">
2026-09-14 11:51:40 +02:00
<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" : "" } >Check for updates</button>
` }
2026-09-14 11:20:45 +02:00
<button data-action="reveal-crash-logs">Reveal Crash Logs</button>
</article>
2026-09-09 10:21:29 +02:00
<article class="settings-panel">
<p class="eyebrow">Hotkeys</p>
2026-09-11 14:07:57 +02:00
<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>
2026-09-09 10:21:29 +02:00
</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 ();
});
});
2026-09-11 09:10:33 +02:00
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 ();
});
2026-09-09 10:21:29 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='clip']" ) ? . addEventListener ( "click" , () => {
void saveClip ();
});
2026-09-14 10:54:58 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='screenshot']" ) ? . addEventListener ( "click" , () => {
void takeScreenshot ();
});
2026-09-09 10:21:29 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='toggle-record']" ) ? . addEventListener ( "click" , () => {
void toggleRecording ();
});
appRoot . querySelector < HTMLButtonElement >( "[data-action='process']" ) ? . addEventListener ( "click" , () => {
void trimSelectedClip ();
});
2026-09-11 09:10:33 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='save-metadata']" ) ? . addEventListener ( "click" , () => {
void saveSelectedClipMetadata ();
});
2026-09-09 10:21:29 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='reveal']" ) ? . addEventListener ( "click" , () => {
void revealSelectedClip ();
});
appRoot . querySelector < HTMLButtonElement >( "[data-action='upload']" ) ? . addEventListener ( "click" , () => {
void uploadSelectedClip ();
});
2026-09-11 09:10:33 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='export-copy']" ) ? . addEventListener ( "click" , () => {
void exportSelectedClip ();
});
2026-09-09 15:28:56 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='write-gsi-configs']" ) ? . addEventListener ( "click" , () => {
void writeGsiConfigs ();
});
2026-09-09 10:21:29 +02:00
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 ();
});
2026-09-09 15:18:10 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='buffer-length']" ) ? . addEventListener ( "change" , ( event ) => {
void saveReplayBufferSetting ( Number (( event . target as HTMLInputElement ). value ));
});
2026-09-09 10:21:29 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='toggle-mic']" ) ? . addEventListener ( "change" , ( event ) => {
state . micEnabled = ( event . target as HTMLInputElement ). checked ;
render ();
2026-09-09 15:18:10 +02:00
void saveMicSetting ( state . micEnabled );
2026-09-09 10:21:29 +02:00
});
2026-09-10 13:55:32 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='toggle-system-audio']" ) ? . addEventListener ( "change" , ( event ) => {
state . systemAudioEnabled = ( event . target as HTMLInputElement ). checked ;
render ();
void saveSystemAudioSetting ( state . systemAudioEnabled );
});
2026-09-10 08:38:02 +02:00
appRoot . querySelector < HTMLSelectElement >( "[data-action='mic-device']" ) ? . addEventListener ( "change" , ( event ) => {
state . micDevice = ( event . target as HTMLSelectElement ). value ;
void saveMicDevice ( state . micDevice );
});
2026-09-09 10:21:29 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='toggle-auto-upload']" ) ? . addEventListener ( "change" , ( event ) => {
state . autoUpload = ( event . target as HTMLInputElement ). checked ;
render ();
2026-09-11 09:10:33 +02:00
void saveUploadSettings ();
2026-09-09 10:21:29 +02:00
});
2026-09-09 15:29:59 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='toggle-auto-record']" ) ? . addEventListener ( "change" , ( event ) => {
state . autoRecordEnabled = ( event . target as HTMLInputElement ). checked ;
render ();
void saveAutoRecordSetting ( state . autoRecordEnabled );
});
2026-09-09 15:25:48 +02:00
appRoot . querySelectorAll < HTMLButtonElement >( "[data-upload-provider]" ). forEach (( button ) => {
button . addEventListener ( "click" , () => {
2026-09-11 09:10:33 +02:00
state . uploadProvider = button . dataset . uploadProvider as UploadProvider ;
2026-09-09 15:25:48 +02:00
render ();
2026-09-11 09:10:33 +02:00
void saveUploadSettings ();
2026-09-09 15:25:48 +02:00
});
});
2026-09-11 09:10:33 +02:00
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 ();
});
2026-09-09 15:25:48 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='custom-upload-endpoint']" ) ? . addEventListener ( "input" , ( event ) => {
state . customUploadEndpoint = ( event . target as HTMLInputElement ). value ;
});
2026-09-11 09:10:33 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='custom-upload-endpoint']" ) ? . addEventListener ( "change" , () => {
void saveUploadSettings ();
});
2026-09-09 15:25:48 +02:00
appRoot . querySelector < HTMLInputElement >( "[data-action='custom-upload-response-path']" ) ? . addEventListener ( "input" , ( event ) => {
state . customUploadResponsePath = ( event . target as HTMLInputElement ). value ;
});
2026-09-11 09:10:33 +02:00
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 ();
});
2026-09-09 15:25:48 +02:00
2026-09-09 10:21:29 +02:00
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 ;
2026-09-11 09:10:33 +02:00
void saveAutoClipEventSetting ( eventRule );
2026-09-09 10:21:29 +02:00
}
});
});
2026-09-11 14:07:57 +02:00
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 ();
});
2026-09-11 15:58:16 +02:00
2026-09-14 11:36:24 +02:00
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 < 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 ();
});
2026-09-14 11:51:40 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='check-updates']" ) ? . addEventListener ( "click" , () => {
void checkForUpdates ();
});
2026-09-14 12:08:31 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='save-override']" ) ? . addEventListener ( "click" , () => {
void saveGameQualityOverride ();
});
appRoot . querySelector < HTMLButtonElement >( "[data-action='clear-override']" ) ? . addEventListener ( "click" , () => {
void clearGameQualityOverride ();
});
2026-09-14 11:51:40 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='download-update']" ) ? . addEventListener ( "click" , () => {
void downloadUpdate ();
});
2026-09-14 11:20:45 +02:00
appRoot . querySelector < HTMLButtonElement >( "[data-action='reveal-crash-logs']" ) ? . addEventListener ( "click" , () => {
void revealCrashLogs ();
});
2026-09-14 10:54:58 +02:00
appRoot . querySelectorAll < HTMLButtonElement >( "[data-action='reveal-screenshot']" ). forEach (( button ) => {
button . addEventListener ( "click" , () => {
const path = button . dataset . screenshotPath ;
if ( path ) {
void revealScreenshot ( path );
}
});
});
2026-09-14 11:15:09 +02:00
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 );
}
}
});
});
2026-09-11 15:58:16 +02:00
// 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 ));
}
};
2026-09-14 10:54:58 +02:00
const startDrag = ( handle : "start" | "end" ) => {
2026-09-11 15:58:16 +02:00
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 ();
2026-09-14 10:54:58 +02:00
startDrag ( "start" );
2026-09-11 15:58:16 +02:00
});
handleEnd . addEventListener ( "mousedown" , ( e ) => {
e . stopPropagation ();
2026-09-14 10:54:58 +02:00
startDrag ( "end" );
2026-09-11 15:58:16 +02:00
});
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 ();
}
2026-09-09 10:21:29 +02:00
}
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" ;
2026-09-11 09:10:33 +02:00
state . recordingState = "Processing" ;
await refreshClips ();
showNotice ( "Clip saved" );
2026-09-09 10:21:29 +02:00
render ();
return ;
} catch ( error ) {
console . error ( "Could not save desktop clip" , error );
2026-09-11 09:10:33 +02:00
showNotice ( `Could not save clip: ${ String ( error ) } ` );
2026-09-09 10:21:29 +02:00
}
}
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 : "" ,
2026-09-09 10:43:35 +02:00
thumbnailPath : null ,
videoUrl : null ,
thumbnailUrl : null ,
2026-09-09 10:21:29 +02:00
tags : [ "manual" ],
colorClass : "manual" ,
});
state . selectedClipId = state . clips [ 0 ]. id ;
state . activeView = "Library" ;
render ();
}
async function toggleRecording() {
if ( tauriInvoke ) {
try {
const status = await tauriInvoke < DesktopStatus >( state . captureActive ? "stop_capture" : "start_capture" );
applyDesktopStatus ( status );
await refreshClips ();
2026-09-11 09:10:33 +02:00
showNotice ( state . captureActive ? "Recording started" : "Recording stopped" );
2026-09-09 10:21:29 +02:00
render ();
return ;
} catch ( error ) {
console . error ( "Could not toggle desktop recording" , error );
2026-09-11 09:10:33 +02:00
showNotice ( `Could not toggle recording: ${ String ( error ) } ` );
2026-09-09 10:21:29 +02:00
}
}
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 ;
2026-09-10 13:55:32 +02:00
state . systemAudioEnabled = status . system_audio_enabled ;
2026-09-09 10:21:29 +02:00
state . micEnabled = status . mic_enabled ;
2026-09-10 08:38:02 +02:00
state . micDevice = status . mic_device ?? "" ;
2026-09-09 15:29:59 +02:00
state . autoRecordEnabled = status . auto_record_enabled ;
2026-09-09 10:21:29 +02:00
state . autoUpload = status . upload_enabled ;
2026-09-11 09:10:33 +02:00
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" );
2026-09-09 10:21:29 +02:00
state . sessionRecording = status . session_recording ;
state . captureActive = status . capture_active ;
2026-09-10 08:52:03 +02:00
state . captureBackend = status . capture_backend ;
2026-09-09 10:21:29 +02:00
state . capturePath = status . capture_path ;
state . ffmpegAvailable = status . ffmpeg_available ;
state . ffmpegPath = status . ffmpeg_path ;
2026-09-09 15:27:30 +02:00
state . systemAudioAvailable = status . system_audio_available ;
2026-09-09 15:32:46 +02:00
state . desktopDuplicationAvailable = status . desktop_duplication_available ;
2026-09-11 09:10:33 +02:00
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 ;
}
}
2026-09-11 14:07:57 +02:00
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 ;
2026-09-14 11:15:09 +02:00
state . freeDiskGb = status . free_disk_gb ;
2026-09-14 11:36:24 +02:00
state . captureFps = status . capture_fps ;
state . captureBitrateKbps = status . capture_bitrate_kbps ;
state . captureResolution = status . capture_resolution ;
state . storageLimitGb = status . storage_limit_gb ;
state . excludedWindowTitles = status . excluded_window_titles ?? [];
state . excludedWindowText = ( status . excluded_window_titles ?? []). join ( ", " );
2026-09-14 12:08:31 +02:00
state . separateAudioTracks = status . separate_audio_tracks ?? false ;
2026-09-14 11:51:40 +02:00
state . appVersion = status . app_version ?? state . appVersion ;
2026-09-14 12:08:31 +02:00
state . gameQualityOverrides = status . game_quality_overrides ?? [];
state . effectiveQualityApplied = status . effective_quality_applied ?? false ;
2026-09-09 10:21:29 +02:00
}
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 ();
2026-09-11 09:10:33 +02:00
showNotice ( "Trimmed clip created" );
2026-09-09 10:21:29 +02:00
render ();
} catch ( error ) {
console . error ( "Could not trim clip" , error );
2026-09-11 09:10:33 +02:00
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 ) } ` );
2026-09-09 10:21:29 +02:00
}
}
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 );
2026-09-11 09:10:33 +02:00
showNotice ( `Could not reveal clip: ${ String ( error ) } ` );
2026-09-09 10:21:29 +02:00
}
}
2026-09-14 10:54:58 +02:00
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 ) } ` );
}
}
2026-09-14 11:20:45 +02:00
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 ) } ` );
}
}
2026-09-09 10:21:29 +02:00
async function uploadSelectedClip() {
if ( ! tauriInvoke || ! state . selectedClipId ) {
return ;
}
try {
2026-09-09 15:25:48 +02:00
const dto = await tauriInvoke < ClipDto >( "upload_clip" , {
clipId : state.selectedClipId ,
provider : state.uploadProvider ,
customEndpoint : state.customUploadEndpoint ,
customResponseUrlPath : state.customUploadResponsePath ,
});
2026-09-09 10:21:29 +02:00
const updated = clipFromDto ( dto );
state . clips = state . clips . map (( clip ) => ( clip . id === updated . id ? updated : clip ));
2026-09-14 11:15:09 +02:00
await refreshUploadHistory ();
2026-09-11 09:10:33 +02:00
showNotice ( "Clip uploaded" );
2026-09-09 10:21:29 +02:00
render ();
} catch ( error ) {
console . error ( "Could not queue upload" , error );
2026-09-11 09:10:33 +02:00
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 ) } ` );
2026-09-09 10:21:29 +02:00
}
}
2026-09-09 15:28:56 +02:00
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 ( " · " );
2026-09-11 09:10:33 +02:00
showNotice ( "GSI configs written" );
2026-09-09 15:28:56 +02:00
render ();
} catch ( error ) {
state . gsiConfigStatus = `Could not write GSI configs: ${ String ( error ) } ` ;
render ();
}
}
2026-09-09 10:21:29 +02:00
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 ?? "" ;
2026-09-11 09:10:33 +02:00
showNotice ( "Clip deleted" );
2026-09-09 10:21:29 +02:00
render ();
} catch ( error ) {
console . error ( "Could not delete clip" , error );
2026-09-11 09:10:33 +02:00
showNotice ( `Could not delete clip: ${ String ( error ) } ` );
2026-09-09 10:21:29 +02:00
}
}
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 ?? "" ;
}
}
2026-09-09 15:18:10 +02:00
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 );
}
}
2026-09-10 13:55:32 +02:00
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 );
}
}
2026-09-10 08:38:02 +02:00
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 );
}
}
2026-09-09 15:29:59 +02:00
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 );
}
}
2026-09-09 10:45:52 +02:00
async function refreshStatus() {
if ( ! tauriInvoke ) {
return ;
}
try {
const status = await tauriInvoke < DesktopStatus >( "refresh_detected_game" );
applyDesktopStatus ( status );
render ();
} catch ( error ) {
console . warn ( "Could not refresh detected game" , error );
}
}
2026-09-10 08:38:02 +02:00
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 );
}
}
2026-09-09 15:13:48 +02:00
async function pollAutoClips() {
if ( ! tauriInvoke || ! state . captureActive ) {
return ;
}
try {
const clips = await tauriInvoke < ClipDto [] >( "poll_auto_clip_events" );
if ( clips . length === 0 ) {
return ;
}
const created = clips . map ( clipFromDto );
state . clips = [... created , ... state . clips . filter (( clip ) => ! created . some (( fresh ) => fresh . id === clip . id ))];
state . selectedClipId = created [ 0 ]. id ;
state . activeView = "Library" ;
render ();
} catch ( error ) {
console . warn ( "Could not poll auto clips" , error );
}
}
2026-09-11 09:10:33 +02:00
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 ) } ` );
}
}
2026-09-11 14:07:57 +02:00
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 ) } ` );
}
}
2026-09-14 11:36:24 +02:00
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 ) } ` );
}
}
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 ,
];
}
2026-09-14 12:08:31 +02:00
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 ) } ` );
}
}
2026-09-14 11:51:40 +02:00
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 ();
}
}
2026-09-14 10:54:58 +02:00
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() {
2026-09-14 11:15:09 +02:00
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 ();
2026-09-14 10:54:58 +02:00
}
2026-09-11 09:10:33 +02:00
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 );
}
2026-09-09 10:21:29 +02:00
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 ];
}
2026-09-11 15:58:16 +02:00
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" ) } ` ;
}
2026-09-10 08:38:02 +02:00
function escapeHtml ( value : string ) {
return value
. replace ( /&/g , "&" )
. replace ( /</g , "<" )
. replace ( />/g , ">" )
. replace ( /"/g , """ );
}
2026-09-09 10:21:29 +02:00
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 ?? "" ;
2026-09-14 10:54:58 +02:00
await refreshScreenshots ();
2026-09-14 11:15:09 +02:00
await refreshUploadHistory ();
2026-09-09 10:21:29 +02:00
render ();
2026-09-10 08:38:02 +02:00
await refreshAudioDevices ();
2026-09-09 10:45:52 +02:00
window . setInterval (() => {
void refreshStatus ();
}, 3 _000 );
2026-09-09 15:13:48 +02:00
window . setInterval (() => {
void pollAutoClips ();
}, 2 _000 );
2026-09-09 10:21:29 +02:00
} catch ( error ) {
console . warn ( "Tauri bridge unavailable" , error );
}
}
render ();
void loadDesktopBridge ();