Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(desktop): tighten settings typing and external actions

Richie McIlroyfb97d3e36854
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/Setting.tsx b/apps/desktop/src/routes/(window-chrome)/settings/Setting.tsx
index 9f182f4a6..019b79829 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/Setting.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/Setting.tsx
@@ -1,10 +1,11 @@
+import type { JSX } from "solid-js";
import { Toggle } from "~/components/Toggle";
export function SettingItem(props: {
pro?: boolean;
label: string;
description?: string;
- children: any;
+ children: JSX.Element;
}) {
return (
<div class="flex flex-row gap-2 justify-between items-center py-3 text-sm">
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
index dde7ede63..8e59e5af9 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
@@ -1,16 +1,23 @@
import { Button } from "@cap/ui-solid";
import { action, useAction, useSubmission } from "@solidjs/router";
import { getVersion } from "@tauri-apps/api/app";
-import { type as ostype } from "@tauri-apps/plugin-os";
+import { type OsType, type as ostype } from "@tauri-apps/plugin-os";
+import * as shell from "@tauri-apps/plugin-shell";
import { createResource, createSignal, For, Show } from "solid-js";
import toast from "solid-toast";
import { commands, type SystemDiagnostics } from "~/utils/tauri";
import { apiClient, protectedHeaders } from "~/utils/web-api";
+const getFeedbackOs = (): Extract<OsType, "macos" | "windows"> => {
+ const os = ostype();
+ if (os === "macos" || os === "windows") return os;
+ throw new Error(`Unsupported OS for feedback submission: ${os}`);
+};
+
const sendFeedbackAction = action(async (feedback: string) => {
const response = await apiClient.desktop.submitFeedback({
- body: { feedback, os: ostype() as any, version: await getVersion() },
+ body: { feedback, os: getFeedbackOs(), version: await getVersion() },
headers: await protectedHeaders(),
});
@@ -109,7 +116,7 @@ export default function FeedbackTab() {
Cap Discord community.
</p>
<Button
- onClick={() => window.open("https://cap.link/discord", "_blank")}
+ onClick={() => shell.open("https://cap.link/discord")}
size="md"
variant="gray"
>
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx b/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx
index 2ac89cecd..fd8daa96d 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/hotkeys.tsx
@@ -53,7 +53,7 @@ function Inner(props: { initialStore: HotkeysStore | null }) {
}>(props.initialStore?.hotkeys ?? {});
createEffect(() => {
- hotkeysStore.set({ hotkeys: { ...hotkeys } as any });
+ hotkeysStore.set({ hotkeys: { ...hotkeys } as HotkeysStore["hotkeys"] });
});
const [listening, setListening] = createSignal<{
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/license.tsx b/apps/desktop/src/routes/(window-chrome)/settings/license.tsx
index 6709433f1..1b33c3653 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/license.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/license.tsx
@@ -108,13 +108,15 @@ function LicenseKeyActivate(props: {
<Show when={store()}>
{(generalSettings) => {
const [licenseKey, setLicenseKey] = createSignal("");
+ const instanceId = generalSettings().instanceId;
+ if (!instanceId) throw new Error("No instance ID found");
const activateLicenseKey = createMutation(() => ({
mutationFn: async (vars: { licenseKey: string }) => {
const resp = await licenseApiClient.activateCommercialLicense({
headers: {
licensekey: vars.licenseKey,
- instanceid: generalSettings().instanceId!,
+ instanceid: instanceId,
},
body: { reset: false },
});
@@ -126,7 +128,7 @@ function LicenseKeyActivate(props: {
"message" in resp.body
)
throw resp.body.message;
- throw new Error((resp.body as any).toString());
+ throw new Error(String(resp.body));
},
onSuccess: (value, { licenseKey }) => {
props.onActivated({ ...value, licenseKey });