Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
refactor(desktop): migrate hotkeys settings to shared layout
Richie McIlroy607aaf88963e
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx b/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsxindex b9b7ba47c..312213d49 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx@@ -20,6 +20,7 @@ import {type HotkeyAction,type HotkeysStore,} from "~/utils/tauri";+import { Section, SectionCard, SettingsPageContent } from "./Setting";const ACTION_TEXT = {startStudioRecording: "Start studio recording",@@ -97,117 +98,120 @@ function Inner(props: { initialStore: HotkeysStore | null }) {] satisfies Array<keyof typeof ACTION_TEXT>;return (- <div class="cap-settings-page flex flex-col flex-1 p-4 h-full custom-scroll">- <div class="flex flex-col pb-4 border-b border-gray-2">- <h2 class="text-lg font-medium text-gray-12">Shortcuts</h2>- <p class="text-sm text-gray-10 w-full max-w-[500px]">- Configure system-wide keyboard shortcuts to control Cap- </p>- </div>- <div class="flex flex-col gap-3 p-4 mt-4 w-full rounded-xl border bg-gray-2 border-gray-3">- <Index each={actions()}>- {(item, idx) => {- createEventListener(window, "click", () => {- if (listening()?.action !== item()) return;-- batch(() => {- setHotkeys(item(), listening()?.prev);- setListening();- });- });-- return (- <>- <div class="flex flex-row justify-between items-center w-full h-8">- <p class="text-sm text-gray-12">{ACTION_TEXT[item()]}</p>- <Switch>- <Match when={listening()?.action === item()}>- <div class="flex flex-row-reverse gap-2 justify-between items-center h-full text-sm rounded-lg w-fit">- <Show- when={hotkeys[item()]}- fallback={- <p class="text-[13px] text-gray-11">- Set hotkeys...- </p>- }- >- {(binding) => <HotkeyText binding={binding()} />}- </Show>- <div class="flex flex-row items-center gap-0.5">- <Show when={hotkeys[item()]}>- <button- class="w-fit"- type="button"- onBlur={(e) => console.log(e)}- onClick={(e) => {- e.stopPropagation();-- setListening();- commands.setHotkey(- item(),- hotkeys[item()] ?? null,- );- }}+ <div class="cap-settings-page flex flex-col h-full custom-scroll">+ <SettingsPageContent>+ <Section+ title="Shortcuts"+ description="Configure system-wide keyboard shortcuts to control Cap."+ >+ <SectionCard class="flex flex-col gap-3 p-4">+ <Index each={actions()}>+ {(item, idx) => {+ createEventListener(window, "click", () => {+ if (listening()?.action !== item()) return;++ batch(() => {+ setHotkeys(item(), listening()?.prev);+ setListening();+ });+ });++ return (+ <>+ <div class="flex flex-row justify-between items-center w-full h-8">+ <p class="text-[13px] text-gray-12">+ {ACTION_TEXT[item()]}+ </p>+ <Switch>+ <Match when={listening()?.action === item()}>+ <div class="flex flex-row-reverse gap-2 justify-between items-center h-full text-sm rounded-lg w-fit">+ <Show+ when={hotkeys[item()]}+ fallback={+ <p class="text-[13px] text-gray-11">+ Set hotkeys...+ </p>+ }>- <IconCapCircleCheck class="transition-colors text-gray-12 hover:text-gray-10 size-5" />- </button>- </Show>+ {(binding) => <HotkeyText binding={binding()} />}+ </Show>+ <div class="flex flex-row items-center gap-0.5">+ <Show when={hotkeys[item()]}>+ <button+ class="w-fit"+ type="button"+ onBlur={(e) => console.log(e)}+ onClick={(e) => {+ e.stopPropagation();++ setListening();+ commands.setHotkey(+ item(),+ hotkeys[item()] ?? null,+ );+ }}+ >+ <IconCapCircleCheck class="transition-colors text-gray-12 hover:text-gray-10 size-5" />+ </button>+ </Show>+ <button+ type="button"+ onClick={(e) => {+ e.stopPropagation();+ batch(() => {+ setListening();+ // biome-ignore lint/style/noNonNullAssertion: store+ setHotkeys(item(), undefined!);+ commands.setHotkey(item(), null);+ });+ }}+ >+ <IconCapCircleX class="text-red-500 transition-colors hover:text-red-700 size-5" />+ </button>+ </div>+ </div>+ </Match>+ <Match when={listening()?.action !== item()}><buttontype="button"- onClick={(e) => {- e.stopPropagation();- batch(() => {- setListening();- // biome-ignore lint/style/noNonNullAssertion: store- setHotkeys(item(), undefined!);- commands.setHotkey(item(), null);- });+ class="text-sm bg-transparent rounded-lg"+ onClick={() => {+ // ensures that previously selected hotkey is cleared by letting the event propagate before listening to the new hotkey+ setTimeout(() => {+ setListening({+ action: item(),+ prev: hotkeys[item()],+ });+ }, 1);}}>- <IconCapCircleX class="text-red-500 transition-colors hover:text-red-700 size-5" />- </button>- </div>- </div>- </Match>- <Match when={listening()?.action !== item()}>- <button- type="button"- class="text-sm bg-transparent rounded-lg"- onClick={() => {- // ensures that previously selected hotkey is cleared by letting the event propagate before listening to the new hotkey- setTimeout(() => {- setListening({- action: item(),- prev: hotkeys[item()],- });- }, 1);- }}- >- <Show- when={hotkeys[item()]}- fallback={- <p- class="flex items-center text-[11px] uppercase transition-colors hover:bg-gray-6 hover:border-gray-7+ <Show+ when={hotkeys[item()]}+ fallback={+ <p+ class="flex items-center text-[11px] uppercase transition-colors hover:bg-gray-6 hover:border-gray-7cursor-pointer py-3 px-2.5 h-5 bg-gray-4 border border-gray-5 rounded-lg text-gray-11 hover:text-gray-12"+ >+ None+ </p>+ }>- None- </p>- }- >- {(binding) => <HotkeyText binding={binding()} />}- </Show>- </button>- </Match>- </Switch>- </div>- {idx !== actions().length - 1 && (- <div class="w-full h-px bg-gray-3" />- )}- </>- );- }}- </Index>- </div>+ {(binding) => <HotkeyText binding={binding()} />}+ </Show>+ </button>+ </Match>+ </Switch>+ </div>+ {idx !== actions().length - 1 && (+ <div class="w-full h-px bg-gray-3" />+ )}+ </>+ );+ }}+ </Index>+ </SectionCard>+ </Section>+ </SettingsPageContent></div>);}