Skip to content

Commit

Permalink
fix setting not save properly in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SeakMengs committed Aug 14, 2023
1 parent 6bada52 commit 954e590
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import SettingWindow from "./SettingWindow";
import Canvas from "./Canvas";
import { getAppSettings } from "./utils/settingsHelper";
import { useSettingStore } from "./hooks/useSettingStore";
import { isEnabled } from "tauri-plugin-autostart-api";

function App() {

const { setLanguage, setTheme } = useSettingStore();
const { setLanguage, setTheme, setIsAutoStartUp } = useSettingStore();

// initialize settings
useEffect(() => {
getAppSettings({}).then((settings) => {
setLanguage(settings.language);
setTheme(settings.theme);
});

isEnabled().then((enabled) => {
setIsAutoStartUp(enabled);
})
}, []);

return (
Expand Down
10 changes: 1 addition & 9 deletions src/components/setting_tabs/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ import { SelectItem } from "./settings/SelectItem";
import languages from "../../locale/languages";
import SettingSwitch from "./settings/SettingSwitch";
import { useTranslation } from "react-i18next";
import { isEnabled } from "tauri-plugin-autostart-api";
import { handleSettingChange } from "../../utils/handleSettingChange";
import { SettingsContent } from "../../utils/type";
import { useSettingStore } from "../../hooks/useSettingStore";
import { useEffect } from "react";

function Settings() {
const { t, i18n } = useTranslation();
const { isAutoStartUp, setIsAutoStartUp } = useSettingStore();

useEffect(() => {
isEnabled().then((enabled) => {
setIsAutoStartUp(enabled);
})
}, []);
const { isAutoStartUp } = useSettingStore();

const settings: SettingsContent = {
parent: {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/settingsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api";
import { Store } from "tauri-plugin-store-api";
import { GetAppSetting, SetSetting } from "./type";
import { configDir } from "@tauri-apps/api/path"

export function toggleAutoStartUp(isAutoStartUp: boolean) {
(async () => {
Expand All @@ -19,7 +20,8 @@ export function toggleAutoStartUp(isAutoStartUp: boolean) {
};

export async function getAppSettings({ path = "settings.json", key = "app" }: GetAppSetting) {
const store = new Store(path)
const configDirPath = await configDir();
const store = new Store(`${configDirPath}WindowPet/${path}`)
const settings: any = await store.get(key);
return settings;
}
Expand All @@ -28,7 +30,8 @@ export function setSettings({ path = "settings.json", key = "app", setKey, newVa
(async () => {
let setting: any = await getAppSettings({});
setting[setKey] = newValue;
const store = new Store(path);
const configDirPath = await configDir();
const store = new Store(`${configDirPath}WindowPet/${path}`)
await store.set(key, setting);
await store.save();
})()
Expand Down

0 comments on commit 954e590

Please sign in to comment.