Bound native media preview capabilities and source range reads

This commit is contained in:
karl committed 2026-10-13 14:22:19 +02:00
1 parent 4b0b5ebfd9
commit 370db7e791
13 files changed
+834 -46

No files matched your search

+3 -1
View File
@@ -4,6 +4,7 @@ import {
convertFileSrc,
} from "@tauri-apps/api/core";
import { CaptureBridge } from "./capture-bridge";
import { nativePreviewToken } from "./media-access";
const capture = new CaptureBridge();
export const isNativeDesktop = () => isTauri();
@@ -25,6 +26,7 @@ export function invoke<T>(
}
export function prepareMediaURL(path: string) {
if (isTauri()) return convertFileSrc(path);
if (isTauri())
return convertFileSrc(nativePreviewToken(path), "searchi-media");
return capture.mediaURL(path);
}
+2 -1
View File
@@ -61,6 +61,7 @@ import {
sourceLabel,
seekSeconds,
PreviewRevision,
previewSelectionKey,
} from "./media-display";
interface SearchResult {
@@ -892,7 +893,7 @@ function select(index: number, focus = false, userChoice = true) {
? `Open in your default application. The matched location ${sourceLabel(result.source)} is shown in Searchi; default application opening starts at its own location.`
: "Open in your default application";
const selection = previewRevision.select(
JSON.stringify([result.path, result.source?.kind, result.source?.number]),
previewSelectionKey(result.path, result.source, folderRevision),
);
if (selection.changed) {
mediaLane.clear();
+9
View File
@@ -0,0 +1,9 @@
/** Native previews carry an opaque grant, never a filesystem path or URL. */
export function nativePreviewToken(value: string): string {
if (!/^[a-f0-9]{32}$/.test(value)) {
throw new Error(
"Media preview access is unavailable. Select the file again.",
);
}
return value;
}
+7
View File
@@ -4,6 +4,13 @@ export interface MediaSource {
number: number;
}
export type MediaKind = "image" | "audio" | "video";
export function previewSelectionKey(
path: string,
source: MediaSource | undefined,
indexRevision: number,
): string {
return JSON.stringify([path, source?.kind, source?.number, indexRevision]);
}
export function timestampLabel(milliseconds: number): string {
if (!Number.isFinite(milliseconds) || milliseconds < 0) return "Unknown time";
const seconds = Math.floor(milliseconds / 1000);