Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): refresh recording thumbnails after editing

Richie McIlroy4fdfba891a64
diff --git a/apps/desktop/src-tauri/src/editor_window.rs b/apps/desktop/src-tauri/src/editor_window.rs
index 8def29c52..42cd221b9 100644
--- a/apps/desktop/src-tauri/src/editor_window.rs
+++ b/apps/desktop/src-tauri/src/editor_window.rs
@@ -9,7 +9,7 @@ use std::{
},
time::Instant,
};
-use tauri::{AppHandle, Listener, Manager, Runtime, Window, ipc::CommandArg};
+use tauri::{AppHandle, Emitter, Listener, Manager, Runtime, Window, ipc::CommandArg};
use tokio::sync::{RwLock, watch};
use tokio_util::sync::CancellationToken;
@@ -400,12 +400,24 @@ impl PendingEditorInstances {
impl EditorInstance {
pub async fn dispose(&self) {
+ self.dispose_inner(false).await;
+ }
+
+ async fn dispose_inner(&self, refresh_thumbnail: bool) {
self.disposed.store(true, Ordering::Release);
let mut handoff = self.handoff_playback.lock().await;
if let Some((_, playback)) = handoff.take() {
playback.stop();
}
- self.inner.dispose().await;
+ if refresh_thumbnail {
+ if self.inner.dispose_with_thumbnail().await {
+ let _ = self
+ .app_handle
+ .emit("recording-thumbnail-changed", &self.project_path);
+ }
+ } else {
+ self.inner.dispose().await;
+ }
self.ws_shutdown_token.cancel();
self.app_handle.unlisten(self.render_frame_event_id);
@@ -740,9 +752,9 @@ impl EditorInstances {
return;
};
- let mut instances = instances.0.write().await;
- if let Some(instance) = instances.remove(window.label()) {
- instance.dispose().await;
+ let instance = instances.0.write().await.remove(window.label());
+ if let Some(instance) = instance {
+ instance.dispose_inner(true).await;
}
}
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/Recents.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/Recents.tsx
index 6d7fe4d83..1b3e2205d 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/Recents.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/Recents.tsx
@@ -10,6 +10,7 @@ import {
onMount,
Show,
} from "solid-js";
+import { createRecordingThumbnail } from "~/utils/recording-thumbnail";
import IconLucideClapperboard from "~icons/lucide/clapperboard";
import IconLucideHistory from "~icons/lucide/history";
import IconLucideImage from "~icons/lucide/image";
@@ -126,10 +127,19 @@ function RecentCard(props: {
}
return <IconLucideZap class="size-2.5" />;
};
- const thumbnailSrc = createMemo(() => {
- if (!props.item.previewPath || !imageAvailable()) return undefined;
+ const recordingThumbnail = createRecordingThumbnail(() =>
+ props.item.kind === "recording" ? props.item.target.path : undefined,
+ );
+ const source = createMemo(() => {
+ if (props.item.kind === "recording") return recordingThumbnail();
+ if (!props.item.previewPath) return undefined;
return `${convertFileSrc(props.item.previewPath)}?v=${props.item.previewVersion ?? 0}`;
});
+ createEffect(() => {
+ source();
+ setImageAvailable(true);
+ });
+ const thumbnailSrc = () => (imageAvailable() ? source() : undefined);
return (
<button
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
index 33ffdbb5e..3621d130f 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetCard.tsx
@@ -5,7 +5,13 @@ import { remove } from "@tauri-apps/plugin-fs";
import * as shell from "@tauri-apps/plugin-shell";
import { cx } from "cva";
import type { ComponentProps } from "solid-js";
-import { createMemo, createSignal, Show, splitProps } from "solid-js";
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ Show,
+ splitProps,
+} from "solid-js";
import toast from "solid-toast";
import Tooltip from "~/components/Tooltip";
import {
@@ -14,6 +20,7 @@ import {
screenshotShareStatusText,
} from "~/routes/screenshot-editor/screenshotExport";
import { openRecordingFolder } from "~/utils/recording";
+import { createRecordingThumbnail } from "~/utils/recording-thumbnail";
import {
type CaptureDisplayWithThumbnail,
type CaptureWindowWithThumbnail,
@@ -169,12 +176,13 @@ export default function TargetCard(props: TargetCardProps) {
return target ? formatRefreshRate(target.refresh_rate) : undefined;
});
+ const recordingThumbnail = createRecordingThumbnail(
+ () => recordingTarget()?.path,
+ );
const thumbnailSrc = createMemo(() => {
const recording = recordingTarget();
if (recording) {
- return `${convertFileSrc(
- `${recording.path}/screenshots/display.jpg`,
- )}?t=${Date.now()}`;
+ return recordingThumbnail();
}
const screenshot = screenshotTarget();
if (screenshot) {
@@ -184,6 +192,10 @@ export default function TargetCard(props: TargetCardProps) {
if (!target?.thumbnail) return undefined;
return `data:image/png;base64,${target.thumbnail}`;
});
+ createEffect(() => {
+ thumbnailSrc();
+ setImageExists(true);
+ });
const appIconSrc = createMemo(() => {
const target = windowTarget();
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx b/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
index 461b80455..53a6a91c9 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
@@ -6,7 +6,7 @@ import {
queryOptions,
useQueryClient,
} from "@tanstack/solid-query";
-import { Channel, convertFileSrc } from "@tauri-apps/api/core";
+import { Channel } from "@tauri-apps/api/core";
import { ask, confirm } from "@tauri-apps/plugin-dialog";
import { remove } from "@tauri-apps/plugin-fs";
import * as shell from "@tauri-apps/plugin-shell";
@@ -27,6 +27,7 @@ import { trackEvent } from "~/utils/analytics";
import { createTauriEventListener } from "~/utils/createEventListener";
import { importVideoFromPicker, showImportError } from "~/utils/importMedia";
import { openRecordingFolder } from "~/utils/recording";
+import { createRecordingThumbnail } from "~/utils/recording-thumbnail";
import {
commands,
events,
@@ -41,7 +42,6 @@ type Recording = {
meta: RecordingMetaWithMetadata;
path: string;
prettyName: string;
- thumbnailPath: string;
};
const Tabs = [
@@ -80,13 +80,11 @@ const recordingsQuery = queryOptions<Recording[]>({
const recordings = await Promise.all(
result.map(async (file) => {
const [path, meta] = file;
- const thumbnailPath = `${path}/screenshots/display.jpg`;
return {
meta,
path,
prettyName: meta.pretty_name,
- thumbnailPath,
};
}),
);
@@ -329,6 +327,11 @@ function RecordingItem(props: {
uploadProgress: number | undefined;
}) {
const [imageExists, setImageExists] = createSignal(true);
+ const thumbnail = createRecordingThumbnail(() => props.recording.path);
+ createEffect(() => {
+ thumbnail();
+ setImageExists(true);
+ });
const mode = () => props.recording.meta.mode;
const firstLetterUpperCase = () =>
mode().charAt(0).toUpperCase() + mode().slice(1);
@@ -357,9 +360,7 @@ function RecordingItem(props: {
<img
class="object-cover rounded-sm size-12"
alt="Recording thumbnail"
- src={`${convertFileSrc(
- props.recording.thumbnailPath,
- )}?t=${Date.now()}`}
+ src={thumbnail()}
onError={() => setImageExists(false)}
/>
</Show>
diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsx
index bc281b4df..b9ea01c14 100644
--- a/apps/desktop/src/routes/editor/Editor.tsx
+++ b/apps/desktop/src/routes/editor/Editor.tsx
@@ -532,6 +532,15 @@ function Inner(props: {
} catch {
return;
}
+ try {
+ await flushProjectConfig();
+ } catch (error) {
+ console.error("Failed to save the project before closing", error);
+ toast.error(
+ "Could not save your edits. Keep the editor open and try again.",
+ );
+ return;
+ }
if (exportState.type === "idle" || exportState.type === "done") {
allowExportClose = true;