Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

improved permissions window

Brendan Allan33f2703efb34
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 67a3e2eb8..594995835 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -193,7 +193,6 @@ impl CapWindow {
.inner_size(300.0, 375.0)
.resizable(false)
.maximized(false)
- .accept_first_mouse(true)
.transparent(true)
.theme(Some(tauri::Theme::Light))
.shadow(true);
@@ -227,7 +226,6 @@ impl CapWindow {
.min_inner_size(600.0, 450.0)
.resizable(true)
.maximized(false)
- .accept_first_mouse(true)
.transparent(true);
#[cfg(target_os = "windows")]
@@ -334,7 +332,6 @@ impl CapWindow {
.transparent(true)
.visible_on_all_workspaces(true)
.content_protected(true)
- .accept_first_mouse(true)
.inner_size(width, height)
.position(
((monitor.size().width as f64) / monitor.scale_factor() - width) / 2.0,
@@ -378,7 +375,6 @@ impl CapWindow {
.shadow(false)
.always_on_top(true)
.visible_on_all_workspaces(true)
- .accept_first_mouse(true)
.content_protected(true)
.inner_size(
350.0,
@@ -426,7 +422,6 @@ impl CapWindow {
.title(self.title())
.hidden_title(true)
.title_bar_style(tauri::TitleBarStyle::Overlay)
- .accept_first_mouse(true)
.theme(Some(tauri::Theme::Light));
#[cfg(target_os = "macos")]
@@ -447,11 +442,10 @@ impl CapWindow {
let mut window_builder = self
.window_builder(app, "/permissions")
.title(self.title())
- .inner_size(300.0, 350.0)
+ .inner_size(500.0, 425.0)
.resizable(false)
.maximized(false)
.shadow(true)
- .accept_first_mouse(true)
.transparent(true);
#[cfg(target_os = "macos")]
@@ -481,7 +475,6 @@ impl CapWindow {
.resizable(false)
.maximized(false)
.shadow(true)
- .accept_first_mouse(true)
.transparent(true);
#[cfg(target_os = "macos")]
@@ -511,7 +504,6 @@ impl CapWindow {
.resizable(false)
.maximized(false)
.shadow(true)
- .accept_first_mouse(true)
.transparent(true);
#[cfg(target_os = "macos")]
@@ -536,7 +528,6 @@ impl CapWindow {
.resizable(true)
.maximized(false)
.shadow(true)
- .accept_first_mouse(true)
.transparent(true);
#[cfg(target_os = "macos")]
@@ -569,6 +560,7 @@ impl CapWindow {
WebviewWindow::builder(app, self.label(), WebviewUrl::App(url.into()))
.title(self.title())
.visible(false)
+ .accept_first_mouse(true)
}
}
diff --git a/apps/desktop/src/routes/(window-chrome)/permissions.tsx b/apps/desktop/src/routes/(window-chrome)/permissions.tsx
new file mode 100644
index 000000000..3894fd19e
--- /dev/null
+++ b/apps/desktop/src/routes/(window-chrome)/permissions.tsx
@@ -0,0 +1,128 @@
+import { Button } from "@cap/ui-solid";
+import type { RouteSectionProps } from "@solidjs/router";
+import { commands, OSPermission, type OSPermissionStatus } from "~/utils/tauri";
+import {
+ createEffect,
+ createResource,
+ Suspense,
+ createSignal,
+ Show,
+ For,
+ startTransition,
+} from "solid-js";
+import { createTimer } from "@solid-primitives/timer";
+import { getCurrentWindow } from "@tauri-apps/api/window";
+import { Transition } from "solid-transition-group";
+
+import Header from "../../components/Header";
+
+function isPermitted(status?: OSPermissionStatus): boolean {
+ return status === "granted" || status === "notNeeded";
+}
+
+const permissions = [
+ {
+ name: "Screen Recording",
+ key: "screenRecording" as const,
+ description: "Cap needs access to record your screen",
+ },
+ {
+ name: "Accessibility",
+ key: "accessibility" as const,
+ description:
+ "Cap records your mouse and keyboard activity to be used in your Caps",
+ },
+] as const;
+
+export default function () {
+ const [initialCheck, setInitialCheck] = createSignal(true);
+ const [check, checkActions] = createResource(() =>
+ commands.doPermissionsCheck(initialCheck())
+ );
+
+ createEffect(() => {
+ if (!initialCheck()) {
+ createTimer(
+ () => startTransition(() => checkActions.refetch()),
+ 250,
+ setInterval
+ );
+ }
+ });
+
+ const requestPermission = (permission: OSPermission) => {
+ console.log({ permission });
+ try {
+ commands.requestPermission(permission);
+ } catch (err) {
+ console.error(`Error occurred while requesting permission: ${err}`);
+ }
+ setInitialCheck(false);
+ };
+
+ const openSettings = (permission: OSPermission) => {
+ commands.openPermissionSettings(permission);
+ setInitialCheck(false);
+ };
+
+ return (
+ <div class="flex flex-col p-[1rem] text-[0.875rem] font-[400] flex-1 bg-gray-100 justify-between">
+ <div class="flex flex-col items-center">
+ <IconCapLogo class="size-16 mb-1" />
+ <h1 class="text-[1rem] font-[700] mb-0.5">Permissions Required</h1>
+ <p class="text-gray-400">Cap needs permissions to run properly.</p>
+ </div>
+
+ <ul class="flex flex-col gap-4">
+ <For each={permissions}>
+ {(permission) => {
+ const permissionCheck = () => check()?.[permission.key];
+
+ return (
+ <Show when={permissionCheck() !== "notNeeded"}>
+ <li class="flex flex-row items-center gap-4">
+ <div class="flex flex-col flex-[2]">
+ <span class="font-[500] text-[0.875rem]">
+ {permission.name} Permission
+ </span>
+ <span class="text-gray-400">{permission.description}</span>
+ </div>
+ <Button
+ class="flex-1 shrink-0"
+ onClick={() =>
+ permissionCheck() !== "denied"
+ ? requestPermission(permission.key)
+ : openSettings(permission.key)
+ }
+ disabled={isPermitted(permissionCheck())}
+ >
+ {permissionCheck() === "granted"
+ ? "Granted"
+ : permissionCheck() !== "denied"
+ ? "Grant Permission"
+ : "Request Permission"}
+ </Button>
+ </li>
+ </Show>
+ );
+ }}
+ </For>
+ </ul>
+
+ <Button
+ disabled={
+ permissions.find((p) => !isPermitted(check()?.[p.key])) !== undefined
+ }
+ onClick={() => {
+ startTransition(() => {
+ commands.openMainWindow().then(() => {
+ getCurrentWindow().close();
+ });
+ });
+ }}
+ >
+ Continue to Cap
+ </Button>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/routes/permissions.tsx b/apps/desktop/src/routes/permissions.tsx
deleted file mode 100644
index fed02fff3..000000000
--- a/apps/desktop/src/routes/permissions.tsx
+++ /dev/null
@@ -1,124 +0,0 @@
-import { Button } from "@cap/ui-solid";
-import { exit } from "@tauri-apps/plugin-process";
-import type { RouteSectionProps } from "@solidjs/router";
-import { commands, type OSPermissionStatus } from "~/utils/tauri";
-import {
- createEffect,
- createResource,
- Suspense,
- createSignal,
- Show,
-} from "solid-js";
-import { createTimer } from "@solid-primitives/timer";
-import { getCurrentWindow } from "@tauri-apps/api/window";
-import { Transition } from "solid-transition-group";
-
-import Header from "../components/Header";
-
-export function isPermitted(status?: OSPermissionStatus): boolean {
- return status === "granted" || status === "notNeeded";
-}
-
-export default function (props: RouteSectionProps) {
- const steps = [
- { name: "Screen Recording", key: "screenRecording" as const },
- { name: "Accessibility", key: "accessibility" as const },
- ] as const;
-
- const [currentStepIndex, setCurrentStepIndex] = createSignal(0);
- const [initialCheck, setInitialCheck] = createSignal(true);
- const [check, checkActions] = createResource(() =>
- commands.doPermissionsCheck(initialCheck())
- );
- const currentStep = () => steps[currentStepIndex()];
- const currentStepStatus = () => check.latest?.[currentStep().key];
-
- createEffect(() => {
- if (!initialCheck()) {
- createTimer(() => checkActions.refetch(), 250, setInterval);
- }
- });
-
- createEffect(() => {
- const c = check.latest;
- const neededStep = steps.findIndex((step) => !isPermitted(c?.[step.key]));
-
- if (neededStep === -1) {
- // We wait for the window to open as closing immediately after seems to cause an unlabeled crash
- commands.openMainWindow().then(() => {
- const window = getCurrentWindow();
- window.close();
- });
- } else {
- setCurrentStepIndex(neededStep);
- }
- });
-
- const requestPermission = () => {
- try {
- commands.requestPermission(currentStep().key);
- } catch (err) {
- console.error(`Error occurred while requesting permission: ${err}`);
- }
- setInitialCheck(false);
- };
-
- const openSettings = () => {
- commands.openPermissionSettings(currentStep().key);
- setInitialCheck(false);
- };
-
- return (
- <div class="rounded-[1.5rem] bg-gray-100 border border-gray-200 w-screen h-screen flex flex-col overflow-hidden">
- <Header />
- <Suspense
- fallback={
- <div class="w-full h-full flex items-center justify-center bg-gray-100">
- <div class="animate-spin">
- <IconCapLogo class="size-[4rem]" />
- </div>
- </div>
- }
- >
- <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] flex-1 bg-gray-100">
- <div class="space-y-[0.375rem] flex-1">
- <IconCapLogo class="size-[3rem]" />
- <h1 class="text-[1rem] font-[700]">Permissions Required</h1>
- <p class="text-gray-400">Cap needs permissions to run properly.</p>
- </div>
- <Transition
- mode="outin"
- enterActiveClass="transition-opacity"
- exitActiveClass="transition-opacity"
- enterClass="opacity-0"
- exitToClass="opacity-0"
- >
- <Show when={currentStep()} keyed>
- <div class="flex flex-col items-start gap-1">
- <h4 class="font-[500] text-[0.875rem]">
- {currentStep().name} Permission
- </h4>
- <Show
- when={currentStepStatus() !== "denied"}
- fallback={
- <Button onClick={openSettings} class="w-full">
- Open Settings
- </Button>
- }
- >
- <Button
- onClick={requestPermission}
- disabled={currentStepStatus() !== "empty"}
- class="w-full"
- >
- Grant {currentStep().name} Permission
- </Button>
- </Show>
- </div>
- </Show>
- </Transition>
- </div>
- </Suspense>
- </div>
- );
-}
diff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.ts
index 85c266bb7..3e56a17d7 100644
--- a/packages/ui-solid/src/auto-imports.d.ts
+++ b/packages/ui-solid/src/auto-imports.d.ts
@@ -58,6 +58,6 @@ declare global {
const IconLucideLoaderCircle: typeof import('~icons/lucide/loader-circle.jsx')['default']
const IconLucideRewind: typeof import("~icons/lucide/rewind.jsx")["default"]
const IconLucideSettings: typeof import("~icons/lucide/settings.jsx")["default"]
- const IconLucideSmile: typeof import("~icons/lucide/smile.jsx")["default"]
+ const IconLucideSmile: typeof import('~icons/lucide/smile.jsx')['default']
const IconLucideVideo: typeof import('~icons/lucide/video.jsx')['default']
}