Repository: mediar-ai/screenpipe
File: screenpipe-app-tauri/lib/hooks/use-settings.tsx (TypeScript)

Code before:
          ? "windows-native"
          : "tesseract";


      // no need to call load() as it's done automatically
      const savedKey = (await store!.get<string>("openaiApiKey")) || "";
      const savedDeepgramKey =
        (await store!.get<string>("deepgramApiKey")) || "";
      const savedAiModel = (await store!.get<string>("aiModel")) || "gpt-4o";
      const savedInstalledPipes =
        (await store!.get<Pipe[]>("installedPipes")) || [];
      const savedUserId = (await store!.get<string>("userId")) || "";
      const savedCustomPrompt =
        (await store!.get<string>("customPrompt")) || "";
      let savedDevMode = await store!.get<boolean>("devMode");
      if (savedDevMode === null) {
        savedDevMode = false;
      }

      const savedAudioTranscriptionEngine =
        (await store!.get<string>("audioTranscriptionEngine")) || "deepgram";
      const savedOcrEngine =
        (await store!.get<string>("ocrEngine")) || ocrModel;
      const savedMonitorIds = (await store!.get<string[]>("monitorIds")) || [
        "default",
      ];
      const savedAudioDevices = (await store!.get<string[]>(
        "audioDevices"
      )) || ["default"];
      let savedUsePiiRemoval = await store!.get<boolean>("usePiiRemoval");
      if (savedUsePiiRemoval === null) {
        savedUsePiiRemoval = false;
      }
      const savedRestartInterval =
        (await store!.get<number>("restartInterval")) || 0;
      const savedPort = (await store!.get<number>("port")) || 3030;
      const savedDataDir = (await store!.get<string>("dataDir")) || "default";
      let savedDisableAudio = await store!.get<boolean>("disableAudio");
      if (savedDisableAudio === null) {
        savedDisableAudio = false;
      }

      const savedIncludedWindows =
        (await store!.get<string[]>("includedWindows")) || [];
      const savedAiUrl =
        (await store!.get<string>("aiUrl")) || "https://api.openai.com/v1";
      const savedAiMaxContextChars =
        (await store!.get<number>("aiMaxContextChars")) || 30000;
      const savedFps =
        (await store!.get<number>("fps")) ||
        (currentPlatform === "macos" ? 0.2 : 1);

Review comment (suggestion):
@oliverqx you're just changing settings to default values of settings but some values are meant to be set dynamically as an example the `fps` value in `defaultSettings` object is 0.5 and this `resetSettings` function is going to set the `fps` value `0.5` on all os but it should change the values of fps dynamically depending upon os

```typescript
        const savedFps =
          (await store!.get<number>("fps")) ||
          (currentPlatform === "macos" ? 0.2 : 1);
```

also there are some unused imports!


Code after:
  const [settings, setSettings] = useState<Settings>(DEFAULT_SETTINGS);

  useEffect(() => {
    posthog.identify(settings.userId);
  }, [settings.userId]);

  const resetSetting = async (key: keyof Settings) => {
    if (!store) {
      await initStore();
    }

    const defaultSettings = createDefaultSettingsObject(platform())

    try {
      const updatedSettings = { ...settings, [key]: defaultSettings[key] };
      setSettings(updatedSettings);
      await store!.set(key, defaultSettings[key]);
      // No need to call save() as we're using autoSave: true
    } catch (error) {
      console.error(`failed to reset setting ${key}:`, error);
      // revert local state if store update fails
      setSettings(settings);
    }
  };

  const resetSettings = async () => {
    const userSettings = createDefaultSettingsObject(
      platform()
    )

    updateSettings(userSettings)
  }

  const loadSettings = async () => {
    if (!store) {
      await initStore();
    }

    try {
      const currentPlatform = platform();
      const userSettings = await createUserSettings(
        store!,
        currentPlatform
      )

      setSettings({...userSettings, isLoading: false});
    } catch (error) {
      console.error("failed to load settings:", error);
      setSettings((prevSettings) => ({ ...prevSettings,  isLoading: false }));
    }
  };