Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
add changes
neo773c97516c6214b
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex e79cc7817..714271bbc 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -41,6 +41,7 @@ import {} from "./projectConfig";import { generalSettingsStore } from "~/store";import { type as ostype } from "@tauri-apps/plugin-os";+import toast from "solid-toast";const BACKGROUND_SOURCES = {wallpaper: "Wallpaper",@@ -340,11 +341,29 @@ export function ConfigSidebar() {type="file"ref={fileInput}class="hidden"- accept="image/*"+ accept="image/apng, image/avif, image/jpeg, image/png, image/webp"onChange={async (e) => {const file = e.currentTarget.files?.[0];if (!file) return;+ /*+ this is a Tauri bug in WebKit so we need to validate the file type manually+ https://github.com/tauri-apps/tauri/issues/9158+ */+ const validExtensions = [+ "jpg",+ "jpeg",+ "png",+ "gif",+ "webp",+ "bmp",+ ];+ const extension = file.name.split(".").pop()?.toLowerCase();+ if (!extension || !validExtensions.includes(extension)) {+ toast.error("Invalid image file type");+ return;+ }+try {const fileName = `bg-${Date.now()}-${file.name}`;const arrayBuffer = await file.arrayBuffer();diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex eb8fbe21a..661817372 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -973,14 +973,16 @@ pub async fn produce_frame(// First, handle the backgroundmatch background {Background::Image { path } => {+ let img = image::open(&path)+ .map_err(|e| RenderingError::ImageLoadError(e.to_string()))?;+// Use entry API to handle texture cachinglet mut textures = constants.background_textures.write().await;let texture = match textures.entry(path.clone()) {std::collections::hash_map::Entry::Occupied(e) => e.into_mut(),std::collections::hash_map::Entry::Vacant(e) => {// Load image with error propagation- let img = image::open(&path)- .map_err(|e| RenderingError::ImageLoadError(e.to_string()))?;+let rgba = img.to_rgba8();let dimensions = img.dimensions();@@ -1028,6 +1030,7 @@ pub async fn produce_frame(// Create uniforms and bind grouplet image_uniforms = ImageBackgroundUniforms {output_size: [uniforms.output_size.0 as f32, uniforms.output_size.1 as f32],+ image_size: [img.dimensions().0 as f32, img.dimensions().1 as f32],padding: uniforms.project.background.padding as f32,_padding: 0.0,};@@ -2410,6 +2413,7 @@ struct ImageBackgroundPipeline {#[derive(Copy, Clone, Pod, Zeroable)]struct ImageBackgroundUniforms {output_size: [f32; 2],+ image_size: [f32; 2],padding: f32,_padding: f32, // For alignment}diff --git a/crates/rendering/src/shaders/image-background.wgsl b/crates/rendering/src/shaders/image-background.wgslindex c5cf059e2..869165363 100644--- a/crates/rendering/src/shaders/image-background.wgsl+++ b/crates/rendering/src/shaders/image-background.wgsl@@ -1,5 +1,6 @@struct Uniforms {output_size: vec2<f32>,+ image_size: vec2<f32>,padding: f32,_padding: f32, // Matches the Rust struct alignment padding};@@ -25,18 +26,15 @@ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {@fragmentfn fs_main(@location(0) tex_coords: vec2<f32>) -> @location(0) vec4<f32> {- // Calculate the padding in UV space- let padding_uv = u.padding / max(u.output_size.x, u.output_size.y);+ // Calculate scaling factors for width and height+ let scale_x = u.output_size.x / u.image_size.x;+ let scale_y = u.output_size.y / u.image_size.y;- // Adjust UV coordinates to account for padding- let adjusted_coords = tex_coords * (1.0 - 2.0 * padding_uv) + padding_uv;+ // Use the larger scale factor to ensure coverage+ let scale = max(scale_x, scale_y);- // Sample the texture with the adjusted coordinates- let color = textureSample(t_image, s_image, adjusted_coords);+ // Transform coordinates to sample from the center of the scaled image+ let adjusted_coords = (tex_coords - 0.5) * (u.output_size / (u.image_size * scale)) + 0.5;- // If the adjusted coordinates are outside the [0,1] range, return transparent- let is_inside = all(adjusted_coords >= vec2<f32>(0.0)) &&- all(adjusted_coords <= vec2<f32>(1.0));-- return select(vec4<f32>(0.0), color, is_inside);+ return textureSample(t_image, s_image, adjusted_coords);}