config and ffmpeg bootstrap
This commit is contained in:
Generated
+1764
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -11,8 +11,8 @@
|
|||||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.11.1",
|
"@tauri-apps/api": "^2.11.0",
|
||||||
"@tauri-apps/plugin-dialog": "^2.0.0"
|
"@tauri-apps/plugin-dialog": "^2.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
||||||
|
|||||||
Generated
+5970
File diff suppressed because it is too large
Load Diff
@@ -4,30 +4,34 @@ version = "0.1.0"
|
|||||||
description = "Portable Windows screen-to-clip recorder"
|
description = "Portable Windows screen-to-clip recorder"
|
||||||
authors = ["lashman <lashman@robotbrush.com>"]
|
authors = ["lashman <lashman@robotbrush.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.95"
|
rust-version = "1.94"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "bytesize_lib"
|
name = "bytesize_lib"
|
||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "2.11", features = [] }
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2.11", features = [] }
|
tauri = { version = "2.11", features = [] }
|
||||||
tauri-plugin-dialog = "2.11"
|
tauri-plugin-dialog = "2"
|
||||||
windows-capture = "1.5"
|
windows-capture = "2.0"
|
||||||
tokio = { version = "1.47", features = ["full"] }
|
tokio = { version = "1.47", features = ["full"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
reqwest = { version = "0.13", default-features = false, features = ["rustls-tls", "stream"] }
|
reqwest = { version = "0.13", default-features = false, features = ["native-tls", "stream"] }
|
||||||
|
futures-util = "0.3"
|
||||||
image = "0.25"
|
image = "0.25"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["fmt"] }
|
tracing-subscriber = { version = "0.3", features = ["fmt"] }
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
|
hex = "0.4"
|
||||||
|
sevenz-rust2 = "0.21"
|
||||||
|
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["custom-protocol"]
|
default = ["custom-protocol"]
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
+211
-1
@@ -1 +1,211 @@
|
|||||||
// first-run ffmpeg download, sha256 verification, extraction into ./bin/
|
use std::fs::{self, File};
|
||||||
|
use std::io::{self, Cursor};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
|
use futures_util::StreamExt;
|
||||||
|
use serde::Serialize;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum FfmpegStatus {
|
||||||
|
Ready,
|
||||||
|
Missing,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bin_dir(app_dir: &Path) -> PathBuf {
|
||||||
|
app_dir.join("bin")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ffmpeg_path(app_dir: &Path) -> PathBuf {
|
||||||
|
bin_dir(app_dir).join("ffmpeg.exe")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check(app_dir: &Path) -> FfmpegStatus {
|
||||||
|
if ffmpeg_path(app_dir).is_file() {
|
||||||
|
FfmpegStatus::Ready
|
||||||
|
} else {
|
||||||
|
FfmpegStatus::Missing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ArchiveKind {
|
||||||
|
SevenZ,
|
||||||
|
Zip,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Source {
|
||||||
|
name: &'static str,
|
||||||
|
archive_url: &'static str,
|
||||||
|
checksum_url: &'static str,
|
||||||
|
kind: ArchiveKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
const SOURCES: &[Source] = &[
|
||||||
|
Source {
|
||||||
|
name: "GyanD",
|
||||||
|
archive_url: "https://github.com/GyanD/codexffmpeg/releases/download/8.1.1/ffmpeg-8.1.1-essentials_build.7z",
|
||||||
|
checksum_url: "https://github.com/GyanD/codexffmpeg/releases/download/8.1.1/ffmpeg-8.1.1-essentials_build.7z.sha256",
|
||||||
|
kind: ArchiveKind::SevenZ,
|
||||||
|
},
|
||||||
|
Source {
|
||||||
|
name: "BtbN",
|
||||||
|
archive_url: "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip",
|
||||||
|
checksum_url: "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip.sha256",
|
||||||
|
kind: ArchiveKind::Zip,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
pub async fn download<F>(app_dir: &Path, mut on_progress: F) -> Result<()>
|
||||||
|
where
|
||||||
|
F: FnMut(u64, Option<u64>) + Send,
|
||||||
|
{
|
||||||
|
let bin = bin_dir(app_dir);
|
||||||
|
fs::create_dir_all(&bin).context("creating ./bin/")?;
|
||||||
|
let dest = bin.join("ffmpeg.exe");
|
||||||
|
|
||||||
|
let mut last_err: Option<anyhow::Error> = None;
|
||||||
|
for source in SOURCES {
|
||||||
|
match try_source(source, &dest, &mut on_progress).await {
|
||||||
|
Ok(()) => {
|
||||||
|
tracing::info!("ffmpeg installed via {}", source.name);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!("source {} failed: {e:#}", source.name);
|
||||||
|
last_err = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(last_err.unwrap_or_else(|| anyhow!("no ffmpeg source succeeded")))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn try_source<F>(source: &Source, dest: &Path, on_progress: &mut F) -> Result<()>
|
||||||
|
where
|
||||||
|
F: FnMut(u64, Option<u64>),
|
||||||
|
{
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.user_agent(concat!("ByteSize/", env!("CARGO_PKG_VERSION")))
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let expected = fetch_sha256(&client, source.checksum_url)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("fetching checksum from {}", source.checksum_url))?;
|
||||||
|
|
||||||
|
let archive = download_verified(&client, source.archive_url, &expected, on_progress)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("downloading archive from {}", source.archive_url))?;
|
||||||
|
|
||||||
|
match source.kind {
|
||||||
|
ArchiveKind::SevenZ => extract_ffmpeg_from_7z(&archive, dest)?,
|
||||||
|
ArchiveKind::Zip => extract_ffmpeg_from_zip(&archive, dest)?,
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_sha256(client: &reqwest::Client, url: &str) -> Result<[u8; 32]> {
|
||||||
|
let body = client
|
||||||
|
.get(url)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.error_for_status()?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
let hex_str = body
|
||||||
|
.split_whitespace()
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| anyhow!("empty checksum file"))?;
|
||||||
|
let bytes = hex::decode(hex_str).context("checksum is not valid hex")?;
|
||||||
|
if bytes.len() != 32 {
|
||||||
|
bail!("checksum length is {} bytes, expected 32", bytes.len());
|
||||||
|
}
|
||||||
|
let mut sha = [0u8; 32];
|
||||||
|
sha.copy_from_slice(&bytes);
|
||||||
|
Ok(sha)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_verified<F>(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
url: &str,
|
||||||
|
expected: &[u8; 32],
|
||||||
|
on_progress: &mut F,
|
||||||
|
) -> Result<Vec<u8>>
|
||||||
|
where
|
||||||
|
F: FnMut(u64, Option<u64>),
|
||||||
|
{
|
||||||
|
let resp = client.get(url).send().await?.error_for_status()?;
|
||||||
|
let total = resp.content_length();
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
let mut buf: Vec<u8> = Vec::with_capacity(total.unwrap_or(0) as usize);
|
||||||
|
let mut downloaded = 0u64;
|
||||||
|
let mut stream = resp.bytes_stream();
|
||||||
|
while let Some(chunk) = stream.next().await {
|
||||||
|
let chunk = chunk?;
|
||||||
|
hasher.update(&chunk);
|
||||||
|
buf.extend_from_slice(&chunk);
|
||||||
|
downloaded += chunk.len() as u64;
|
||||||
|
on_progress(downloaded, total);
|
||||||
|
}
|
||||||
|
let got: [u8; 32] = hasher.finalize().into();
|
||||||
|
if &got != expected {
|
||||||
|
bail!(
|
||||||
|
"sha256 mismatch: expected {} got {}",
|
||||||
|
hex::encode(expected),
|
||||||
|
hex::encode(got)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_ffmpeg_entry(name: &str) -> bool {
|
||||||
|
let normalized: String = name
|
||||||
|
.chars()
|
||||||
|
.map(|c| if c == '\\' { '/' } else { c })
|
||||||
|
.collect();
|
||||||
|
normalized
|
||||||
|
.rsplit('/')
|
||||||
|
.next()
|
||||||
|
.map(|leaf| leaf.eq_ignore_ascii_case("ffmpeg.exe"))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_ffmpeg_from_7z(archive: &[u8], dest: &Path) -> Result<()> {
|
||||||
|
let reader = Cursor::new(archive);
|
||||||
|
let mut extracted = false;
|
||||||
|
let scratch = std::env::temp_dir();
|
||||||
|
sevenz_rust2::decompress_with_extract_fn(reader, scratch, |entry, src, _| {
|
||||||
|
if extracted || entry.is_directory() {
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
if is_ffmpeg_entry(entry.name()) {
|
||||||
|
let mut out = File::create(dest)?;
|
||||||
|
io::copy(src, &mut out)?;
|
||||||
|
extracted = true;
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
})
|
||||||
|
.map_err(|e| anyhow!("7z extraction failed: {e}"))?;
|
||||||
|
if !extracted {
|
||||||
|
bail!("ffmpeg.exe not found inside the 7z archive");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_ffmpeg_from_zip(archive: &[u8], dest: &Path) -> Result<()> {
|
||||||
|
let reader = Cursor::new(archive);
|
||||||
|
let mut zip = zip::ZipArchive::new(reader).context("open zip archive")?;
|
||||||
|
for i in 0..zip.len() {
|
||||||
|
let mut entry = zip.by_index(i)?;
|
||||||
|
if entry.is_dir() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let name = entry.name().to_string();
|
||||||
|
if is_ffmpeg_entry(&name) {
|
||||||
|
let mut out = File::create(dest).context("create ffmpeg.exe")?;
|
||||||
|
io::copy(&mut entry, &mut out).context("write ffmpeg.exe from zip")?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bail!("ffmpeg.exe not found inside the zip archive");
|
||||||
|
}
|
||||||
|
|||||||
+145
-1
@@ -1 +1,145 @@
|
|||||||
// TOML config load/save - state lives in ./config.toml next to the exe
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
#[serde(default)]
|
||||||
|
pub export: ExportConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub capture: CaptureConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub hotkeys: HotkeyConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub updates: UpdatesConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub output_dir: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ExportConfig {
|
||||||
|
pub default_format: Format,
|
||||||
|
pub gif_dither: GifDither,
|
||||||
|
pub webm_codec: WebmCodec,
|
||||||
|
pub mp4_codec: Mp4Codec,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct CaptureConfig {
|
||||||
|
pub default_fps: u32,
|
||||||
|
pub capture_cursor: bool,
|
||||||
|
pub capture_audio: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
|
pub struct HotkeyConfig {
|
||||||
|
pub start: Option<String>,
|
||||||
|
pub stop: Option<String>,
|
||||||
|
pub pause: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct UpdatesConfig {
|
||||||
|
pub check_on_launch: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum Format {
|
||||||
|
Gif,
|
||||||
|
Webm,
|
||||||
|
Mp4,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum GifDither {
|
||||||
|
FloydSteinberg,
|
||||||
|
Bayer,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum WebmCodec {
|
||||||
|
Vp9,
|
||||||
|
Av1,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum Mp4Codec {
|
||||||
|
H264,
|
||||||
|
H265,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
export: ExportConfig::default(),
|
||||||
|
capture: CaptureConfig::default(),
|
||||||
|
hotkeys: HotkeyConfig::default(),
|
||||||
|
updates: UpdatesConfig::default(),
|
||||||
|
output_dir: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ExportConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
default_format: Format::Gif,
|
||||||
|
gif_dither: GifDither::FloydSteinberg,
|
||||||
|
webm_codec: WebmCodec::Vp9,
|
||||||
|
mp4_codec: Mp4Codec::H264,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CaptureConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
default_fps: 30,
|
||||||
|
capture_cursor: true,
|
||||||
|
capture_audio: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for UpdatesConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { check_on_launch: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn load_or_create(path: &Path) -> Result<Self> {
|
||||||
|
if !path.exists() {
|
||||||
|
let cfg = Self::default();
|
||||||
|
cfg.save(path)?;
|
||||||
|
return Ok(cfg);
|
||||||
|
}
|
||||||
|
let raw = std::fs::read_to_string(path)?;
|
||||||
|
Ok(toml::from_str(&raw)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save(&self, path: &Path) -> Result<()> {
|
||||||
|
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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn needs_first_run(&self) -> bool {
|
||||||
|
self.hotkeys.start.is_none()
|
||||||
|
|| self.hotkeys.stop.is_none()
|
||||||
|
|| self.hotkeys.pause.is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn config_path(app_dir: &Path) -> PathBuf {
|
||||||
|
app_dir.join("config.toml")
|
||||||
|
}
|
||||||
|
|||||||
+91
-1
@@ -3,10 +3,100 @@ mod capture;
|
|||||||
mod config;
|
mod config;
|
||||||
mod encode;
|
mod encode;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use serde::Serialize;
|
||||||
|
use tauri::{AppHandle, Emitter, State};
|
||||||
|
|
||||||
|
use crate::bootstrap::FfmpegStatus;
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
|
pub struct AppState {
|
||||||
|
pub app_dir: PathBuf,
|
||||||
|
pub config: Mutex<Config>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exe_dir() -> Result<PathBuf> {
|
||||||
|
let exe = std::env::current_exe()?;
|
||||||
|
Ok(exe
|
||||||
|
.parent()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("exe has no parent directory"))?
|
||||||
|
.to_path_buf())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct AppStatus {
|
||||||
|
ffmpeg: FfmpegStatus,
|
||||||
|
needs_first_run: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_status(state: State<'_, AppState>) -> AppStatus {
|
||||||
|
let cfg = state.config.lock().expect("config mutex");
|
||||||
|
AppStatus {
|
||||||
|
ffmpeg: bootstrap::check(&state.app_dir),
|
||||||
|
needs_first_run: cfg.needs_first_run(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_config(state: State<'_, AppState>) -> Config {
|
||||||
|
state.config.lock().expect("config mutex").clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn save_config(state: State<'_, AppState>, config: Config) -> Result<(), String> {
|
||||||
|
let path = config::config_path(&state.app_dir);
|
||||||
|
config.save(&path).map_err(|e| format!("{e:#}"))?;
|
||||||
|
*state.config.lock().expect("config mutex") = config;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
|
struct DownloadProgress {
|
||||||
|
downloaded: u64,
|
||||||
|
total: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
|
||||||
|
let app_dir = state.app_dir.clone();
|
||||||
|
let app_handle = app.clone();
|
||||||
|
bootstrap::download(&app_dir, move |downloaded, total| {
|
||||||
|
let _ = app_handle.emit(
|
||||||
|
"ffmpeg-progress",
|
||||||
|
DownloadProgress { downloaded, total },
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("{e:#}"))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
let app_dir = exe_dir().expect("resolve exe directory");
|
||||||
|
let cfg_path = config::config_path(&app_dir);
|
||||||
|
let cfg = Config::load_or_create(&cfg_path).expect("load or create config.toml");
|
||||||
|
|
||||||
|
tracing::info!(?app_dir, "starting ByteSize");
|
||||||
|
|
||||||
|
let state = AppState {
|
||||||
|
app_dir,
|
||||||
|
config: Mutex::new(cfg),
|
||||||
|
};
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.invoke_handler(tauri::generate_handler![])
|
.manage(state)
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
get_status,
|
||||||
|
get_config,
|
||||||
|
save_config,
|
||||||
|
download_ffmpeg,
|
||||||
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running ByteSize")
|
.expect("error while running ByteSize")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": false,
|
||||||
"targets": "none",
|
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
]
|
]
|
||||||
|
|||||||
+34
-56
@@ -1,61 +1,39 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let recording = $state(false)
|
import { onMount } from "svelte"
|
||||||
|
import { api, type AppStatus } from "./lib/api"
|
||||||
|
import Loading from "./lib/Loading.svelte"
|
||||||
|
import Bootstrap from "./lib/Bootstrap.svelte"
|
||||||
|
import FirstRun from "./lib/FirstRun.svelte"
|
||||||
|
import Main from "./lib/Main.svelte"
|
||||||
|
|
||||||
function toggle() {
|
type View = "loading" | "bootstrap" | "first-run" | "main"
|
||||||
recording = !recording
|
|
||||||
|
let view: View = $state("loading")
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
view = "loading"
|
||||||
|
let status: AppStatus
|
||||||
|
try {
|
||||||
|
status = await api.getStatus()
|
||||||
|
} catch (e) {
|
||||||
|
console.error("get_status failed", e)
|
||||||
|
view = "bootstrap"
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if (status.ffmpeg === "missing") view = "bootstrap"
|
||||||
|
else if (status.needs_first_run) view = "first-run"
|
||||||
|
else view = "main"
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(refresh)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
{#if view === "loading"}
|
||||||
<header>
|
<Loading />
|
||||||
<h1>ByteSize</h1>
|
{:else if view === "bootstrap"}
|
||||||
<p>screen-to-clip recorder</p>
|
<Bootstrap onReady={refresh} />
|
||||||
</header>
|
{:else if view === "first-run"}
|
||||||
|
<FirstRun onDone={refresh} />
|
||||||
<section class="controls">
|
{:else}
|
||||||
<button onclick={toggle} class:active={recording}>
|
<Main />
|
||||||
{recording ? "stop" : "start"}
|
{/if}
|
||||||
</button>
|
|
||||||
</section>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
main {
|
|
||||||
padding: 1.5rem;
|
|
||||||
max-width: 480px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
header h1 {
|
|
||||||
margin: 0 0 0.25rem;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
letter-spacing: -0.01em;
|
|
||||||
}
|
|
||||||
|
|
||||||
header p {
|
|
||||||
margin: 0 0 1.5rem;
|
|
||||||
color: #888;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.controls {
|
|
||||||
display: flex;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
font: inherit;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border: 1px solid currentColor;
|
|
||||||
background: transparent;
|
|
||||||
color: inherit;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.active {
|
|
||||||
background: #c33;
|
|
||||||
border-color: #c33;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { api, formatBytes, type DownloadProgress } from "./api"
|
||||||
|
|
||||||
|
let { onReady }: { onReady: () => void } = $props()
|
||||||
|
|
||||||
|
type Phase = "idle" | "downloading" | "error"
|
||||||
|
let phase: Phase = $state("idle")
|
||||||
|
let progress: DownloadProgress | null = $state(null)
|
||||||
|
let errMsg: string | null = $state(null)
|
||||||
|
|
||||||
|
async function start() {
|
||||||
|
phase = "downloading"
|
||||||
|
errMsg = null
|
||||||
|
progress = null
|
||||||
|
const unlisten = await api.onFfmpegProgress((p) => {
|
||||||
|
progress = p
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
await api.downloadFfmpeg()
|
||||||
|
unlisten()
|
||||||
|
onReady()
|
||||||
|
} catch (e) {
|
||||||
|
unlisten()
|
||||||
|
errMsg = String(e)
|
||||||
|
phase = "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<header>
|
||||||
|
<h1>ByteSize</h1>
|
||||||
|
<p class="sub">set up encoder</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{#if phase === "idle"}
|
||||||
|
<p>
|
||||||
|
ByteSize needs ffmpeg to encode video. The download is around 30 MB and
|
||||||
|
is verified against a published SHA-256 checksum.
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<button class="primary" onclick={start}>download ffmpeg</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint">
|
||||||
|
Already have ffmpeg? Drop <code>ffmpeg.exe</code> into the
|
||||||
|
<code>bin/</code> folder next to the app, then click below.
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<button onclick={onReady}>i added it manually</button>
|
||||||
|
</div>
|
||||||
|
{:else if phase === "downloading"}
|
||||||
|
<p>downloading ffmpeg...</p>
|
||||||
|
<progress
|
||||||
|
value={progress?.downloaded ?? 0}
|
||||||
|
max={progress?.total ?? undefined}
|
||||||
|
></progress>
|
||||||
|
<p class="hint">
|
||||||
|
{#if progress && progress.total}
|
||||||
|
{formatBytes(progress.downloaded)} / {formatBytes(progress.total)}
|
||||||
|
{:else if progress}
|
||||||
|
{formatBytes(progress.downloaded)} downloaded
|
||||||
|
{/if}
|
||||||
|
</p>
|
||||||
|
{:else}
|
||||||
|
<p class="err">download failed</p>
|
||||||
|
<pre>{errMsg}</pre>
|
||||||
|
<div class="row">
|
||||||
|
<button onclick={start}>retry</button>
|
||||||
|
<button onclick={onReady}>i added it manually</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main {
|
||||||
|
padding: 2rem;
|
||||||
|
max-width: 560px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
header h1 {
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
.sub {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0 0 1.5rem;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
code {
|
||||||
|
background: #2a2a2a;
|
||||||
|
padding: 0.1rem 0.35rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
|
progress {
|
||||||
|
width: 100%;
|
||||||
|
height: 8px;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
background: #2a2a2a;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #ec9a9a;
|
||||||
|
}
|
||||||
|
.err {
|
||||||
|
color: #ec9a9a;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
font: inherit;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border: 1px solid #444;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
border-color: #888;
|
||||||
|
}
|
||||||
|
button.primary {
|
||||||
|
background: #4a8;
|
||||||
|
border-color: #4a8;
|
||||||
|
color: #111;
|
||||||
|
}
|
||||||
|
button.primary:hover {
|
||||||
|
background: #5b9;
|
||||||
|
border-color: #5b9;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { api } from "./api"
|
||||||
|
|
||||||
|
let { onDone }: { onDone: () => void } = $props()
|
||||||
|
|
||||||
|
let start = $state("")
|
||||||
|
let stop = $state("")
|
||||||
|
let pause = $state("")
|
||||||
|
let saving = $state(false)
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
saving = true
|
||||||
|
try {
|
||||||
|
const cfg = await api.getConfig()
|
||||||
|
cfg.hotkeys.start = start.trim() || null
|
||||||
|
cfg.hotkeys.stop = stop.trim() || null
|
||||||
|
cfg.hotkeys.pause = pause.trim() || null
|
||||||
|
await api.saveConfig(cfg)
|
||||||
|
onDone()
|
||||||
|
} finally {
|
||||||
|
saving = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let valid = $derived(start.trim() && stop.trim() && pause.trim())
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<header>
|
||||||
|
<h1>ByteSize</h1>
|
||||||
|
<p class="sub">assign your hotkeys</p>
|
||||||
|
</header>
|
||||||
|
<p>
|
||||||
|
ByteSize doesn't ship default hotkeys. Pick combinations that won't clash
|
||||||
|
with apps you use. You can change these later in settings.
|
||||||
|
</p>
|
||||||
|
<div class="form">
|
||||||
|
<label>
|
||||||
|
<span>start</span>
|
||||||
|
<input bind:value={start} placeholder="e.g. F9" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>stop</span>
|
||||||
|
<input bind:value={stop} placeholder="e.g. F9" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>pause</span>
|
||||||
|
<input bind:value={pause} placeholder="e.g. F10" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<button class="primary" disabled={!valid || saving} onclick={save}>
|
||||||
|
{saving ? "saving..." : "save and continue"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint">
|
||||||
|
Live key capture isn't wired up yet - for now type the combination as text
|
||||||
|
(F9, Ctrl+Shift+R, etc).
|
||||||
|
</p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main {
|
||||||
|
padding: 2rem;
|
||||||
|
max-width: 560px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
header h1 {
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
.sub {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0 0 1.5rem;
|
||||||
|
}
|
||||||
|
.form {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin: 1.25rem 0;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 80px 1fr;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
label span {
|
||||||
|
color: #aaa;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
font: inherit;
|
||||||
|
padding: 0.45rem 0.6rem;
|
||||||
|
border: 1px solid #444;
|
||||||
|
background: #222;
|
||||||
|
color: inherit;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #4a8;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
font: inherit;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border: 1px solid #444;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
button:hover:not(:disabled) {
|
||||||
|
border-color: #888;
|
||||||
|
}
|
||||||
|
button.primary {
|
||||||
|
background: #4a8;
|
||||||
|
border-color: #4a8;
|
||||||
|
color: #111;
|
||||||
|
}
|
||||||
|
button.primary:disabled {
|
||||||
|
background: #333;
|
||||||
|
border-color: #333;
|
||||||
|
color: #666;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<main class="center">
|
||||||
|
<p class="muted">loading...</p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main.center {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
}
|
||||||
|
.muted {
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { api, type Config } from "./api"
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
let recording: boolean = $state(false)
|
||||||
|
let config: Config | null = $state(null)
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
config = await api.getConfig()
|
||||||
|
})
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
recording = !recording
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<header>
|
||||||
|
<h1>ByteSize</h1>
|
||||||
|
<p class="sub">ready</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="controls">
|
||||||
|
<button onclick={toggle} class:active={recording}>
|
||||||
|
{recording ? "stop" : "start"}
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{#if config}
|
||||||
|
<section class="cfg">
|
||||||
|
<h2>current settings</h2>
|
||||||
|
<dl>
|
||||||
|
<dt>format</dt>
|
||||||
|
<dd>{config.export.default_format}</dd>
|
||||||
|
<dt>fps</dt>
|
||||||
|
<dd>{config.capture.default_fps}</dd>
|
||||||
|
<dt>cursor</dt>
|
||||||
|
<dd>{config.capture.capture_cursor ? "on" : "off"}</dd>
|
||||||
|
<dt>audio</dt>
|
||||||
|
<dd>{config.capture.capture_audio ? "on" : "off"}</dd>
|
||||||
|
<dt>hotkeys</dt>
|
||||||
|
<dd>
|
||||||
|
start: {config.hotkeys.start ?? "-"} |
|
||||||
|
stop: {config.hotkeys.stop ?? "-"} |
|
||||||
|
pause: {config.hotkeys.pause ?? "-"}
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<p class="hint">
|
||||||
|
capture and encode aren't wired up yet. that's next.
|
||||||
|
</p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main {
|
||||||
|
padding: 2rem;
|
||||||
|
max-width: 720px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
header h1 {
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
.sub {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0 0 1.5rem;
|
||||||
|
}
|
||||||
|
.controls {
|
||||||
|
margin: 1rem 0 2rem;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
font: inherit;
|
||||||
|
padding: 0.6rem 1.2rem;
|
||||||
|
border: 1px solid #444;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
border-color: #888;
|
||||||
|
}
|
||||||
|
button.active {
|
||||||
|
background: #c33;
|
||||||
|
border-color: #c33;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.cfg {
|
||||||
|
border: 1px solid #2a2a2a;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
background: #1e1e1e;
|
||||||
|
}
|
||||||
|
.cfg h2 {
|
||||||
|
margin: 0 0 0.75rem;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
color: #888;
|
||||||
|
font-weight: normal;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
dl {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 100px 1fr;
|
||||||
|
gap: 0.5rem 1rem;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
dt {
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
dd {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/core"
|
||||||
|
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
|
||||||
|
|
||||||
|
export type FfmpegStatus = "ready" | "missing"
|
||||||
|
|
||||||
|
export type AppStatus = {
|
||||||
|
ffmpeg: FfmpegStatus
|
||||||
|
needs_first_run: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Format = "gif" | "webm" | "mp4"
|
||||||
|
export type GifDither = "floyd_steinberg" | "bayer" | "none"
|
||||||
|
export type WebmCodec = "vp9" | "av1"
|
||||||
|
export type Mp4Codec = "h264" | "h265"
|
||||||
|
|
||||||
|
export type ExportConfig = {
|
||||||
|
default_format: Format
|
||||||
|
gif_dither: GifDither
|
||||||
|
webm_codec: WebmCodec
|
||||||
|
mp4_codec: Mp4Codec
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CaptureConfig = {
|
||||||
|
default_fps: number
|
||||||
|
capture_cursor: boolean
|
||||||
|
capture_audio: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HotkeyConfig = {
|
||||||
|
start: string | null
|
||||||
|
stop: string | null
|
||||||
|
pause: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdatesConfig = {
|
||||||
|
check_on_launch: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Config = {
|
||||||
|
export: ExportConfig
|
||||||
|
capture: CaptureConfig
|
||||||
|
hotkeys: HotkeyConfig
|
||||||
|
updates: UpdatesConfig
|
||||||
|
output_dir: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DownloadProgress = {
|
||||||
|
downloaded: number
|
||||||
|
total: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const api = {
|
||||||
|
getStatus: () => invoke<AppStatus>("get_status"),
|
||||||
|
getConfig: () => invoke<Config>("get_config"),
|
||||||
|
saveConfig: (config: Config) => invoke<void>("save_config", { config }),
|
||||||
|
downloadFfmpeg: () => invoke<void>("download_ffmpeg"),
|
||||||
|
onFfmpegProgress: (handler: (p: DownloadProgress) => void): Promise<UnlistenFn> =>
|
||||||
|
listen<DownloadProgress>("ffmpeg-progress", (e) => handler(e.payload)),
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBytes(n: number): string {
|
||||||
|
if (n < 1024) return `${n} B`
|
||||||
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||||
|
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`
|
||||||
|
return `${(n / 1024 / 1024 / 1024).toFixed(2)} GB`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user