diff --git a/src-tauri/capabilities/main-window.json b/src-tauri/capabilities/main-window.json new file mode 100644 index 0000000..d3a7dc6 --- /dev/null +++ b/src-tauri/capabilities/main-window.json @@ -0,0 +1,13 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "main-window", + "description": "Window controls for the main ByteSize title bar", + "windows": ["main"], + "permissions": [ + "core:window:allow-close", + "core:window:allow-minimize", + "core:window:allow-is-maximized", + "core:window:allow-toggle-maximize", + "core:window:allow-internal-toggle-maximize" + ] +} diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 1cfa746..15408c9 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -212,12 +212,24 @@ impl Config { } pub fn save(&self, path: &Path) -> Result<()> { + use std::io::Write; + let serialized = toml::to_string_pretty(self)?; if let Some(parent) = path.parent() { std::fs::create_dir_all(parent)?; } - std::fs::write(path, serialized)?; - Ok(()) + let staging = path.with_extension("toml.part"); + let result = (|| { + let mut file = std::fs::File::create(&staging)?; + file.write_all(serialized.as_bytes())?; + file.sync_all()?; + drop(file); + std::fs::rename(&staging, path) + })(); + if result.is_err() { + drop(std::fs::remove_file(&staging)); + } + result.map_err(Into::into) } pub fn needs_first_run(&self) -> bool { diff --git a/src-tauri/src/encode.rs b/src-tauri/src/encode.rs index 6f8e7cc..11f9673 100644 --- a/src-tauri/src/encode.rs +++ b/src-tauri/src/encode.rs @@ -1147,6 +1147,21 @@ pub(crate) fn extract_thumbnails( Ok(paths) } +pub(crate) fn display_preview(ffmpeg: &Path, x: i32, y: i32, width: u32, height: u32) -> Result> { + use std::os::windows::process::CommandExt; + const CREATE_NO_WINDOW: u32 = 0x0800_0000; + let output = Command::new(ffmpeg) + .creation_flags(CREATE_NO_WINDOW) + .args(["-hide_banner", "-loglevel", "error", "-f", "gdigrab", "-draw_mouse", "0"]) + .args(["-offset_x", &x.to_string(), "-offset_y", &y.to_string(), "-video_size", &format!("{width}x{height}")]) + .args(["-i", "desktop", "-frames:v", "1", "-vf", "scale=960:-2", "-c:v", "mjpeg", "-f", "image2pipe", "pipe:1"]) + .output().context("opening display preview")?; + if !output.status.success() || output.stdout.is_empty() { + bail!(ffmpeg_failure_message("display preview", output.status, &output.stderr)); + } + Ok(output.stdout) +} + pub(crate) fn mux_with_audio( ffmpeg: &Path, video: &Path, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5e36c5e..30edf14 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -181,34 +181,36 @@ pub struct HotkeyRegistrationResult { pub pause_ok: Option, } -fn register_hotkeys(app: &AppHandle, cfg: &Config) -> HotkeyRegistrationResult { +fn configured_hotkeys(config: &Config) -> [Option<&str>; 3] { + [ + config.hotkeys.start.as_deref(), + config.hotkeys.stop.as_deref(), + config.hotkeys.pause.as_deref(), + ] +} + +fn register_hotkeys(app: &AppHandle, cfg: &Config) -> (HotkeyRegistrationResult, Vec) { let gs = app.global_shortcut(); - drop(gs.unregister_all()); - - let start_ok = cfg - .hotkeys - .start - .as_deref() - .and_then(parse_shortcut) - .map(|sc| gs.register(sc).is_ok()); - let stop_ok = cfg - .hotkeys - .stop - .as_deref() - .and_then(parse_shortcut) - .map(|sc| gs.register(sc).is_ok()); - let pause_ok = cfg - .hotkeys - .pause - .as_deref() - .and_then(parse_shortcut) - .map(|sc| gs.register(sc).is_ok()); - - HotkeyRegistrationResult { - start_ok, - stop_ok, - pause_ok, - } + let mut added = Vec::new(); + let [start_ok, stop_ok, pause_ok] = configured_hotkeys(cfg).map(|input| { + input.map(|input| { + let Some(shortcut) = parse_shortcut(input) else { return false }; + if gs.is_registered(shortcut) { + return true; + } + match gs.register(shortcut) { + Ok(()) => { + added.push(shortcut); + true + } + Err(e) => { + tracing::warn!("could not register {input}: {e}"); + false + } + } + }) + }); + (HotkeyRegistrationResult { start_ok, stop_ok, pause_ok }, added) } #[derive(Serialize)] @@ -217,36 +219,13 @@ struct SaveConfigResult { } fn validate_config(config: &Config) -> Result<(), String> { - let mut keys = Vec::new(); - if let Some(k) = config - .hotkeys - .start - .as_deref() - .filter(|s| !s.trim().is_empty()) - { - keys.push(("start", k)); - } - if let Some(k) = config - .hotkeys - .stop - .as_deref() - .filter(|s| !s.trim().is_empty()) - { - keys.push(("stop", k)); - } - if let Some(k) = config - .hotkeys - .pause - .as_deref() - .filter(|s| !s.trim().is_empty()) - { - keys.push(("pause", k)); - } - for (i, (a, ka)) in keys.iter().enumerate() { - for (b, kb) in keys.iter().skip(i + 1) { - if ka.eq_ignore_ascii_case(kb) { - return Err(format!("duplicate hotkey: {a} and {b} both use {ka}")); + let mut seen = Vec::new(); + for input in configured_hotkeys(config).into_iter().flatten() { + if let Some(shortcut) = parse_shortcut(input) { + if seen.contains(&shortcut) { + return Err(format!("duplicate shortcut: {input}")); } + seen.push(shortcut); } } Ok(()) @@ -259,10 +238,33 @@ fn save_config( config: Config, ) -> Result { validate_config(&config)?; + let mut current = lock(&state.config); + let gs = app.global_shortcut(); + let (hotkey_result, added) = register_hotkeys(&app, &config); + let failed = [hotkey_result.start_ok, hotkey_result.stop_ok, hotkey_result.pause_ok] + .contains(&Some(false)); + if failed { + for shortcut in added { + drop(gs.unregister(shortcut)); + } + return Ok(SaveConfigResult { hotkey_result }); + } let path = config::config_path(&state.app_dir); - config.save(&path).map_err(|e| format!("{e:#}"))?; - *lock(&state.config) = config.clone(); - let hotkey_result = register_hotkeys(&app, &config); + if let Err(e) = config.save(&path) { + for shortcut in added { + drop(gs.unregister(shortcut)); + } + return Err(format!("{e:#}")); + } + let next = configured_hotkeys(&config).map(|input| input.and_then(parse_shortcut)); + for shortcut in configured_hotkeys(¤t).into_iter().flatten().filter_map(parse_shortcut) { + if !next.contains(&Some(shortcut)) { + if let Err(e) = gs.unregister(shortcut) { + tracing::warn!("could not unregister an old hotkey: {e}"); + } + } + } + *current = config; Ok(SaveConfigResult { hotkey_result }) } @@ -1149,6 +1151,18 @@ fn render_raw_preview(state: State<'_, AppState>, timestamp: f64) -> Result, x: i32, y: i32) -> Result { + let window = app.get_webview_window("main").ok_or_else(|| "main window is unavailable".to_string())?; + let screen = window.available_monitors().map_err(|error| error.to_string())? + .into_iter().find(|monitor| monitor.position().x == x && monitor.position().y == y) + .ok_or_else(|| "display is no longer available".to_string())?; + let size = screen.size(); + let png_or_jpeg = encode::display_preview(&bootstrap::ffmpeg_path(&state.app_dir), x, y, size.width, size.height) + .map_err(|error| format!("{error:#}"))?; + Ok(tauri::ipc::Response::new(png_or_jpeg)) +} + #[derive(Debug, Serialize)] pub struct ExportResult { pub output_path: PathBuf, @@ -1524,6 +1538,11 @@ fn enforce_overlay_aspect(app: AppHandle, state: State<'_, AppState>) -> Result< Ok(()) } +#[tauri::command] +async fn check_for_updates() -> Result, String> { + updates::check_for_update().await.map_err(|error| format!("{error:#}")) +} + #[tauri::command] fn list_windows() -> Vec { windows_list::list_visible_windows() @@ -2361,6 +2380,7 @@ pub fn run() { download_update, apply_update, pending_update, + check_for_updates, start_capture, pause_capture, resume_capture, @@ -2371,6 +2391,7 @@ pub fn run() { default_output_path, extract_thumbnails, render_preview, + preview_display, render_raw_preview, estimate_gif_params, estimate_gif_params_table, diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 51c056b..bea146c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -14,10 +14,11 @@ { "label": "main", "title": "ByteSize", - "width": 900, - "height": 600, + "width": 1120, + "height": 760, "minWidth": 600, "minHeight": 400, + "decorations": false, "resizable": true, "fullscreen": false }, diff --git a/src/App.svelte b/src/App.svelte index c6f9f76..5e1fd8e 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -11,6 +11,8 @@ type View = "loading" | "bootstrap" | "first-run" | "main" | "settings" let view: View = $state("loading") + let updatesOpen = $state(false) + let updateCheck = $state(0) async function refresh() { view = "loading" @@ -35,29 +37,26 @@ onMount(refresh) - - -
+ + + diff --git a/src/lib/Bootstrap.svelte b/src/lib/Bootstrap.svelte index e1c36fd..91f6fd8 100644 --- a/src/lib/Bootstrap.svelte +++ b/src/lib/Bootstrap.svelte @@ -1,4 +1,6 @@ -
-
-
- -
encoder setup
+ + {#if phase === "downloading"} +
+ + {progress ? formatBytes(progress.downloaded) + (progress.total ? " of " + formatBytes(progress.total) : " downloaded") : "Connecting..."}
- - {#if phase === "idle"} -
-

- ByteSize needs ffmpeg to encode video. Download is ~30 MB and verified against a published SHA-256 checksum. -

- -

- Already have ffmpeg? Drop ffmpeg.exe into the bin/ folder, then - . -

-
- - {:else if phase === "downloading"} -
-

Downloading ffmpeg

- {#if progress?.total} -
-
-
-

- {formatBytes(progress.downloaded)} / {formatBytes(progress.total)} -

- {:else if progress} -

{formatBytes(progress.downloaded)} downloaded

- {:else} -

Connecting

- {/if} -
- - {:else} -
- - {#if errMsg}
{errMsg}
{/if} - - -
+ {:else if phase === "error" && errMsg} + + {:else} +
Install to.\bin\ffmpeg.exe
+ {/if} + {#snippet actions()} + {#if phase !== "downloading"} + + {/if} -
-
- - + {/snippet} + diff --git a/src/lib/FirstRun.svelte b/src/lib/FirstRun.svelte index 0b89c8d..1cfd61d 100644 --- a/src/lib/FirstRun.svelte +++ b/src/lib/FirstRun.svelte @@ -1,4 +1,5 @@ -
-
-
- -
assign your hotkeys
-
- -
-

- No defaults are shipped. Pick combos that work for you - you can change these later in settings. -

- -
- - - -
- - {#if warnings.length > 0} - - {/if} - - - -

Click a field, press your combo. Escape to cancel.

-
+ +
+
Start recording
+
Stop recording
+
Pause / resume
+ {#if warnings.length}{/if}
-
+ {#snippet actions()} + + {/snippet} + diff --git a/src/lib/HotkeyInput.svelte b/src/lib/HotkeyInput.svelte index 41a02b8..570dd20 100644 --- a/src/lib/HotkeyInput.svelte +++ b/src/lib/HotkeyInput.svelte @@ -1,10 +1,12 @@
- {#if value && !capturing} - + {/if}
diff --git a/src/lib/Loading.svelte b/src/lib/Loading.svelte index 4a387ae..81ed150 100644 --- a/src/lib/Loading.svelte +++ b/src/lib/Loading.svelte @@ -1,44 +1,5 @@ -
-
- - - -
-
- - + diff --git a/src/lib/Main.svelte b/src/lib/Main.svelte index 8f466e7..e889478 100644 --- a/src/lib/Main.svelte +++ b/src/lib/Main.svelte @@ -1,8 +1,19 @@ -
- -
-
- BYTESIZE -
-
- - - {phaseLabel} - - {#if clip && (phase === "editing" || phase === "exporting" || phase === "done")} - {clip.width}x{clip.height} · {clip.duration_secs.toFixed(2)}s - {/if} - {#if phase === "recording" || phase === "paused"} - {elapsed.toFixed(1)}s - {/if} -
-
- -
-
+ { phase = "editing" } : undefined} + {onSettings} disabled={settingsLocked || sourcePending} /> - -
- - {#if phase === "idle"} -
- -

- {#if useFrame} - Drag the frame to position your capture region - {:else} - Captures the full primary monitor + +

+ {#if phase === "idle" || phase === "recording" || phase === "paused"} +
+
+
+
+

{phase === "paused" ? "Recording paused" : phase === "recording" ? "Recording in progress" : frameOpen ? "Capture frame" : "New recording"}

+

+ {phase !== "idle" ? sourceLabel : frameOpen ? "Move the desktop frame by its grip or resize it from a corner." + : source === "display" ? "Record the entire primary display." : "Only the area inside the frame is recorded."} +

+
+ {#if frameOpen && phase === "idle"} + {/if} -

+
+
+
+ {source === "display" ? "Primary display" : currentMonitor?.name || "Display"} +
+ {#if currentMonitor}{currentMonitor.size.width} × {currentMonitor.size.height}{/if} + {#if phase === "idle" && currentMonitor}{/if} +
+
+
+ {#if currentImage}Display snapshot{/if} + {#if source !== "display" && frameRect && currentMonitor} + {@const stages = currentMonitor} +
+ {frameRect.width} × {frameRect.height} +
+ {:else if !currentImage} +
+ + {captureDimensions ? captureDimensions.width + " × " + captureDimensions.height : "Primary display"} +
+ {/if} +
+
+
-
- - - {#if useFrame} -
- {#each PRESETS as [w, h, label]} - +
- - - {:else if phase === "recording" || phase === "paused"} -
-
- {elapsed.toFixed(1)} - seconds -
- - {#if audioWarning} - - {:else if config?.capture.capture_audio} -
- - audio + {:else} +
+ {phase === "recording" ? "Recording" : "Paused"} + {timecode(elapsed)} +

{sourceLabel}{captureDimensions ? ", " + captureDimensions.width + " × " + captureDimensions.height : ""}

+
+ {#if audioWarning} + + {:else} +
System audio

{!captureOptions?.capture_audio ? "Audio is off for this clip." : phase === "paused" ? "Audio will resume with video." : "Audio is being recorded."}

+ {/if} +
+ +
{/if} - -
- - {#if phase === "recording"} - - {:else} - - {/if} -
-
- - + +
{:else if phase === "editing" && clip}
@@ -719,8 +900,8 @@
- {/if} - + {/if} +
{#if showDiscardConfirm}
@@ -732,332 +913,13 @@
{/if} - +{#if errMsg} + +{/if} - - {#if errMsg} - - {/if} -
- - diff --git a/src/lib/Settings.svelte b/src/lib/Settings.svelte index 1b305cc..d4ab647 100644 --- a/src/lib/Settings.svelte +++ b/src/lib/Settings.svelte @@ -1,15 +1,21 @@ -
-
-
- -

Settings

-
-
- - {#if cfg} -
- - - - -
- {#if activeTab === "capture"} -
-
-

Capture

-

Recording behavior and defaults

-
-
- - - {#if cfg.capture.limit_capture_fps} -

- Recording stops at {cfg.capture.default_fps} fps instead of the display's refresh - rate. Smaller temp files and less CPU, but nothing above that rate is captured. -

- {/if} - - - -
-
- - {:else if activeTab === "export"} -
-
-

Export

-

Default format and encoding options

-
-
- - - - - {#if showAdvanced} - - - - {#if codecs && (!codecs.av1 || !codecs.h265)} -

Some codecs are unavailable in your ffmpeg build and disabled above.

- {/if} - {/if} -
-
- - {:else if activeTab === "hotkeys"} -
-
-

Hotkeys

-

Global keyboard shortcuts

-
-
- - - -
-
- - {:else if activeTab === "output"} -
-
-

Output

-

Where exported files are saved

-
-
- -
-
- - {:else if activeTab === "system"} -
-
-

System

-

Appearance and updates

-
-
- - -
-
- - {:else if activeTab === "diagnostics"} -
-
-

Diagnostics

-

Versions and recent log output

-
-
-
- ByteSize - {diagnostics ? `v${diagnostics.app_version}` : "..."} -
-
- ffmpeg - {diagnostics ? diagnostics.ffmpeg_version : "..."} -
-
- Log folder - {diagnostics ? diagnostics.log_dir : "..."} - -
-
-
- Recent log - -
-
{diagnostics ? diagnostics.log_tail || "(empty)" : "loading..."}
+ + +{#if cfg} +
+ + {#key activeTab} +
+
+

{TABS.find(tab => tab.id === activeTab)?.label}

+

{descriptions[activeTab]}

+
+
+ {#if activeTab === "capture"} +
Export frame rate

Preselected when you finish a recording.

+
Limit capture frame rate

Record at the selected rate instead of the display rate.

+
Resolution

Auto caps the longest side at 1920 px.

+
Record mouse pointer
+
Record system audio
+ {:else if activeTab === "export"} +
Default format

Preselected when you finish a recording.

+
Advanced encoding +
+
GIF dithering
+
MP4 codec
+
WebM codec
+
+ {:else if activeTab === "hotkeys"} +
Start recording
+
Stop recording
+
Pause / resume
+ {:else if activeTab === "output"} +
+ { cfg!.output_dir = e.currentTarget.value.trim() || null }} disabled={saving} />
-
- {/if} - - {#if hotkeyWarnings.length > 0} - + {#if hotkeyWarnings.length} + {/if} +
-
- {/if} -
+ {/key} + +{/if} + diff --git a/src/lib/UpdateBanner.svelte b/src/lib/UpdateBanner.svelte index 310d942..a791646 100644 --- a/src/lib/UpdateBanner.svelte +++ b/src/lib/UpdateBanner.svelte @@ -1,150 +1,107 @@ -{#if info || phase === "ready"} -