Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Add font weight option to caption settings + progress loader
Richie McIlroy9e0ead19fc7b
diff --git a/apps/desktop/src-tauri/src/captions.rs b/apps/desktop/src-tauri/src/captions.rsindex f4fb8ac49..e9fb1711e 100644--- a/apps/desktop/src-tauri/src/captions.rs+++ b/apps/desktop/src-tauri/src/captions.rs@@ -5,6 +5,7 @@ use ffmpeg::{format::{self as avformat},software::resampling,};+use futures::StreamExt;use serde::{Deserialize, Serialize};use specta::Type;use std::fs::File;@@ -12,7 +13,8 @@ use std::io::Read;use std::path::PathBuf;use std::process::Command;use std::sync::Arc;-use tauri::{AppHandle, Emitter, Manager, Window};+use tauri::{AppHandle, Manager};+use tauri_specta::Event;use tempfile::tempdir;use tokio::io::AsyncWriteExt;use tokio::sync::Mutex;@@ -1920,10 +1922,15 @@ pub fn parse_captions_json(json: &str) -> Result<cap_project::CaptionsData, Stri.get("italic").and_then(|v| v.as_bool()).unwrap_or(false);+ let font_weight = settings_obj+ .get("fontWeight")+ .or_else(|| settings_obj.get("font_weight"))+ .and_then(|v| v.as_u64())+ .unwrap_or(700) as u32;let outline = settings_obj.get("outline").and_then(|v| v.as_bool())- .unwrap_or(true);+ .unwrap_or(false);let outline_color = settings_obj.get("outlineColor")@@ -1973,6 +1980,7 @@ pub fn parse_captions_json(json: &str) -> Result<cap_project::CaptionsData, Striposition,bold,italic,+ font_weight,outline,outline_color,export_with_subtitles,@@ -2081,16 +2089,11 @@ pub struct DownloadProgress {pub message: String,}-impl DownloadProgress {- const EVENT_NAME: &'static str = "download-progress";-}-#[tauri::command]#[specta::specta]-#[instrument(skip(window))]+#[instrument(skip(app))]pub async fn download_whisper_model(app: AppHandle,- window: Window,model_name: String,output_path: String,) -> Result<(), String> {@@ -2128,22 +2131,17 @@ pub async fn download_whisper_model(.await.map_err(|e| format!("Failed to create file: {e}"))?;- let mut downloaded = 0;- let mut bytes = response- .bytes()- .await- .map_err(|e| format!("Failed to get response bytes: {e}"))?;+ let mut downloaded: u64 = 0;+ let mut stream = response.bytes_stream();- const CHUNK_SIZE: usize = 1024 * 1024;- while !bytes.is_empty() {- let chunk_size = std::cmp::min(CHUNK_SIZE, bytes.len());- let chunk = bytes.split_to(chunk_size);+ while let Some(chunk_result) = stream.next().await {+ let chunk = chunk_result.map_err(|e| format!("Error while downloading: {e}"))?;file.write_all(&chunk).await.map_err(|e| format!("Error while writing to file: {e}"))?;- downloaded += chunk_size as u64;+ downloaded += chunk.len() as u64;let progress = if total_size > 0 {(downloaded as f64 / total_size as f64) * 100.0@@ -2151,15 +2149,12 @@ pub async fn download_whisper_model(0.0};- window- .emit(- DownloadProgress::EVENT_NAME,- DownloadProgress {- message: format!("Downloading model: {progress:.1}%"),- progress,- },- )- .map_err(|e| format!("Failed to emit progress: {e}"))?;+ DownloadProgress {+ progress,+ message: format!("Downloading model: {progress:.1}%"),+ }+ .emit(&app)+ .ok();}file.flush()diff --git a/apps/desktop/src/routes/editor/CaptionsTab.tsx b/apps/desktop/src/routes/editor/CaptionsTab.tsxindex 2c6e87a8a..aee33edfe 100644--- a/apps/desktop/src/routes/editor/CaptionsTab.tsx+++ b/apps/desktop/src/routes/editor/CaptionsTab.tsx@@ -18,6 +18,8 @@ import { Toggle } from "~/components/Toggle";import { defaultCaptionSettings } from "~/store/captions";import type { CaptionSettings } from "~/utils/tauri";import { commands, events } from "~/utils/tauri";+import IconCapChevronDown from "~icons/cap/chevron-down";+import IconCapCircleCheck from "~icons/cap/circle-check";import IconLucideCheck from "~icons/lucide/check";import IconLucideDownload from "~icons/lucide/download";import { useEditorContext } from "./context";@@ -31,6 +33,7 @@ import {Slider,Subfield,topLeftAnimateClasses,+ topSlideAnimateClasses,} from "./ui";interface ModelOption {@@ -273,16 +276,24 @@ export function CaptionsTab() {);createEffect(- on(selectedModel, (model) => {- if (model) localStorage.setItem("selectedTranscriptionModel", model);- }),+ on(+ selectedModel,+ (model) => {+ if (model) localStorage.setItem("selectedTranscriptionModel", model);+ },+ { defer: true },+ ),);createEffect(- on(selectedLanguage, (language) => {- if (language)- localStorage.setItem("selectedTranscriptionLanguage", language);- }),+ on(+ selectedLanguage,+ (language) => {+ if (language)+ localStorage.setItem("selectedTranscriptionLanguage", language);+ },+ { defer: true },+ ),);const checkModelExists = async (modelName: string) => {@@ -778,32 +789,71 @@ export function CaptionsTab() {</div></Field>- <Field name="Style Options" icon={<IconCapMessageBubble />}>- <div class="space-y-3">- <div class="flex flex-col gap-4">- <Subfield name="Outline">- <Toggle- checked={getSetting("outline")}- onChange={(checked) =>- updateCaptionSetting("outline", checked)- }- disabled={!hasCaptions()}- />- </Subfield>- </div>-- <Show when={getSetting("outline")}>- <div class="flex flex-col gap-2">- <span class="text-gray-11 text-sm">Outline Color</span>- <RgbInput- value={getSetting("outlineColor")}- onChange={(value) =>- updateCaptionSetting("outlineColor", value)- }+ <Field name="Font Weight" icon={<IconCapMessageBubble />}>+ <KSelect+ options={[+ { label: "Normal", value: 400 },+ { label: "Medium", value: 500 },+ { label: "Bold", value: 700 },+ ]}+ optionValue="value"+ optionTextValue="label"+ value={{+ label: "Custom",+ value: getSetting("fontWeight"),+ }}+ onChange={(value) => {+ if (!value) return;+ updateCaptionSetting("fontWeight", value.value);+ }}+ disabled={!hasCaptions()}+ itemComponent={(selectItemProps) => (+ <MenuItem<typeof KSelect.Item>+ as={KSelect.Item}+ item={selectItemProps.item}+ >+ <KSelect.ItemLabel class="flex-1">+ {selectItemProps.item.rawValue.label}+ </KSelect.ItemLabel>+ <KSelect.ItemIndicator class="ml-auto text-blue-9">+ <IconCapCircleCheck />+ </KSelect.ItemIndicator>+ </MenuItem>+ )}+ >+ <KSelect.Trigger class="flex w-full items-center justify-between rounded-md border border-gray-3 bg-gray-2 px-3 py-2 text-sm text-gray-12 transition-colors hover:border-gray-4 hover:bg-gray-3 focus:border-blue-9 focus:outline-none focus:ring-1 focus:ring-blue-9">+ <KSelect.Value<{+ label: string;+ value: number;+ }> class="truncate">+ {(state) => {+ const selected = state.selectedOption();+ if (selected) return selected.label;+ const weight = getSetting("fontWeight");+ const option = [+ { label: "Normal", value: 400 },+ { label: "Medium", value: 500 },+ { label: "Bold", value: 700 },+ ].find((o) => o.value === weight);+ return option ? option.label : "Bold";+ }}+ </KSelect.Value>+ <KSelect.Icon>+ <IconCapChevronDown class="size-4 shrink-0 transform transition-transform ui-expanded:rotate-180 text-[--gray-500]" />+ </KSelect.Icon>+ </KSelect.Trigger>+ <KSelect.Portal>+ <PopperContent<typeof KSelect.Content>+ as={KSelect.Content}+ class={cx(topSlideAnimateClasses, "z-50")}+ >+ <MenuItemList<typeof KSelect.Listbox>+ class="overflow-y-auto max-h-40"+ as={KSelect.Listbox}/>- </div>- </Show>- </div>+ </PopperContent>+ </KSelect.Portal>+ </KSelect></Field><Field name="Export Options" icon={<IconCapMessageBubble />}>diff --git a/apps/desktop/src/store/captions.ts b/apps/desktop/src/store/captions.tsindex c6d850474..56b0ef2e5 100644--- a/apps/desktop/src/store/captions.ts+++ b/apps/desktop/src/store/captions.ts@@ -22,7 +22,8 @@ export const defaultCaptionSettings: CaptionSettings = {position: "bottom-center",bold: false,italic: false,- outline: true,+ fontWeight: 700,+ outline: false,outlineColor: "#000000",exportWithSubtitles: false,highlightColor: "#FFFFFF",@@ -138,6 +139,7 @@ function createCaptionsStore() {position: state.settings.position,bold: state.settings.bold,italic: state.settings.italic,+ fontWeight: state.settings.fontWeight,outline: state.settings.outline,outlineColor: state.settings.outlineColor,exportWithSubtitles: state.settings.exportWithSubtitles,diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rsindex 85b34847c..7f3f62bc4 100644--- a/crates/project/src/configuration.rs+++ b/crates/project/src/configuration.rs@@ -604,6 +604,8 @@ pub struct MaskSegment {pub pixelation: f64,#[serde(default)]pub darkness: f64,+ #[serde(default = "MaskSegment::default_fade_duration")]+ pub fade_duration: f64,#[serde(default)]pub keyframes: MaskKeyframes,}@@ -616,6 +618,10 @@ impl MaskSegment {fn default_opacity() -> f64 {1.0}++ fn default_fade_duration() -> f64 {+ 0.15+ }}#[derive(Type, Serialize, Deserialize, Clone, Debug)]@@ -641,6 +647,8 @@ pub struct TextSegment {pub italic: bool,#[serde(default = "TextSegment::default_color")]pub color: String,+ #[serde(default = "TextSegment::default_fade_duration")]+ pub fade_duration: f64,}impl TextSegment {@@ -675,6 +683,10 @@ impl TextSegment {fn default_color() -> String {"#ffffff".to_string()}++ fn default_fade_duration() -> f64 {+ 0.15+ }}#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default)]@@ -778,6 +790,8 @@ pub struct CaptionSettings {pub position: String,pub bold: bool,pub italic: bool,+ #[serde(alias = "fontWeight", default = "CaptionSettings::default_font_weight")]+ pub font_weight: u32,pub outline: bool,#[serde(alias = "outlineColor")]pub outline_color: String,@@ -810,6 +824,10 @@ impl CaptionSettings {"#FFFFFF".to_string()}+ fn default_font_weight() -> u32 {+ 700+ }+fn default_fade_duration() -> f32 {0.15}@@ -835,7 +853,8 @@ impl Default for CaptionSettings {position: "bottom-center".to_string(),bold: false,italic: false,- outline: true,+ font_weight: Self::default_font_weight(),+ outline: false,outline_color: "#000000".to_string(),export_with_subtitles: false,highlight_color: Self::default_highlight_color(),diff --git a/crates/rendering/src/layers/captions.rs b/crates/rendering/src/layers/captions.rsindex b17b451bb..c98bc98af 100644--- a/crates/rendering/src/layers/captions.rs+++ b/crates/rendering/src/layers/captions.rs@@ -542,8 +542,10 @@ impl CaptionsLayer {_ => Family::SansSerif,};- let weight = if caption_data.settings.bold {+ let weight = if caption_data.settings.font_weight >= 700 {Weight::BOLD+ } else if caption_data.settings.font_weight >= 500 {+ Weight::MEDIUM} else {Weight::NORMAL};