Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Optimize device queries and refactor permissions handling
Richie McIlroya6b591ab08d2
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsxindex 34c402255..7714e6194 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx@@ -1,4 +1,3 @@-import { createQuery } from "@tanstack/solid-query";import { CheckMenuItem, Menu, PredefinedMenuItem } from "@tauri-apps/api/menu";import { cx } from "cva";import {@@ -10,8 +9,8 @@ import {} from "solid-js";import { trackEvent } from "~/utils/analytics";import { createTauriEventListener } from "~/utils/createEventListener";-import { createCurrentRecordingQuery, getPermissions } from "~/utils/queries";-import { events } from "~/utils/tauri";+import { createCurrentRecordingQuery } from "~/utils/queries";+import { events, type OSPermissionsCheck } from "~/utils/tauri";import InfoPill from "./InfoPill";import TargetSelectInfoPill from "./TargetSelectInfoPill";import useRequestPermission from "./useRequestPermission";@@ -23,6 +22,7 @@ export default function MicrophoneSelect(props: {options: string[];value: string | null;onChange: (micName: string | null) => void;+ permissions?: OSPermissionsCheck;}) {return (<MicrophoneSelectBase@@ -46,10 +46,10 @@ export function MicrophoneSelectBase(props: {PillComponent: Component<ComponentProps<"button"> & { variant: "blue" | "red" }>;+ permissions?: OSPermissionsCheck;}) {const DB_SCALE = 40;- const permissions = createQuery(() => getPermissions);const currentRecording = createCurrentRecordingQuery();const [dbs, setDbs] = createSignal<number | undefined>();@@ -58,8 +58,8 @@ export function MicrophoneSelectBase(props: {const requestPermission = useRequestPermission();const permissionGranted = () =>- permissions?.data?.microphone === "granted" ||- permissions?.data?.microphone === "notNeeded";+ props.permissions?.microphone === "granted" ||+ props.permissions?.microphone === "notNeeded";type Option = { name: string };diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsxindex f1fcf0771..6fc0bff1b 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx@@ -37,6 +37,7 @@ import {createCameraMutation,createCurrentRecordingQuery,createLicenseQuery,+ createPermissionsQuery,listAudioDevices,listDisplaysWithThumbnails,listRecordings,@@ -498,7 +499,8 @@ function Page() {([path, meta]) => ({ ...meta, path }) as ScreenshotWithPath,);},- refetchInterval: 2000,+ refetchInterval: 10_000,+ staleTime: 5_000,reconcile: (old, next) => reconcile(next)(old),initialData: [],}),@@ -664,6 +666,7 @@ function Page() {const cameras = useQuery(() => listVideoDevices);const mics = useQuery(() => listAudioDevices);+ const permissions = createPermissionsQuery();const windowListSignature = createMemo(() =>createWindowSignature(windows.data),@@ -835,6 +838,7 @@ function Page() {else if (c.model_id) setCamera.mutate({ ModelID: c.model_id });else setCamera.mutate({ DeviceID: c.device_id });}}+ permissions={permissions.data}/><MicrophoneSelectdisabled={mics.isPending}@@ -843,6 +847,7 @@ function Page() {mics.isPending ? rawOptions.micName : (options.micName() ?? null)}onChange={(v) => setMicInput.mutate(v)}+ permissions={permissions.data}/><SystemAudio /></div>@@ -889,6 +894,8 @@ function Page() {if (next) {setWindowMenuOpen(false);setHasOpenedDisplayMenu(true);+ screens.refetch();+ displayTargets.refetch();}return next;});@@ -926,6 +933,8 @@ function Page() {if (next) {setDisplayMenuOpen(false);setHasOpenedWindowMenu(true);+ windows.refetch();+ windowTargets.refetch();}return next;});diff --git a/apps/desktop/src/utils/queries.ts b/apps/desktop/src/utils/queries.tsindex 53cfee00d..5539e029f 100644--- a/apps/desktop/src/utils/queries.ts+++ b/apps/desktop/src/utils/queries.ts@@ -46,7 +46,8 @@ export const listScreens = queryOptions({queryKey: ["capture", "displays"] as const,queryFn: () => commands.listCaptureDisplays(),reconcile: "id",- refetchInterval: 1000,+ refetchInterval: 10_000,+ staleTime: 5_000,});export const listWindowsWithThumbnails = queryOptions({@@ -70,7 +71,8 @@ export const listDisplaysWithThumbnails = queryOptions({queryKey: ["capture", "displays-thumbnails"] as const,queryFn: () => commands.listDisplaysWithThumbnails(),reconcile: "id",- refetchInterval: 1000,+ refetchInterval: 10_000,+ staleTime: 5_000,});const getCurrentRecording = queryOptions({@@ -90,7 +92,8 @@ export const listRecordings = queryOptions({export const listVideoDevices = queryOptions({queryKey: ["videoDevices"] as const,queryFn: () => commands.listCameras(),- refetchInterval: 1000,+ refetchInterval: 5_000,+ staleTime: 3_000,initialData: [],});@@ -110,17 +113,33 @@ export const listAudioDevices = queryOptions({queryKey: ["audioDevices"] as const,queryFn: () => commands.listAudioDevices(),reconcile: "name",- refetchInterval: 1000,- gcTime: 0,- staleTime: 0,+ refetchInterval: 5_000,+ staleTime: 3_000,});export const getPermissions = queryOptions({queryKey: ["permissionsOS"] as const,queryFn: () => commands.doPermissionsCheck(true),- refetchInterval: 1000,+ staleTime: 3_000,});+export function createPermissionsQuery() {+ const [refetchInterval, setRefetchInterval] = createStore<{+ value: number;+ }>({ value: 5_000 });++ const timeoutId = setTimeout(() => {+ setRefetchInterval("value", 15_000);+ }, 30_000);++ onCleanup(() => clearTimeout(timeoutId));++ return createQuery(() => ({+ ...getPermissions,+ refetchInterval: refetchInterval.value,+ }));+}+export const isSystemAudioSupported = queryOptions({queryKey: ["systemAudioSupported"] as const,queryFn: () => commands.isSystemAudioCaptureSupported(),