Skip to content

Commit

Permalink
fix: settings update issue
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Sep 30, 2024
1 parent 4f2391c commit 40dc633
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 196 deletions.
149 changes: 0 additions & 149 deletions screenpipe-app-tauri/components/dev-dialog.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions screenpipe-app-tauri/components/pipe-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { MemoizedReactMarkdown } from "@/components/markdown";
import { CodeBlock } from "@/components/ui/codeblock";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import { useSettings } from "@/lib/hooks/use-settings";
import { invoke } from "@tauri-apps/api/core";
import { toast } from "./ui/use-toast";
import { Input } from "./ui/input";
import {
Expand Down
52 changes: 27 additions & 25 deletions screenpipe-app-tauri/components/recording-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
} from "./ui/dialog";
import { CodeBlock } from "./ui/codeblock";
import { useCopyToClipboard } from "@/lib/hooks/use-copy-to-clipboard";
import { platform } from "@tauri-apps/plugin-os";

interface AudioDevice {
name: string;
Expand All @@ -76,11 +77,9 @@ interface MonitorDevice {
export function RecordingSettings({
localSettings,
setLocalSettings,
currentPlatform,
}: {
localSettings: Settings;
setLocalSettings: (settings: Settings) => void;
currentPlatform: string;
}) {
const { settings, updateSettings } = useSettings();
const [openAudioDevices, setOpenAudioDevices] = React.useState(false);
Expand All @@ -98,9 +97,7 @@ export function RecordingSettings({
const isDisabled = health?.status_code === 500;
const [isCopyDialogOpen, setIsCopyDialogOpen] = useState(false);
const { copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
console.log("localSettings", localSettings);
console.log("settings", settings);
console.log("availableMonitors", availableMonitors);

useEffect(() => {
const loadDevices = async () => {
try {
Expand Down Expand Up @@ -180,7 +177,7 @@ export function RecordingSettings({
};

loadDevices();
}, [localSettings, setLocalSettings]);
}, [settings]);

const handleUpdate = async () => {
setIsUpdating(true);
Expand Down Expand Up @@ -393,6 +390,29 @@ export function RecordingSettings({
});
};

const renderOcrEngineOptions = () => {
const currentPlatform = platform();
return (
<>
{/* <SelectItem value="unstructured">
<div className="flex items-center justify-between w-full space-x-2">
<span>unstructured</span>
<Badge variant="secondary">cloud</Badge>
</div>
</SelectItem> */}
{currentPlatform === "linux" && (
<SelectItem value="tesseract">tesseract</SelectItem>
)}
{currentPlatform === "windows" && (
<SelectItem value="windows-native">windows native</SelectItem>
)}
{currentPlatform === "macos" && (
<SelectItem value="apple-native">apple native</SelectItem>
)}
</>
);
};

return (
<>
<div className="relative">
Expand Down Expand Up @@ -460,25 +480,7 @@ export function RecordingSettings({
<SelectTrigger>
<SelectValue placeholder="select ocr engine" />
</SelectTrigger>
<SelectContent>
<SelectItem value="unstructured">
<div className="flex items-center justify-between w-full space-x-2">
<span>unstructured</span>
<Badge variant="secondary">cloud</Badge>
</div>
</SelectItem>
{currentPlatform !== "macos" && (
<SelectItem value="tesseract">tesseract</SelectItem>
)}
{currentPlatform === "windows" && (
<SelectItem value="windows-native">
windows native
</SelectItem>
)}
{currentPlatform === "macos" && (
<SelectItem value="apple-native">apple native</SelectItem>
)}
</SelectContent>
<SelectContent>{renderOcrEngineOptions()}</SelectContent>
</Select>
</div>

Expand Down
4 changes: 1 addition & 3 deletions screenpipe-app-tauri/components/screenpipe-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Button } from "./ui/button";
import { Separator } from "./ui/separator";
import { Card, CardContent, CardFooter } from "./ui/card";
import { useHealthCheck } from "@/lib/hooks/use-health-check";
import { DevSettings } from "./dev-dialog";
import { Lock, Folder, FileText, Activity } from "lucide-react";
import { open } from "@tauri-apps/plugin-shell";
import { homeDir } from "@tauri-apps/api/path";
Expand Down Expand Up @@ -122,8 +121,7 @@ const DevModeSettings = () => {
const handleDevModeToggle = async (checked: boolean) => {
try {
await updateSettings({ devMode: checked });
setLocalSettings((prev) => ({ ...prev, devMode: checked }));
// ... rest of the function ...
setLocalSettings({ ...localSettings, devMode: checked });
} catch (error) {
console.error("Failed to update dev mode:", error);
// Add error handling, e.g., show a toast notification
Expand Down
26 changes: 11 additions & 15 deletions screenpipe-app-tauri/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,45 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Textarea } from "./ui/textarea";
import { Slider } from "@/components/ui/slider"; // Add this import

import { platform } from "@tauri-apps/plugin-os";
import { Eye, EyeOff, HelpCircle, RefreshCw, Settings2 } from "lucide-react";
import { RecordingSettings } from "./recording-settings";

export function Settings({ className }: { className?: string }) {
const { settings, updateSettings, resetSetting } = useSettings();
const [localSettings, setLocalSettings] = React.useState(settings);
const [currentPlatform, setCurrentPlatform] = React.useState<string>("");
const [showApiKey, setShowApiKey] = React.useState(false);

const handleApiUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value;
setLocalSettings((prev) => ({ ...prev, aiUrl: newValue }));
setLocalSettings({ ...localSettings, aiUrl: newValue });
updateSettings({ aiUrl: newValue });
};

const handleApiKeyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value;
setLocalSettings((prev) => ({ ...prev, openaiApiKey: newValue }));
setLocalSettings({ ...localSettings, openaiApiKey: newValue });
updateSettings({ openaiApiKey: newValue });
};

const handleDeepgramApiKeyChange = (
e: React.ChangeEvent<HTMLInputElement>
) => {
const newValue = e.target.value;
setLocalSettings((prev) => ({ ...prev, deepgramApiKey: newValue }));
setLocalSettings({ ...localSettings, deepgramApiKey: newValue });
updateSettings({ deepgramApiKey: newValue });
};

const handleModelChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value;
setLocalSettings((prev) => ({ ...prev, aiModel: newValue }));
setLocalSettings({ ...localSettings, aiModel: newValue });
updateSettings({ aiModel: newValue });
};

const handleCustomPromptChange = (
e: React.ChangeEvent<HTMLTextAreaElement>
) => {
const newValue = e.target.value;
setLocalSettings((prev) => ({ ...prev, customPrompt: newValue }));
setLocalSettings({ ...localSettings, customPrompt: newValue });
updateSettings({ customPrompt: newValue });
};

Expand All @@ -73,22 +71,21 @@ export function Settings({ className }: { className?: string }) {

const handleMaxContextCharsChange = (value: number[]) => {
const newValue = value[0];
setLocalSettings((prev) => ({ ...prev, aiMaxContextChars: newValue }));
setLocalSettings({ ...localSettings, aiMaxContextChars: newValue });
updateSettings({ aiMaxContextChars: newValue });
};

React.useEffect(() => {
setLocalSettings(settings);
setCurrentPlatform(platform());
}, [settings]);

return (
<Dialog
onOpenChange={(open) => {
if (!open) {
location.reload(); // ! HACK to properly refresh stuff (tood beter)
}
}}
// onOpenChange={(open) => {
// if (!open) {
// location.reload(); // ! HACK to properly refresh stuff (tood beter)
// }
// }}
>
<DialogTrigger asChild>
<Button variant="ghost" className={className}>
Expand All @@ -107,7 +104,6 @@ export function Settings({ className }: { className?: string }) {
<RecordingSettings
localSettings={localSettings}
setLocalSettings={setLocalSettings}
currentPlatform={currentPlatform}
/>

<Separator />
Expand Down
4 changes: 2 additions & 2 deletions screenpipe-app-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
version = "0.2.79"
version = "0.2.80"
description = ""
authors = ["you"]
license = ""
Expand Down Expand Up @@ -114,4 +114,4 @@ custom-protocol = [ "tauri/custom-protocol" ]


[package.metadata.cargo-machete]
ignored = ["tauri-utils"]
ignored = ["tauri-utils"]

0 comments on commit 40dc633

Please sign in to comment.