Skip to content

Commit

Permalink
release-app fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Feb 8, 2025
1 parent a9dd529 commit bc122af
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resolver = "2"


[workspace.package]
version = "0.2.36"
version = "0.2.37"
authors = ["louis030195 <[email protected]>"]
description = ""
repository = "https://github.com/mediar-ai/screenpipe"
Expand Down
2 changes: 1 addition & 1 deletion pipes/obsidian/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian",
"version": "0.1.12",
"version": "0.1.13",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
Expand Down
16 changes: 6 additions & 10 deletions pipes/obsidian/src/components/obsidian-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export function ObsidianSettings() {
description: "your obsidian settings have been updated",
});
} catch (err) {
// dismiss loading toast and show error
loadingToast.update({
id: loadingToast.id,
title: "error",
Expand Down Expand Up @@ -198,17 +197,14 @@ export function ObsidianSettings() {
input.value = path;
}

await updateSettings(
{
customSettings: {
obsidian: {
...settings.customSettings?.obsidian,
path,
},
await updateSettings({
customSettings: {
obsidian: {
...settings.customSettings?.obsidian,
path,
},
},
"obsidian"
);
});

toast({
title: "path updated",
Expand Down
177 changes: 41 additions & 136 deletions pipes/obsidian/src/lib/hooks/use-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { useState, useEffect } from "react";
import { getDefaultSettings, type Settings } from "@screenpipe/browser";

const SETTINGS_KEY = "screenpipe_settings";

export function useSettings() {
const defaultSettings = getDefaultSettings();

Expand Down Expand Up @@ -37,41 +39,18 @@ if you do your job well, i'll give you a 🍺 and $1m`,
},
};

const [settings, setSettings] = useState<Settings | null>(null);
const [settings, setSettings] = useState<Settings | null>(() => {
if (typeof window !== "undefined") {
const saved = localStorage.getItem(SETTINGS_KEY);
return saved ? JSON.parse(saved) : null;
}
return null;
});
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
const loadSettings = async () => {
if (!loading) setLoading(true);
try {
const response = await fetch("/api/settings");
const data = await response.json();
console.log("useSettings data", data?.customSettings?.obsidian);
setSettings({ ...defaultSettings, ...data });
} catch (err) {
console.error("failed to load settings:", err);
setSettings(defaultSettings);
setError(err as Error);
} finally {
setLoading(false);
}
};

// Initial load
loadSettings();

// Refresh on window focus
const onFocus = () => loadSettings();
window.addEventListener("focus", onFocus);

// Optional: periodic refresh every 30s
const interval = setInterval(loadSettings, 2000);

return () => {
window.removeEventListener("focus", onFocus);
clearInterval(interval);
};
setLoading(false);
}, []);

const updateSetting = async <T extends keyof Settings>(
Expand All @@ -81,74 +60,30 @@ if you do your job well, i'll give you a 🍺 and $1m`,
) => {
if (!settings) return;
try {
await fetch("/api/settings", {
method: "PUT",
body: JSON.stringify({ key, value, namespace }),
});

if (namespace) {
setSettings((prev) => {
if (!prev) return defaultSettings;
return {
...prev,
customSettings: {
...prev.customSettings,
[namespace]: {
...(prev.customSettings?.[namespace] || {}),
[key]: value,
},
},
};
});
} else {
setSettings((prev) => {
if (!prev) return defaultSettings;
return { ...prev, [key]: value };
});
}
const updatedSettings = {
...settings,
customSettings: {
...settings.customSettings,
[namespace || "default"]: {
...(settings.customSettings?.[namespace || "default"] || {}),
[key]: value,
},
},
};
setSettings(updatedSettings);
localStorage.setItem(SETTINGS_KEY, JSON.stringify(updatedSettings));
} catch (err) {
setError(err as Error);
}
};

const updateSettings = async (
newSettings: Partial<Settings>,
namespace?: string
) => {
if (!settings) return;
try {
await fetch("/api/settings", {
method: "PUT",
body: JSON.stringify({
value: newSettings,
isPartialUpdate: true,
namespace,
}),
});

if (namespace) {
setSettings((prev) => {
if (!prev) return defaultSettings;
return {
...prev,
customSettings: {
...prev.customSettings,
[namespace]: {
...(prev.customSettings?.[namespace] || {}),
...newSettings,
},
},
};
});
} else {
setSettings((prev) => {
if (!prev) return defaultSettings;
return { ...prev, ...newSettings };
});
}
} catch (err) {
setError(err as Error);
}
const updateSettings = async (newSettings: any) => {
const updatedSettings = {
...settings,
...newSettings,
};
setSettings(updatedSettings);
localStorage.setItem(SETTINGS_KEY, JSON.stringify(updatedSettings));
};

const resetSettings = async (
Expand All @@ -157,48 +92,18 @@ if you do your job well, i'll give you a 🍺 and $1m`,
) => {
if (!settings) return;
try {
await fetch("/api/settings", {
method: "PUT",
body: JSON.stringify({ reset: true, key: settingKey, namespace }),
});

if (namespace) {
setSettings((prev) => {
if (!prev) return defaultSettings;
if (settingKey) {
return {
...prev,
customSettings: {
...prev.customSettings,
[namespace]: {
...(prev.customSettings?.[namespace] || {}),
[settingKey]: undefined,
},
},
};
} else {
return {
...prev,
customSettings: {
...prev.customSettings,
[namespace]: {},
},
};
}
});
} else {
if (settingKey) {
setSettings((prev) => {
if (!prev) return defaultSettings;
return {
...prev,
[settingKey]: defaultSettings[settingKey],
};
});
} else {
setSettings(defaultSettings);
}
}
const updatedSettings = {
...settings,
customSettings: {
...settings.customSettings,
[namespace || ("default" as string)]: {
...(settings.customSettings?.[namespace || "default"] || {}),
[settingKey as string]: undefined,
},
},
};
setSettings(updatedSettings);
localStorage.setItem(SETTINGS_KEY, JSON.stringify(updatedSettings));
} catch (err) {
setError(err as Error);
}
Expand Down
2 changes: 1 addition & 1 deletion 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.32.1"
version = "0.32.2"
description = ""
authors = ["you"]
license = ""
Expand Down
4 changes: 3 additions & 1 deletion screenpipe-core/src/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ done

tokio::fs::write(&script_path, script_content).await?;

if !cfg!(windows) {
// Set executable permissions on Unix systems only
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = tokio::fs::metadata(&script_path).await?.permissions();
perms.set_mode(0o755);
Expand Down

0 comments on commit bc122af

Please sign in to comment.