-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useEffect, useState } from "react"; | ||
import { getAppSettings } from "../utils/settingsFunction"; | ||
|
||
export interface ISetting { | ||
language: string, | ||
theme: 'light' | 'dark', | ||
} | ||
|
||
export default function useSetting() { | ||
const [appSetting, setAppSetting] = useState<any>(); | ||
|
||
useEffect(() => { | ||
(async function () { | ||
const setting = await getAppSettings(); | ||
setAppSetting(setting); | ||
})(); | ||
}, []); | ||
|
||
return appSetting as ISetting; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api"; | ||
import { appConfigDir } from '@tauri-apps/api/path'; | ||
import { exists } from '@tauri-apps/api/fs'; | ||
import { exists } from '@tauri-apps/api/fs'; | ||
import { Store } from "tauri-plugin-store-api"; | ||
import defaultSettings from "../settings/defaultSettings.json"; | ||
|
||
export interface ISetting { | ||
language: string, | ||
theme: 'light' | 'dark', | ||
} | ||
|
||
export async function toggleAutoStartUp(isAutoStartUp: boolean) { | ||
const hasEnabledStartUp = await isEnabled(); | ||
|
||
if (isAutoStartUp) { | ||
if (hasEnabledStartUp) return; | ||
await enable(); | ||
return; | ||
} | ||
|
||
if (hasEnabledStartUp) { | ||
await disable(); | ||
} | ||
import { ISetting } from "../hooks/useSettings"; | ||
|
||
export function toggleAutoStartUp(isAutoStartUp: boolean) { | ||
(async () => { | ||
const hasEnabledStartUp = await isEnabled(); | ||
|
||
if (isAutoStartUp) { | ||
if (hasEnabledStartUp) return; | ||
await enable(); | ||
return; | ||
} | ||
|
||
if (hasEnabledStartUp) { | ||
await disable(); | ||
} | ||
})() | ||
}; | ||
|
||
export async function getAppSettings() { | ||
const store = new Store("settings.json") | ||
const settings: ISetting | null = await store.get("app"); | ||
const settings: any = await store.get("app"); | ||
return settings; | ||
} | ||
|
||
export async function setSettings(key: string, newValue: unknown) { | ||
let setting: any = await getAppSettings(); | ||
setting[key] = newValue; | ||
const store = new Store("settings.json") | ||
await store.set("app", setting); | ||
await store.save(); | ||
} | ||
|
||
export async function createDefaultSettingsIfNotExist() { | ||
const configDirPath = await appConfigDir(); | ||
const settingsFilePath = `${configDirPath}settings.json`; | ||
const fileExists = await exists(settingsFilePath); | ||
|
||
if (!fileExists) { | ||
export function setSettings(key: string, newValue: unknown) { | ||
(async () => { | ||
let setting: any = await getAppSettings(); | ||
setting[key] = newValue; | ||
const store = new Store("settings.json") | ||
await store.set("app", defaultSettings); | ||
await store.set("app", setting); | ||
await store.save(); | ||
} | ||
})() | ||
} | ||
|
||
export function createDefaultSettingsIfNotExist() { | ||
(async () => { | ||
const configDirPath = await appConfigDir(); | ||
const settingsFilePath = `${configDirPath}settings.json`; | ||
const fileExists = await exists(settingsFilePath); | ||
|
||
if (!fileExists) { | ||
const store = new Store("settings.json") | ||
await store.set("app", defaultSettings); | ||
await store.save(); | ||
} | ||
})() | ||
} |