Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: codegen functions types #1092

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions screenpipe-app-tauri/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import { Button } from "@/components/ui/button";
import { Plus } from "lucide-react";
import { platform } from "@tauri-apps/plugin-os";
import PipeStore from "@/components/pipe-store";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { useProfiles } from "@/lib/hooks/use-profiles";
import { relaunch } from "@tauri-apps/plugin-process";
import { commands } from "@/types/tauri";
import { PipeApi } from "@/lib/api";


export default function Home() {
const { settings } = useSettings();
const { setActiveProfile } = useProfiles();
Expand All @@ -42,7 +43,7 @@ export default function Home() {
useEffect(() => {
const unlisten = Promise.all([
listen("shortcut-start-recording", async () => {
await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();

toast({
title: "recording started",
Expand All @@ -51,7 +52,7 @@ export default function Home() {
}),

listen("shortcut-stop-recording", async () => {
await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();

toast({
title: "recording stopped",
Expand All @@ -68,11 +69,11 @@ export default function Home() {
description: `switched to ${profile} profile, restarting screenpipe now`,
});

await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();

await new Promise((resolve) => setTimeout(resolve, 1000));

await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();

await new Promise((resolve) => setTimeout(resolve, 1000));
relaunch();
Expand All @@ -84,11 +85,8 @@ export default function Home() {
const pipeApi = new PipeApi();
const pipeList = await pipeApi.listPipes();
const pipe = pipeList.find(p => p.id === pipeId);
if (pipe) {
await invoke("open_pipe_window", {
port: pipe.port,
title: pipe.id,
});
if (pipe && pipe.port) {
await commands.openPipeWindow(pipe.port, pipe.id);
}
})

Expand Down
6 changes: 3 additions & 3 deletions screenpipe-app-tauri/components/dev-mode-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { platform } from "@tauri-apps/plugin-os";
import { Label } from "./ui/label";
import { Switch } from "./ui/switch";
import { useSettings } from "@/lib/hooks/use-settings";
import { invoke } from "@tauri-apps/api/core";
import { useToast } from "./ui/use-toast";
import {
Tooltip,
Expand All @@ -19,6 +18,7 @@ import { Separator } from "./ui/separator";
import { Card, CardContent, CardFooter } from "./ui/card";

import { CliCommandDialog } from "./cli-command-dialog";
import { commands } from "@/types/tauri";

const getDebuggingCommands = (os: string | null, dataDir: string) => {
let cliInstructions = "";
Expand Down Expand Up @@ -121,7 +121,7 @@ export const DevModeSettings = ({ localDataDir }: { localDataDir: string }) => {
duration: Infinity,
});
try {
await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();
await new Promise((resolve) => setTimeout(resolve, 2000));
toastId.update({
id: toastId.id,
Expand Down Expand Up @@ -152,7 +152,7 @@ export const DevModeSettings = ({ localDataDir }: { localDataDir: string }) => {
duration: Infinity,
});
try {
await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();
await new Promise((resolve) => setTimeout(resolve, 2000));
toastId.update({
id: toastId.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Card, CardContent } from "@/components/ui/card";
import { DialogHeader, DialogTitle } from "@/components/ui/dialog";
import OnboardingNavigation from "@/components/onboarding/navigation";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "@/types/tauri";

interface OnboardingDevOrNonDevProps {
className?: string;
Expand Down Expand Up @@ -90,7 +91,7 @@ const OnboardingDevOrNonDev: React.FC<OnboardingDevOrNonDevProps> = ({
variant: "default",
});
// TODO: should give better user feedback
await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();
}
} catch (error: any) {
toast({
Expand Down
1 change: 0 additions & 1 deletion screenpipe-app-tauri/components/pipe-config-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Input } from "./ui/input";
import { Button } from "./ui/button";
import { Label } from "./ui/label";
import { Checkbox } from "./ui/checkbox";
import { invoke } from "@tauri-apps/api/core";
import {
Tooltip,
TooltipContent,
Expand Down
18 changes: 9 additions & 9 deletions screenpipe-app-tauri/components/pipe-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import { useSettings } from "@/lib/hooks/use-settings";
import { useUser } from "@/lib/hooks/use-user";
import { PipeStoreMarkdown } from "@/components/pipe-store-markdown";
import { PublishDialog } from "./publish-dialog";
import { invoke } from "@tauri-apps/api/core";
import { Progress } from "@/components/ui/progress";
import supabase from "@/lib/supabase/client";
import { CreditPurchaseDialog } from "./store/credit-purchase-dialog";
import { commands } from "@/types/tauri";

export interface Pipe {
enabled: boolean;
Expand Down Expand Up @@ -977,10 +977,10 @@ const PipeStore: React.FC = () => {
variant="default"
onClick={async () => {
try {
await invoke("open_pipe_window", {
port: selectedPipe.config!.port,
title: selectedPipe.id,
});
await commands.openPipeWindow(
selectedPipe.config!.port,
selectedPipe.id
);
} catch (err) {
console.error("failed to open pipe window:", err);
toast({
Expand Down Expand Up @@ -1255,10 +1255,10 @@ const PipeStore: React.FC = () => {
(p) => p.id === pipe.id
);
if (installedPipe?.config?.port) {
invoke("open_pipe_window", {
port: installedPipe.config.port,
title: installedPipe.id,
}).catch((err) => {
commands.openPipeWindow(
installedPipe.config.port,
installedPipe.id
).catch((err) => {
console.error(
"failed to open pipe window:",
err
Expand Down
16 changes: 9 additions & 7 deletions screenpipe-app-tauri/components/recording-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
} from "@/lib/hooks/use-settings";
import { useToast } from "@/components/ui/use-toast";
import { useHealthCheck } from "@/lib/hooks/use-health-check";
import { invoke } from "@tauri-apps/api/core";
import { Badge } from "./ui/badge";
import {
Tooltip,
Expand All @@ -70,6 +69,7 @@ import { MultiSelect } from "@/components/ui/multi-select";
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
import { useSqlAutocomplete } from "@/lib/hooks/use-sql-autocomplete";
import { relaunch } from "@tauri-apps/plugin-process";
import { commands } from "@/types/tauri";

type PermissionsStatus = {
screenRecording: string;
Expand Down Expand Up @@ -297,11 +297,11 @@ export function RecordingSettings() {
}
}

await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();

await new Promise((resolve) => setTimeout(resolve, 1000));
// Start a new instance with updated settings
await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();

await new Promise((resolve) => setTimeout(resolve, 2000));
// await relaunch();
Expand Down Expand Up @@ -626,9 +626,7 @@ export function RecordingSettings() {
try {
if (checked) {
// Check accessibility permissions first
const perms = await invoke<PermissionsStatus>("do_permissions_check", {
initialCheck: false,
});
const perms = await commands.doPermissionsCheck(false);
if (!perms.accessibility) {
toast({
title: "accessibility permission required",
Expand All @@ -637,7 +635,11 @@ export function RecordingSettings() {
action: (
<ToastAction
altText="open preferences"
onClick={() => invoke("open_accessibility_preferences")}
onClick={() => {
// TODO: fix this unimplemented function
// invoke("open_accessibility_preferences")
}
}
>
open preferences
</ToastAction>
Expand Down
15 changes: 9 additions & 6 deletions screenpipe-app-tauri/components/screenpipe-instance-checker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
requestPermission,
sendNotification,
} from "@tauri-apps/plugin-notification";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "@/types/tauri";

const ScreenpipeInstanceChecker: React.FC = () => {
useEffect(() => {
Expand All @@ -24,10 +24,10 @@ const ScreenpipeInstanceChecker: React.FC = () => {
if (event.actionTypeId === "is_running_multiple_instances") {
console.log("Action received:", event);

await invoke("kill_all_screenpipes");
await commands.killAllSreenpipes();
// sleep 2s
await new Promise((resolve) => setTimeout(resolve, 2000));
await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();
sendNotification({
title: "Screenpipe Restarted",
body: "All instances have been stopped and Screenpipe has been restarted.",
Expand All @@ -52,9 +52,12 @@ const ScreenpipeInstanceChecker: React.FC = () => {
return;
}

const multipleInstances = await invoke<boolean>(
"is_running_multiple_instances"
);
// TODO: fix this unimplemented function
// const multipleInstances = await invoke<boolean>(
// "is_running_multiple_instances"
// );

const multipleInstances = false;

if (multipleInstances) {
sendNotification({
Expand Down
15 changes: 6 additions & 9 deletions screenpipe-app-tauri/components/screenpipe-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";
import { Check, X } from "lucide-react";
import { useSettings } from "@/lib/hooks/use-settings";
import { commands } from "@/types/tauri";

type PermissionsStatus = {
screenRecording: string;
Expand Down Expand Up @@ -182,13 +183,9 @@ const HealthStatus = ({ className }: { className?: string }) => {
? "microphone"
: "accessibility";

await invoke("request_permission", {
permission: permissionType,
});
await commands.requestPermission(permissionType);

const perms = await invoke<PermissionsStatus>("do_permissions_check", {
initialCheck: false,
});
const perms = await commands.doPermissionsCheck(false);

setPermissions({
screenRecording: perms.screenRecording,
Expand All @@ -198,10 +195,10 @@ const HealthStatus = ({ className }: { className?: string }) => {

const granted =
type === "screen"
? perms.screenRecording === "Granted"
? perms.screenRecording === "granted"
: type === "audio"
? perms.microphone === "Granted"
: perms.accessibility === "Granted";
? perms.microphone === "granted"
: perms.accessibility === "granted";

toastId.update({
id: toastId.id,
Expand Down
5 changes: 3 additions & 2 deletions screenpipe-app-tauri/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { relaunch } from "@tauri-apps/plugin-process";
import { invoke } from "@tauri-apps/api/core";
import { useProfiles } from "@/lib/hooks/use-profiles";
import { toast } from "./ui/use-toast";
import { commands } from "@/types/tauri";

type SettingsSection = "ai" | "shortcuts" | "recording" | "account";

Expand All @@ -54,11 +55,11 @@ export function Settings() {
title: "Restarting Screenpipe",
description: "Please wait while we restart Screenpipe",
});
await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();

await new Promise((resolve) => setTimeout(resolve, 1000));

await invoke("spawn_screenpipe");
await commands.spawnScreenpipe();

await new Promise((resolve) => setTimeout(resolve, 1000));
relaunch();
Expand Down
3 changes: 2 additions & 1 deletion screenpipe-app-tauri/components/settings/ai-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { commands } from "@/types/tauri";

interface AIProviderCardProps {
type: "screenpipe-cloud" | "openai" | "native-ollama" | "custom" | "embedded";
Expand Down Expand Up @@ -218,7 +219,7 @@ const AISection = () => {

const handleStopLLM = async () => {
try {
await invoke("stop_ollama_sidecar");
await commands.stopOllamaSidecar();
setOllamaStatus("idle");
setEmbeddedAIStatus("idle");
toast({
Expand Down
3 changes: 2 additions & 1 deletion screenpipe-app-tauri/components/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ask, message } from "@tauri-apps/plugin-dialog";
import { relaunch } from "@tauri-apps/plugin-process";
import { invoke } from "@tauri-apps/api/core";
import { platform } from "@tauri-apps/plugin-os";
import { commands } from "@/types/tauri";

export async function checkForAppUpdates({ toast }: { toast: any }) {
const update = await check();
Expand All @@ -25,7 +26,7 @@ Release notes: ${update.body}
// on windows only - TODO shouldnt be necessary
const os = platform();
if (os === "windows") {
await invoke("kill_all_sreenpipes");
await commands.killAllSreenpipes();
}

const toastId = toast({
Expand Down
10 changes: 5 additions & 5 deletions screenpipe-app-tauri/lib/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invoke } from "@tauri-apps/api/core";
import { Shortcut } from "./hooks/use-settings";
import { commands } from "@/types/tauri";

export async function registerShortcuts({
showScreenpipeShortcut,
Expand All @@ -8,8 +8,8 @@ export async function registerShortcuts({
showScreenpipeShortcut: string;
disabledShortcuts: Shortcut[];
}) {
invoke("update_show_screenpipe_shortcut", {
new_shortcut: showScreenpipeShortcut,
enabled: !disabledShortcuts.includes(Shortcut.SHOW_SCREENPIPE),
});
commands.updateShowScreenpipeShortcut(
showScreenpipeShortcut,
!disabledShortcuts.includes(Shortcut.SHOW_SCREENPIPE)
);
}
Loading
Loading