redesign capture and settings
This commit is contained in:
@@ -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"
|
||||
]
|
||||
}
|
||||
+14
-2
@@ -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 {
|
||||
|
||||
@@ -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<Vec<u8>> {
|
||||
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,
|
||||
|
||||
+80
-59
@@ -181,34 +181,36 @@ pub struct HotkeyRegistrationResult {
|
||||
pub pause_ok: Option<bool>,
|
||||
}
|
||||
|
||||
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<Shortcut>) {
|
||||
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<SaveConfigResult, String> {
|
||||
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<Path
|
||||
Ok(out_path)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
fn preview_display(app: AppHandle, state: State<'_, AppState>, x: i32, y: i32) -> Result<tauri::ipc::Response, String> {
|
||||
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<Option<updates::UpdateInfo>, String> {
|
||||
updates::check_for_update().await.map_err(|error| format!("{error:#}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn list_windows() -> Vec<windows_list::WindowInfo> {
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user