nex_shift/src-tauri/src/capture.rs

638 lines
22 KiB
Rust
Raw Normal View History

use std::{
fs,
path::{Path, PathBuf},
};
use chrono::Local;
use image::GenericImageView;
use tauri::{AppHandle, Emitter, LogicalPosition, LogicalSize, Manager, State};
use crate::{
editor,
files::app_cache_dir,
models::{ActionOutcome, CaptureSessionInfo, CaptureSource, NormalizedRect},
result_card, settings, AppState,
};
#[cfg(target_os = "macos")]
#[link(name = "CoreGraphics", kind = "framework")]
extern "C" {
fn CGPreflightScreenCaptureAccess() -> bool;
fn CGRequestScreenCaptureAccess() -> bool;
}
#[cfg(target_os = "macos")]
fn ensure_screen_capture_access() -> Result<(), String> {
unsafe {
if screen_capture_access_allowed() || CGRequestScreenCaptureAccess() {
return Ok(());
}
}
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
Err("errScreenPermission".into())
}
#[cfg(not(target_os = "macos"))]
fn ensure_screen_capture_access() -> Result<(), String> {
Ok(())
}
#[cfg(target_os = "macos")]
fn screen_capture_access_allowed() -> bool {
unsafe { CGPreflightScreenCaptureAccess() }
}
#[cfg(not(target_os = "macos"))]
fn screen_capture_access_allowed() -> bool {
true
}
#[tauri::command]
pub fn screen_capture_access_status() -> bool {
screen_capture_access_allowed()
}
fn monitor_at_cursor(app: &AppHandle) -> Result<tauri::Monitor, String> {
let cursor = app.cursor_position().map_err(|error| error.to_string())?;
let monitors = app
.available_monitors()
.map_err(|error| error.to_string())?;
monitors
.into_iter()
.find(|monitor| {
let x = monitor.position().x as f64;
let y = monitor.position().y as f64;
cursor.x >= x
&& cursor.y >= y
&& cursor.x <= x + monitor.size().width as f64
&& cursor.y <= y + monitor.size().height as f64
})
.or_else(|| app.primary_monitor().ok().flatten())
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
.ok_or_else(|| "errNoMonitor".to_string())
}
fn capture_screen(app: &AppHandle, monitor: &tauri::Monitor) -> Result<CaptureSource, String> {
let directory = app_cache_dir(app)?;
let filename = format!("screen-{}.png", Local::now().format("%Y%m%d-%H%M%S-%3f"));
let output = directory.join(filename);
#[cfg(target_os = "macos")]
{
let scale = monitor.scale_factor();
let region = format!(
"{},{},{},{}",
(monitor.position().x as f64 / scale).round() as i64,
(monitor.position().y as f64 / scale).round() as i64,
(monitor.size().width as f64 / scale).round() as u32,
(monitor.size().height as f64 / scale).round() as u32,
);
2026-10-25 04:24:05 +00:00
let status = crate::process::command("/usr/sbin/screencapture")
.args([
"-x",
"-R",
&region,
"-t",
"png",
output.to_string_lossy().as_ref(),
])
.status()
.map_err(|error| format!("Could not launch screencapture: {error}"))?;
if !status.success() {
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errCaptureBlocked".into());
}
}
#[cfg(target_os = "windows")]
{
2026-10-25 04:24:05 +00:00
capture_windows_screen(monitor, &output)?;
}
#[cfg(target_os = "linux")]
{
let status = if let Some(grim) = crate::files::resolve_tool("grim") {
if let Some(name) = monitor.name() {
2026-10-25 04:24:05 +00:00
crate::process::command(grim)
.args(["-o", name, output.to_string_lossy().as_ref()])
.status()
} else {
2026-10-25 04:24:05 +00:00
crate::process::command(grim)
.arg(output.to_string_lossy().as_ref())
.status()
}
} else if let Some(gnome_screenshot) = crate::files::resolve_tool("gnome-screenshot") {
2026-10-25 04:24:05 +00:00
crate::process::command(gnome_screenshot)
.args(["-f", output.to_string_lossy().as_ref()])
.status()
} else {
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errCaptureToolMissing".into());
};
let status = status.map_err(|error| error.to_string())?;
if !status.success() {
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errCaptureFailed".into());
}
}
let (width, height) = match image::image_dimensions(&output) {
Ok(dimensions) => dimensions,
Err(error) => {
let _ = fs::remove_file(&output);
return Err(format!("Invalid capture: {error}"));
}
};
Ok(CaptureSource {
path: output.to_string_lossy().to_string(),
width,
height,
monitor_x: monitor.position().x as f64,
monitor_y: monitor.position().y as f64,
scale_factor: monitor.scale_factor(),
})
}
2026-10-25 04:24:05 +00:00
#[cfg(target_os = "windows")]
fn capture_windows_screen(monitor: &tauri::Monitor, output: &Path) -> Result<(), String> {
use windows_sys::Win32::Graphics::Gdi::{
BitBlt, CreateCompatibleBitmap, CreateCompatibleDC, DeleteDC, DeleteObject, GetDC,
GetDIBits, ReleaseDC, SelectObject, BITMAPINFO, BITMAPINFOHEADER, BI_RGB, CAPTUREBLT,
DIB_RGB_COLORS, HGDIOBJ, SRCCOPY,
};
use windows_sys::Win32::UI::HiDpi::{
SetThreadDpiAwarenessContext, DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2,
};
// Capture only the monitor under the cursor. Grabbing the virtual desktop
// would make a mixed-DPI or multi-monitor setup produce an image whose
// origin no longer matches the overlay window.
let x = monitor.position().x;
let y = monitor.position().y;
let width = monitor.size().width as i32;
let height = monitor.size().height as i32;
unsafe {
// Tauri's monitor bounds are physical pixels. Pin this worker thread
// to per-monitor-v2 while calling GDI; otherwise GetDC(NULL) may use a
// thread-scaled virtual desktop and the capture no longer aligns with
// the overlay.
let previous_awareness =
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
let restore_awareness = || {
if !previous_awareness.is_null() {
SetThreadDpiAwarenessContext(previous_awareness);
}
};
if width <= 0 || height <= 0 {
restore_awareness();
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errWinScreenSize".into());
2026-10-25 04:24:05 +00:00
}
let screen = GetDC(std::ptr::null_mut());
if screen.is_null() {
restore_awareness();
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errWinDesktopDC".into());
2026-10-25 04:24:05 +00:00
}
let memory = CreateCompatibleDC(screen);
let bitmap = CreateCompatibleBitmap(screen, width, height);
if memory.is_null() || bitmap.is_null() {
if !bitmap.is_null() {
DeleteObject(bitmap as HGDIOBJ);
}
if !memory.is_null() {
DeleteDC(memory);
}
ReleaseDC(std::ptr::null_mut(), screen);
restore_awareness();
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errWinSurfaceAlloc".into());
2026-10-25 04:24:05 +00:00
}
let previous = SelectObject(memory, bitmap as HGDIOBJ);
let copied = BitBlt(
memory,
0,
0,
width,
height,
screen,
x,
y,
SRCCOPY | CAPTUREBLT,
);
let mut info = BITMAPINFO {
bmiHeader: BITMAPINFOHEADER {
biSize: std::mem::size_of::<BITMAPINFOHEADER>() as u32,
biWidth: width,
// Negative height asks GDI for top-down rows, matching PNG.
biHeight: -height,
biPlanes: 1,
biBitCount: 32,
biCompression: BI_RGB,
biSizeImage: 0,
biXPelsPerMeter: 0,
biYPelsPerMeter: 0,
biClrUsed: 0,
biClrImportant: 0,
},
bmiColors: [windows_sys::Win32::Graphics::Gdi::RGBQUAD {
rgbBlue: 0,
rgbGreen: 0,
rgbRed: 0,
rgbReserved: 0,
}],
};
let mut pixels = vec![0_u8; width as usize * height as usize * 4];
let rows = GetDIBits(
memory,
bitmap,
0,
height as u32,
pixels.as_mut_ptr().cast(),
&mut info,
DIB_RGB_COLORS,
);
SelectObject(memory, previous);
DeleteObject(bitmap as HGDIOBJ);
DeleteDC(memory);
ReleaseDC(std::ptr::null_mut(), screen);
if copied == 0 || rows == 0 {
restore_awareness();
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errWinSurfaceCopy".into());
2026-10-25 04:24:05 +00:00
}
for pixel in pixels.chunks_exact_mut(4) {
pixel.swap(0, 2);
pixel[3] = 255;
}
let Some(image) = image::RgbaImage::from_raw(width as u32, height as u32, pixels) else {
restore_awareness();
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errWinSurfaceBuffer".into());
2026-10-25 04:24:05 +00:00
};
let result = image
.save_with_format(output, image::ImageFormat::Png)
.map_err(|error| format!("Could not save the screenshot: {error}"));
restore_awareness();
result
}
}
fn screenshot_directory(app: &AppHandle) -> Result<PathBuf, String> {
settings::screenshot_dir(app)
}
2026-10-27 10:45:32 +00:00
/// Freeze the screen and raise the overlay for one capture mode.
///
/// The Shift windows go down before the grab so the frozen frame holds nothing of
/// Shift, and come back whether the overlay ends in a file, a cancel, or a failure.
pub fn begin_capture(app: &AppHandle, mode: &str) -> Result<CaptureSessionInfo, String> {
ensure_screen_capture_access()?;
2026-10-27 10:45:32 +00:00
hide_shift_windows(app);
let result = begin_overlay(app, mode);
if result.is_err() {
// A capture that never reached the screen must not leave the panel hidden.
restore_windows(app);
}
2026-10-27 10:45:32 +00:00
result
}
fn begin_overlay(app: &AppHandle, mode: &str) -> Result<CaptureSessionInfo, String> {
std::thread::sleep(std::time::Duration::from_millis(90));
let monitor = monitor_at_cursor(app)?;
let source = capture_screen(app, &monitor)?;
let info = CaptureSessionInfo {
mode: mode.to_string(),
source: source.clone(),
};
let state = app.state::<AppState>();
*state.capture.lock().map_err(|error| error.to_string())? = Some(info.clone());
let window = app
.get_webview_window("capture")
.ok_or_else(|| "Capture window is unavailable.".to_string())?;
let scale = monitor.scale_factor();
window
.set_position(LogicalPosition::new(
monitor.position().x as f64 / scale,
monitor.position().y as f64 / scale,
))
.map_err(|error| error.to_string())?;
window
.set_size(LogicalSize::new(
monitor.size().width as f64 / scale,
monitor.size().height as f64 / scale,
))
.map_err(|error| error.to_string())?;
#[cfg(target_os = "macos")]
{
window
.set_simple_fullscreen(true)
.map_err(|error| error.to_string())?;
}
window.show().map_err(|error| error.to_string())?;
window.set_focus().map_err(|error| error.to_string())?;
2026-10-27 10:45:32 +00:00
// Showing the overlay is not the same as giving it the keyboard: see `focus_page`.
crate::focus_page(app, "capture");
window
.emit("capture://ready", info.clone())
.map_err(|error| error.to_string())?;
Ok(info)
}
2026-10-27 10:45:32 +00:00
/// True while a region recording is on screen. `recording::stop` holds the session
/// lock while it finishes the file and restores the windows, so this reads the HUD
/// rather than that mutex — locking it from here would self-deadlock.
fn recording_active(app: &AppHandle) -> bool {
app.get_webview_window("recorder")
.and_then(|window| window.is_visible().ok())
.unwrap_or(false)
}
/// The labels a capture clears off the screen, so the grab holds nothing of Shift.
const CAPTURE_COVERED: [&str; 3] = ["main", "radial", "editor"];
/// Hide the Shift windows, remembering which ones were open. Without that record a
/// capture could only guess on the way back, which is how "the panel was open, I
/// took a screenshot, and the panel is gone" happens.
fn hide_shift_windows(app: &AppHandle) {
let mut hidden = Vec::new();
for label in CAPTURE_COVERED {
if let Some(window) = app.get_webview_window(label) {
if window.is_visible().unwrap_or(false) {
hidden.push(label.to_string());
}
let _ = window.hide();
}
}
if let Some(state) = app.try_state::<AppState>() {
// Only a fresh capture writes the record. A second overlay raised on top of
// the first, or a shot taken mid-recording, must leave the pending one alone
// rather than trade the open panel for an empty list.
let overlay_up = app
.get_webview_window("capture")
.and_then(|window| window.is_visible().ok())
.unwrap_or(false);
if !overlay_up && !recording_active(app) {
if let Ok(mut restore) = state.capture_restore.lock() {
*restore = hidden;
}
}
}
}
/// Put back the windows this capture hid. Called when the capture overlay leaves,
/// whether the shot was taken, cancelled, or handed to the recorder.
pub fn restore_windows(app: &AppHandle) {
// Mid-recording the panel stays down, or it would appear inside the shot; the
// recorder restores it when the video is written.
if recording_active(app) {
return;
}
let Some(state) = app.try_state::<AppState>() else {
return;
};
let Ok(mut restore) = state.capture_restore.lock() else {
return;
};
let mut restored_main = false;
for label in restore.drain(..) {
restored_main |= label == "main";
if let Some(window) = app.get_webview_window(&label) {
let _ = window.show();
}
}
// The panel the capture came from is the thing the user was working in, so it
// takes the keyboard back. A result card or editor opened after this still
// focuses itself, so it wins when it is the more recent request.
if restored_main {
if let Some(window) = app.get_webview_window("main") {
let _ = window.set_focus();
crate::focus_page(app, "main");
}
}
}
pub fn crop_session(
app: &AppHandle,
state: &AppState,
rect: &NormalizedRect,
) -> Result<PathBuf, String> {
let session = state
.capture
.lock()
.map_err(|error| error.to_string())?
.clone()
.ok_or_else(|| "No capture session is active.".to_string())?;
let image = image::open(&session.source.path)
.map_err(|error| format!("Could not read the screenshot: {error}"))?;
let (width, height) = image.dimensions();
let x = (rect.x.clamp(0.0, 1.0) * width as f64).round() as u32;
let y = (rect.y.clamp(0.0, 1.0) * height as f64).round() as u32;
let crop_width = (rect.width.clamp(0.0, 1.0) * width as f64).round() as u32;
let crop_height = (rect.height.clamp(0.0, 1.0) * height as f64).round() as u32;
if crop_width < 2 || crop_height < 2 || x >= width || y >= height {
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
return Err("errNoSelection".into());
}
let cropped = image.crop_imm(x, y, crop_width.min(width - x), crop_height.min(height - y));
let directory = screenshot_directory(app)?;
let stem = format!("Shift-{}", Local::now().format("%Y%m%d-%H%M%S"));
let output = unique_capture_path(&directory, &stem)?;
cropped
.save_with_format(&output, image::ImageFormat::Png)
.map_err(|error| error.to_string())?;
Ok(output)
}
fn unique_capture_path(directory: &Path, stem: &str) -> Result<PathBuf, String> {
crate::files::unique_output_in(Path::new(stem), Some(directory), "", "png")
}
pub fn dismiss_capture(app: &AppHandle) {
2026-10-27 10:45:32 +00:00
close_overlay(app, true)
}
/// End the overlay but leave the panel hidden, for the recorder: a restored window
/// would land inside the region being filmed. `recording::stop` restores it instead.
pub fn dismiss_capture_for_recording(app: &AppHandle) {
close_overlay(app, false)
}
fn close_overlay(app: &AppHandle, restore: bool) {
let source = app
.try_state::<AppState>()
.and_then(|state| {
state
.capture
.lock()
.ok()
.and_then(|mut session| session.take())
})
.map(|session| session.source.path);
if let Some(window) = app.get_webview_window("capture") {
#[cfg(target_os = "macos")]
let _ = window.set_simple_fullscreen(false);
let _ = window.hide();
}
if let Some(path) = source {
let _ = fs::remove_file(path);
}
2026-10-27 10:45:32 +00:00
if restore {
restore_windows(app);
}
}
#[tauri::command]
pub fn get_capture_session(
state: State<'_, AppState>,
) -> Result<Option<CaptureSessionInfo>, String> {
Ok(state
.capture
.lock()
.map_err(|error| error.to_string())?
.clone())
}
2026-10-25 04:24:05 +00:00
/// Capture work runs off the main thread: freezing a screen, decoding the grab
/// and writing the crop all take longer than a frame budget.
#[tauri::command]
2026-10-25 04:24:05 +00:00
pub async fn start_capture(app: AppHandle, mode: String) -> Result<CaptureSessionInfo, String> {
tauri::async_runtime::spawn_blocking(move || begin_capture(&app, &mode))
.await
.map_err(|error| error.to_string())?
}
#[tauri::command]
pub fn cancel_capture(app: AppHandle) -> Result<(), String> {
dismiss_capture(&app);
Ok(())
}
#[tauri::command]
2026-10-25 04:24:05 +00:00
pub async fn capture_crop(app: AppHandle, rect: NormalizedRect) -> Result<String, String> {
tauri::async_runtime::spawn_blocking(move || {
let state = app.state::<AppState>();
finish_capture(&app, &state, &rect)
})
.await
.map_err(|error| error.to_string())?
}
fn finish_capture(
app: &AppHandle,
state: &AppState,
rect: &NormalizedRect,
) -> Result<String, String> {
let output = crop_session(app, state, rect)?;
{
use tauri_plugin_clipboard_manager::ClipboardExt;
if let Ok(image) = tauri::image::Image::from_path(&output) {
let _ = app.clipboard().write_image(&image);
}
}
dismiss_capture(app);
hand_off(app, &output);
crate::history::publish_result(
app,
ActionOutcome {
outputs: vec![output.to_string_lossy().to_string()],
feat(ui): spend the OCR button instead of explaining it, and unify how the app speaks Two changes, one goal: the same gesture and the same news should look and read the same way wherever they happen. Dropping a file OCR cannot read used to be answered after the fact - the drop ran, refused, and popped "文字识别仅支持图片格式". The user had to do the wrong thing first and then be told. Now the decision happens when the drag starts: MainWindow records the files in flight (`dragPaths`, from the native `enter` payload or from a Recent row's `dragstart`) and marks the button spent for the whole gesture with `is-drop-unavailable`, so the refusal is visible before the pointer is committed and releasing on it is inert and silent. Both drag sources were verified in a production build, including the reverse case: an image still lights the button and opens the editor. `over` carries no paths and `dataTransfer` is unreadable during `dragover`, so the paths have to be registered at the start - a later refactor that reads them from the move event gets nothing. The audit that followed found the same class of problem in the messaging, and worse: the app said one thing three ways. Prompts were the largest gap. A Rust-authored sentence reached the screen verbatim, so a Chinese interface answered Convert with `Saved 1 file.`, and macOS's first-run write-permission failure was one long English line. Rust now names the outcome or the failure (`outcomeSaved`, `errCaptureBlocked`) and the interface words it; `translate` still returns an unknown key unchanged, so genuine technical detail - `ffmpeg exited with status 137` - is reported as it is rather than flattened into a generic line. `feedback.test.ts` scans the Rust sources and fails on any code without wording in both languages, and on any outcome the worder does not know; both directions were checked by breaking them. It also asserts the two dictionaries list identical keys, which was silently false before. Durations were arbitrary: the identical share result showed for 2.6s in the ring and 3.6s in the main window, one file's `processing` message lived 12s in one branch and 120s in another, and generic errors used 2200/2400/3000/3200/3800. `FEEDBACK` is now the only ladder, and `hold` is reserved for tasks that report progress and must not expire mid-task. Error text had three normalisation idioms, two inside the same file; `messageFrom()` is the only one left. Share failures reported twice at once - a banner saying "could not send" plus a toast naming a different reason - and now report once, in the panel, with the real reason. The editor's failure notices wore a green check and lasted 1.4s; a clipboard refusal was silent, and an OCR failure printed into the text box as though it had been read from the image. Disabled controls were dimmed at nine different opacities across the app, three buttons were disabled in JS with no CSS at all, and several `:hover` rules answered a disabled control. `--dimmed` plus `cursor: default` and `:not(:disabled)` hovers is now the single treatment, and the OCR drop-target state joins it. Every transient message is a live region, three unlabeled icon buttons are named, Escape closes the settings sheet and the first-run panel, the main toast is raised above every sheet of its window, and nine raw px font sizes went back onto the type ladder. Out of scope, deliberately: the accent is still ~87 literals rather than one variable, and the muted warm greys are still written many ways. Both need a visual pass, not a search and replace.
2026-11-01 08:18:20 +00:00
message: "outcomeSaved".into(),
},
);
Ok(output.to_string_lossy().to_string())
}
feat(ui): drop onto a button, and read the panels again Three changes to the main window, requested together. A file drop is now aimed. The three buttons are the only drop targets and the button you release on is the action it runs; a release anywhere else on the panel runs nothing and says so, instead of opening an action ring nobody asked for. This replaces the old fallback in both delivery paths - the DOM handler and the native webview drop - because two routes to the same gesture must not have two different rules. dropFiles therefore takes a required action rather than an optional one, and the actions ring is still reachable from the Shift-drag gesture and from a file type with no convertible formats. Recent rows can be dragged back onto those buttons. A row leaves Shift as a real file drag, so one gesture can be reported twice, once by the DOM and once by the native events, and which arrives first depends on the engine; recentDrag.landed lets only the first through. The hint under the buttons names the affordance, which is otherwise invisible, and all three buttons light up as candidates for as long as any drag is in flight - a native one via dragging, an internal one via rowDragging, since a row drag inside the webview does not raise native events. Type sizes are on one ladder now (--text-3xs to --text-hero) instead of being invented per rule, which is how the settings drawer drifted down to 7-8px. 92 declarations under 12px became one. The drawer is wider, its tabs are pills, and the runtime, share, setup and radial surfaces moved onto the same scale. The capture-behaviour setting is removed: the CaptureAfter enum, its field, its command and its UI. A finished capture always shows the result card, falling back to the editor when a card window cannot be created. Stored settings that still carry captureAfter load unchanged, because the struct does not deny unknown fields. Also dropped 23 i18n keys no surface used, one dead re-export in history.ts, and a stale .home-drop p rule that was outranking the new hint and sizing it as body copy. tsconfig now turns on noUnusedLocals, noUnusedParameters and noFallthroughCasesInSwitch, which is what keeps the dead imports from coming back; the tree already passes all three.
2026-11-01 04:02:24 +00:00
/// Show the result card for a finished capture. The card is allowed to fail
/// silently: a screenshot that saved is more important than an overlay that could
/// not be built, and the file is already on disk and copied by then. The editor is
/// the fallback so a capture is never left with no way to act on it.
fn hand_off(app: &AppHandle, output: &Path) {
feat(ui): drop onto a button, and read the panels again Three changes to the main window, requested together. A file drop is now aimed. The three buttons are the only drop targets and the button you release on is the action it runs; a release anywhere else on the panel runs nothing and says so, instead of opening an action ring nobody asked for. This replaces the old fallback in both delivery paths - the DOM handler and the native webview drop - because two routes to the same gesture must not have two different rules. dropFiles therefore takes a required action rather than an optional one, and the actions ring is still reachable from the Shift-drag gesture and from a file type with no convertible formats. Recent rows can be dragged back onto those buttons. A row leaves Shift as a real file drag, so one gesture can be reported twice, once by the DOM and once by the native events, and which arrives first depends on the engine; recentDrag.landed lets only the first through. The hint under the buttons names the affordance, which is otherwise invisible, and all three buttons light up as candidates for as long as any drag is in flight - a native one via dragging, an internal one via rowDragging, since a row drag inside the webview does not raise native events. Type sizes are on one ladder now (--text-3xs to --text-hero) instead of being invented per rule, which is how the settings drawer drifted down to 7-8px. 92 declarations under 12px became one. The drawer is wider, its tabs are pills, and the runtime, share, setup and radial surfaces moved onto the same scale. The capture-behaviour setting is removed: the CaptureAfter enum, its field, its command and its UI. A finished capture always shows the result card, falling back to the editor when a card window cannot be created. Stored settings that still carry captureAfter load unchanged, because the struct does not deny unknown fields. Also dropped 23 i18n keys no surface used, one dead re-export in history.ts, and a stale .home-drop p rule that was outranking the new hint and sizing it as body copy. tsconfig now turns on noUnusedLocals, noUnusedParameters and noFallthroughCasesInSwitch, which is what keeps the dead imports from coming back; the tree already passes all three.
2026-11-01 04:02:24 +00:00
if result_card::show(app, output).is_err() {
let _ = editor::show_editor(app, output);
}
}
pub fn capture_fullscreen_core(app: &AppHandle, state: &AppState) -> Result<String, String> {
ensure_screen_capture_access()?;
2026-10-27 10:45:32 +00:00
hide_shift_windows(app);
std::thread::sleep(std::time::Duration::from_millis(90));
let monitor = monitor_at_cursor(app)?;
let source = capture_screen(app, &monitor)?;
*state.capture.lock().map_err(|error| error.to_string())? = Some(CaptureSessionInfo {
mode: "screenshot".into(),
source,
});
finish_capture(
app,
state,
&NormalizedRect {
x: 0.0,
y: 0.0,
width: 1.0,
height: 1.0,
},
)
}
#[tauri::command]
2026-10-25 04:24:05 +00:00
pub async fn capture_fullscreen(app: AppHandle) -> Result<String, String> {
let result = tauri::async_runtime::spawn_blocking(move || {
let state = app.state::<AppState>();
let result = capture_fullscreen_core(&app, &state);
if result.is_err() {
2026-10-27 10:45:32 +00:00
restore_windows(&app);
}
2026-10-25 04:24:05 +00:00
result
})
.await
.map_err(|error| error.to_string())?;
result
}
#[tauri::command]
2026-10-25 04:24:05 +00:00
pub async fn copy_file_to(source: String, destination: String) -> Result<(), String> {
tauri::async_runtime::spawn_blocking(move || {
fs::copy(Path::new(&source), Path::new(&destination))
.map(|_| ())
.map_err(|error| error.to_string())
})
.await
.map_err(|error| error.to_string())?
}
#[tauri::command]
2026-10-25 04:24:05 +00:00
pub async fn open_screen_recording_settings() -> Result<(), String> {
tauri::async_runtime::spawn_blocking(open_screen_recording_settings_sync)
.await
.map_err(|error| error.to_string())?
}
fn open_screen_recording_settings_sync() -> Result<(), String> {
#[cfg(target_os = "macos")]
{
2026-10-25 04:24:05 +00:00
let status = crate::process::command("/usr/bin/open")
.arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")
.status()
.map_err(|error| error.to_string())?;
if status.success() {
2026-10-27 10:45:32 +00:00
Ok(())
} else {
Err("Could not open Screen Recording settings.".into())
}
}
#[cfg(not(target_os = "macos"))]
{
Err("Screen Recording settings are macOS-specific.".into())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn two_captures_in_the_same_second_do_not_overwrite() {
let directory =
std::env::temp_dir().join(format!("shift-capture-name-{}", uuid::Uuid::new_v4()));
fs::create_dir_all(&directory).unwrap();
let stem = "Shift-20260101-120000";
let first = unique_capture_path(&directory, stem).unwrap();
fs::write(&first, b"first").unwrap();
let second = unique_capture_path(&directory, stem).unwrap();
assert_ne!(first, second);
assert_eq!(second.file_name().unwrap(), "Shift-20260101-120000 2.png");
assert_eq!(fs::read(&first).unwrap(), b"first");
fs::remove_dir_all(directory).ok();
}
}