Skip to content

Commit

Permalink
fix: issue with settings
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Aug 28, 2024
1 parent a42c20a commit 6bad85c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
33 changes: 26 additions & 7 deletions examples/apps/screenpipe-app-tauri/components/dev-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function DevSettings() {
const [isSaving, setIsSaving] = useState(false);
const { toast } = useToast();

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

Expand All @@ -36,13 +36,32 @@ export function DevSettings() {
});

try {
await updateSettings(localSettings);
await new Promise((resolve) => setTimeout(resolve, 1000));
// Create an object to store only the changed settings
const changedSettings = Object.entries(localSettings).reduce(
(acc, [key, value]) => {
if (value !== settings[key as keyof typeof settings]) {
acc[key as keyof typeof settings] = value;
}
return acc;
},
{} as Partial<typeof settings>
);

toast({
title: "dev settings updated successfully",
description: "your changes have been saved.",
});
// Only update if there are changes
if (Object.keys(changedSettings).length > 0) {
await updateSettings(changedSettings);
await new Promise((resolve) => setTimeout(resolve, 1000));

toast({
title: "dev settings updated successfully",
description: "your changes have been saved.",
});
} else {
toast({
title: "no changes detected",
description: "no settings were updated.",
});
}
} catch (error) {
console.error("failed to update dev settings:", error);
toast({
Expand Down
27 changes: 12 additions & 15 deletions examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ sqlite3 "${dbPath}" "SELECT * FROM audio_transcriptions ORDER BY timestamp DESC
const DevModeSettings = () => {
const { settings, updateSettings } = useSettings();
const [localSettings, setLocalSettings] = useState(settings);
const handleDevModeToggle = (checked: boolean) => {
setLocalSettings((prev) => ({ ...prev, devMode: checked }));
updateSettings({ devMode: checked });
const handleDevModeToggle = async (checked: boolean) => {
try {
await updateSettings({ devMode: checked });
setLocalSettings((prev) => ({ ...prev, devMode: checked }));
// ... rest of the function ...
} catch (error) {
console.error("Failed to update dev mode:", error);
// Add error handling, e.g., show a toast notification
}
};
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();

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

Expand Down Expand Up @@ -336,21 +342,12 @@ const HealthStatus = ({ className }: { className?: string }) => {

try {
await invoke("open_screen_capture_preferences");
await new Promise((resolve) => setTimeout(resolve, 2000));

toastId.update({
id: toastId.id,
title: "permissions reset",
description:
"screen capture permissions have been reset. please restart the app.",
duration: 5000,
});
} catch (error) {
console.error("failed to reset screen permissions:", error);
console.error("failed to open screen permissions:", error);
toastId.update({
id: toastId.id,
title: "error",
description: "failed to reset screen permissions.",
description: "failed to open screen permissions.",
variant: "destructive",
duration: 3000,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ export function useHealthCheck() {
throw new Error(`HTTP error! status: ${response.status} ${text}`);
}
const data: HealthCheckResponse = await response.json();
if (health !== null && health.status === data.status) {
if (
(health !== null && health.status === data.status) ||
// did not change
(health != null &&
health.status_code === data.status_code &&
health.message === data.message)
) {
return;
}
console.log("setting health", data);
setHealth(data);
} catch (error) {
console.error("Failed to fetch health status:", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let store: Store | null = null;
export function useSettings() {
const [settings, setSettings] = useState<Settings>(defaultSettings);

// console.log("settings", settings);
const resetSetting = async (key: keyof Settings) => {
if (!store) {
await initStore();
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/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.1.70"
version = "0.1.71"
description = ""
authors = ["you"]
license = ""
Expand Down

0 comments on commit 6bad85c

Please sign in to comment.