From e7a61872b7b18edae91dd0ce6041d6305c788121 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Tue, 24 Mar 2026 22:45:28 -0700 Subject: [PATCH] Switch to Tauris json store management for settings --- bun.lock | 3 + package.json | 1 + src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 3 + src-tauri/src/lib.rs | 1 + src/app/GlobalProvider.tsx | 10 +- src/app/game/page.tsx | 26 ++-- src/app/layout.tsx | 173 ++++++++++++++++----- src/app/page.tsx | 3 +- src/app/settings/page.tsx | 225 ++++++++-------------------- src/componets/Sidebar.tsx | 15 +- src/componets/popups/Downloads.tsx | 6 +- src/lib/BazookaManager.ts | 75 ---------- src/lib/Clipboard.ts | 7 +- src/types/NormalConfig.ts | 21 --- src/types/SettingsType.ts | 9 -- 16 files changed, 239 insertions(+), 340 deletions(-) delete mode 100644 src/types/NormalConfig.ts delete mode 100644 src/types/SettingsType.ts diff --git a/bun.lock b/bun.lock index c900a04..f102e6b 100644 --- a/bun.lock +++ b/bun.lock @@ -17,6 +17,7 @@ "@tauri-apps/plugin-notification": "2.3.3", "@tauri-apps/plugin-opener": "2.5.3", "@tauri-apps/plugin-os": "2.3.2", + "@tauri-apps/plugin-store": "2.4.2", "@tauri-apps/plugin-window-state": "2.4.1", "next": "16.2.1", "pretty-bytes": "7.1.0", @@ -280,6 +281,8 @@ "@tauri-apps/plugin-os": ["@tauri-apps/plugin-os@2.3.2", "", { "dependencies": { "@tauri-apps/api": "^2.8.0" } }, "sha512-n+nXWeuSeF9wcEsSPmRnBEGrRgOy6jjkSU+UVCOV8YUGKb2erhDOxis7IqRXiRVHhY8XMKks00BJ0OAdkpf6+A=="], + "@tauri-apps/plugin-store": ["@tauri-apps/plugin-store@2.4.2", "", { "dependencies": { "@tauri-apps/api": "^2.8.0" } }, "sha512-0ClHS50Oq9HEvLPhNzTNFxbWVOqoAp3dRvtewQBeqfIQ0z5m3JRnOISIn2ZVPCrQC0MyGyhTS9DWhHjpigQE7A=="], + "@tauri-apps/plugin-window-state": ["@tauri-apps/plugin-window-state@2.4.1", "", { "dependencies": { "@tauri-apps/api": "^2.8.0" } }, "sha512-OuvdrzyY8Q5Dbzpj+GcrnV1iCeoZbcFdzMjanZMMcAEUNy/6PH5pxZPXpaZLOR7whlzXiuzx0L9EKZbH7zpdRw=="], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.1", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg=="], diff --git a/package.json b/package.json index a642ed3..467bb5a 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@tauri-apps/plugin-notification": "2.3.3", "@tauri-apps/plugin-opener": "2.5.3", "@tauri-apps/plugin-os": "2.3.2", + "@tauri-apps/plugin-store": "2.4.2", "@tauri-apps/plugin-window-state": "2.4.1", "next": "16.2.1", "pretty-bytes": "7.1.0", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3fb071e..c97fcd5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -33,6 +33,7 @@ openssl = { version = "0.10.76", features = ["v110", "vendored"] } base64 = "0.22.1" tauri-plugin-http = "2.5.7" dashmap = "6.1.0" +tauri-plugin-store = "2.4.2" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-single-instance = "2.4.0" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 2b84329..448d306 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -24,6 +24,9 @@ "notification:default", "clipboard-manager:default", "clipboard-manager:allow-write-text", + "store:default", + "store:allow-load", + "store:allow-save", "fs:allow-applocaldata-read", "fs:allow-applocaldata-write", { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8f36137..b7d038d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -620,6 +620,7 @@ async fn cancel_download(name: String) { pub fn run() { #[allow(unused_variables)] tauri::Builder::default() + .plugin(tauri_plugin_store::Builder::new().build()) .plugin(tauri_plugin_http::init()) .plugin( tauri_plugin_prevent_default::Builder::new() diff --git a/src/app/GlobalProvider.tsx b/src/app/GlobalProvider.tsx index 8ec529f..8d7035c 100644 --- a/src/app/GlobalProvider.tsx +++ b/src/app/GlobalProvider.tsx @@ -9,11 +9,11 @@ import { } from 'react' import { DownloadProgress } from '@/types/DownloadProgress' import { VersionsConfig } from '@/types/VersionsConfig' -import { NormalConfig } from '@/types/NormalConfig' import { ServerVersionsResponse } from '@/types/ServerVersionsResponse' import { GameVersion } from '@/types/GameVersion' import { Game } from '@/types/Game' import { Mod } from '@/types/Mod' +import { Store } from '@tauri-apps/plugin-store' type GlobalCtxType = { serverVersionList: ServerVersionsResponse | null @@ -29,8 +29,6 @@ type GlobalCtxType = { setFadeOut: Dispatch> downloadedVersionsConfig: VersionsConfig | null setDownloadedVersionsConfig: Dispatch> - normalConfig: NormalConfig | null - setNormalConfig: Dispatch> managingVersion: string | null setManagingVersion: Dispatch> setSelectedGame: Dispatch> @@ -63,6 +61,12 @@ type GlobalCtxType = { setViewingInfoFromDownloads: Dispatch> showModInfo: Mod | null setShowModInfo: Dispatch> + settings: Store | null + notificationsAllowed: boolean + sidebarAlwaysShowGames: boolean + unixUseWine: boolean + unixWineCommand: string + theme: string } const GlobalCtx = createContext(null) diff --git a/src/app/game/page.tsx b/src/app/game/page.tsx index 393c248..62e4d12 100644 --- a/src/app/game/page.tsx +++ b/src/app/game/page.tsx @@ -21,7 +21,6 @@ export default function Installs () { setFadeOut, setSelectedVersionList, downloadedVersionsConfig, - normalConfig, setManagingVersion, getVersionInfo, getGameInfo, @@ -31,7 +30,9 @@ export default function Installs () { setCategory, setDownloadedVersionsConfig, downloadVersions, - downloadProgress + downloadProgress, + unixUseWine, + unixWineCommand } = useGlobal() const params = useSearchParams() @@ -43,7 +44,7 @@ export default function Installs () { useEffect(() => { if (!showPopup) return setSelectedVersionList([]) - }, [normalConfig, setSelectedVersionList, showPopup]) + }, [setSelectedVersionList, showPopup]) if (!id || !game) return

Invalid game

@@ -129,11 +130,7 @@ export default function Installs () { const info = getVersionInfo(v) if (!info) return false - if ( - platform() == 'linux' && - info.wine && - !normalConfig?.settings.useWineOnUnixWhenNeeded - ) + if (platform() == 'linux' && info.wine && !unixUseWine) return false return info.game === id && info.category === Number(key) @@ -168,8 +165,7 @@ export default function Installs () { if ( platform() == 'linux' && info.wine && - !normalConfig?.settings - .useWineOnUnixWhenNeeded + !unixUseWine ) return false return ( @@ -200,11 +196,7 @@ export default function Installs () { .filter(v => { const info = getVersionInfo(v) if (!info) return false - if ( - platform() == 'linux' && - info.wine && - !normalConfig?.settings.useWineOnUnixWhenNeeded - ) + if (platform() == 'linux' && info.wine && !unixUseWine) return false return ( info.game === id && @@ -299,9 +291,9 @@ export default function Installs () { useWine: !!( platform() == 'linux' && verInfo.wine && - normalConfig?.settings.useWineOnUnixWhenNeeded + unixUseWine ), - wineCommand: normalConfig?.settings.wineOnUnixCommand + wineCommand: unixWineCommand }) }} onContextMenu={e => { diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 9319756..585e1e0 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -7,13 +7,8 @@ import { DownloadProgress } from '@/types/DownloadProgress' import { invoke } from '@tauri-apps/api/core' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faChevronLeft, faXmark } from '@fortawesome/free-solid-svg-icons' -import { - readNormalConfig, - readVersionsConfig, - writeVersionsConfig -} from '@/lib/BazookaManager' +import { readVersionsConfig, writeVersionsConfig } from '@/lib/BazookaManager' import { VersionsConfig } from '@/types/VersionsConfig' -import { NormalConfig } from '@/types/NormalConfig' import { app } from '@tauri-apps/api' import { openUrl } from '@tauri-apps/plugin-opener' import { GlobalProvider } from './GlobalProvider' @@ -24,12 +19,16 @@ import { Game } from '@/types/Game' import { listen } from '@tauri-apps/api/event' import { usePathname } from 'next/navigation' import { arch, platform } from '@tauri-apps/plugin-os' -import { notifyUser } from '@/lib/Notifications' import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification' -import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs' +import { + BaseDirectory, + exists, + readTextFile, + remove +} from '@tauri-apps/plugin-fs' import { fetch } from '@tauri-apps/plugin-http' import { verifySignature } from '@/lib/Util' import { getCurrentWindow, UserAttentionType } from '@tauri-apps/api/window' @@ -40,6 +39,8 @@ import DownloadsPopup from '@/componets/popups/Downloads' import ManageVersionPopup from '@/componets/popups/ManageVersion' import ModDownloadsPopup from '@/componets/popups/ModDownloads' import { Mod } from '@/types/Mod' +import { load, Store } from '@tauri-apps/plugin-store' +import { notifyUser } from '@/lib/Notifications' const roboto = Roboto({ subsets: ['latin'] @@ -62,7 +63,6 @@ export default function RootLayout ({ const [downloadedVersionsConfig, setDownloadedVersionsConfig] = useState(null) - const [normalConfig, setNormalConfig] = useState(null) const [showPopup, setShowPopup] = useState(false) const [popupMode, setPopupMode] = useState(null) @@ -84,20 +84,25 @@ export default function RootLayout ({ const pathname = usePathname() const revisionCheck = useRef(false) + const [settings, setSettings] = useState(null) + + const [notificationsAllowed, setNotificationsAllowed] = + useState(false) + const [sidebarAlwaysShowGames, setSidebarAlwaysShowGames] = + useState(false) + const [unixUseWine, setUnixUseWine] = useState(false) + const [unixWineCommand, setUnixWineCommand] = useState('wine %path%') + const [theme, setTheme] = useState('dark') + function getSpecialVersionsList (game?: number): GameVersion[] { - if (!normalConfig || !serverVersionList) return [] + if (!serverVersionList) return [] return serverVersionList.versions .filter( v => !Object.keys(downloadedVersionsConfig?.list ?? []).includes(v.id) ) .filter(v => { - if ( - platformName == 'linux' && - v.wine && - !normalConfig.settings.useWineOnUnixWhenNeeded - ) - return false + if (platformName == 'linux' && v.wine && unixUseWine) return false if (game && v.game != game) return false if (category != -1 && v.category != category) return false @@ -150,8 +155,7 @@ export default function RootLayout ({ } | null { if (!downloadedVersionsConfig || !serverVersionList) return null - const allowWine = - platformName !== 'linux' || normalConfig?.settings.useWineOnUnixWhenNeeded + const allowWine = platformName !== 'linux' || unixUseWine const installed = Object.keys(downloadedVersionsConfig.list).filter(v => { const info = getVersionInfo(v) @@ -353,10 +357,85 @@ export default function RootLayout ({ setLoadingText('Failed to download versions list.') return } - const normalConfig = await readNormalConfig() + const settingsLocal = await load('settings.json', { + autoSave: true, + defaults: { + version: client, + notificationsAllowed: true, + sidebarAlwaysShowGames: true, + unixUseWine: false, + unixWineCommand: 'wine %path%', + theme: 'dark' + } + }) + settingsLocal.set('version', client) + const oldSettingsOptions = { + baseDir: BaseDirectory.AppLocalData + } + if (await exists('config.json', oldSettingsOptions)) { + const config = await readTextFile('config.json', oldSettingsOptions) + const raw = JSON.parse(config) + if ( + raw.settings && + raw.settings.theme && + (raw.version == '1.0.0' || + raw.version == '1.1.0' || + raw.version == '1.1.1' || + raw.version == '1.2.0' || + raw.version == '1.3.0' || + raw.version == '1.3.1' || + raw.version == '1.4.0' || + raw.version == '1.5.0' || + raw.version == '1.5.1' || + raw.version == '1.5.2' || + raw.version == '1.5.3' || + raw.version == '1.5.4') + ) { + const parsed = Number(raw.settings.theme) + if (parsed == 3) raw.settings.theme = 2 + if (parsed == 4) raw.settings.theme = 3 + else if (parsed != 0 && parsed != 1) raw.settings.theme = 0 + } + if (raw.settings.allowNotifications) + settingsLocal?.set( + 'notificationsAllowed', + Boolean(raw.settings.allowNotifications) + ) + if (raw.settings.alwaysShowGamesInSidebar) + settingsLocal?.set( + 'sidebarAlwaysShowGames', + Boolean(raw.settings.alwaysShowGamesInSidebar) + ) + if (raw.settings.useWineOnUnixWhenNeeded) + settingsLocal?.set( + 'unixUseWine', + Boolean(raw.settings.useWineOnUnixWhenNeeded) + ) + if (raw.settings.wineOnUnixCommand) + settingsLocal?.set( + 'unixWineCommand', + String(raw.settings.wineOnUnixCommand) + ) + if (raw.settings.theme) { + const tempTheme = (() => { + switch (Number(raw.settings.theme)) { + case 1: + return 'red' + case 2: + return 'blue' + case 3: + return 'purple' + default: + return 'dark' + } + })() + settingsLocal?.set('theme', tempTheme) + } + await remove('config.json', oldSettingsOptions) + } const versionsConfig = await readVersionsConfig() setDownloadedVersionsConfig(versionsConfig) - setNormalConfig(normalConfig) + setSettings(settingsLocal) setLoading(false) if (!(await isPermissionGranted())) { @@ -475,7 +554,7 @@ export default function RootLayout ({ : d ) ) - if (normalConfig?.settings.allowNotifications) + if (await settings?.get('notifications-allowed')) await notifyUser( 'Download Failed', `The download for version ${info.displayName} has failed.` @@ -560,7 +639,7 @@ export default function RootLayout ({ : d ) ) - if (normalConfig?.settings.allowNotifications) + if (await settings?.get('notifications-allowed')) await notifyUser( 'Download Failed', `The download for version ${info.displayName} has failed.` @@ -581,7 +660,7 @@ export default function RootLayout ({ getVersionInfo, getGameInfo, downloadProgress, - normalConfig + settings ]) useEffect(() => { @@ -612,20 +691,36 @@ export default function RootLayout ({ })() }, [serverVersionList, downloadedVersionsConfig, downloadVersions]) + useEffect(() => { + if (!settings) return + const unlisteners: Promise<() => void>[] = [] + + function watch (key: string, fn: (v: T | undefined) => void) { + settings!.get(key).then(fn) + unlisteners.push(settings!.onKeyChange(key, fn)) + } + + watch('theme', v => setTheme(v ?? 'dark')) + watch('notificationsAllowed', v => + setNotificationsAllowed(v ?? true) + ) + watch('sidebarAlwaysShowGames', v => + setSidebarAlwaysShowGames(v ?? true) + ) + watch('unixUseWine', v => setUnixUseWine(v ?? false)) + watch('unixWineCommand', v => + setUnixWineCommand(v ?? 'wine %path%') + ) + + return () => { + unlisteners.forEach(u => u.then(fn => fn())) + } + }, [settings]) + return ( <> - + {loading ? ( <>
{ if (!showPopup) return setSelectedVersionList([]) - }, [normalConfig, setSelectedVersionList, showPopup]) + }, [setSelectedVersionList, showPopup]) return (
diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index f3a8136..53cc41a 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -1,181 +1,84 @@ 'use client' -import { useEffect, useState } from 'react' import { Setting } from '@/componets/Setting' -import { writeNormalConfig } from '@/lib/BazookaManager' import { useGlobal } from '@/app/GlobalProvider' import { copyToClipboard } from '@/lib/Clipboard' import { platform } from '@tauri-apps/plugin-os' export default function Settings () { - const [allowNotifications, setAllowNotifications] = useState(false) - const [alwaysShowGamesInSidebar, setAlwaysShowGamesInSidebar] = - useState(false) - const [useWineOnUnixWhenNeeded, setUseWineOnUnixWhenNeeded] = useState(false) - const [wineOnUnixCommand, setWineOnUnixCommand] = useState('wine %path%') - const [theme, setTheme] = useState(0) - - const [loaded, setLoaded] = useState(false) - const { normalConfig, setNormalConfig, version } = useGlobal() - - useEffect(() => { - ;(async () => { - while (normalConfig != null) { - setAllowNotifications(normalConfig.settings.allowNotifications) - setAlwaysShowGamesInSidebar( - normalConfig.settings.alwaysShowGamesInSidebar - ) - setUseWineOnUnixWhenNeeded( - normalConfig.settings.useWineOnUnixWhenNeeded - ) - setWineOnUnixCommand(normalConfig.settings.wineOnUnixCommand) - setTheme(normalConfig.settings.theme) - setLoaded(true) - break - } - })() - }, [normalConfig]) + const { + settings, + version, + notificationsAllowed, + sidebarAlwaysShowGames, + unixUseWine, + unixWineCommand, + theme + } = useGlobal() return ( <>

Settings

- {loaded && ( -
- { - if (!normalConfig) return - setAllowNotifications(!allowNotifications) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - allowNotifications: !allowNotifications - } - }) - await writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - allowNotifications: !allowNotifications - } - }) - }} - title='This setting does as you expect, allow the launcher to send notifications for when stuff like downloading is done.' - /> - { - if (!normalConfig) return - setAlwaysShowGamesInSidebar(!alwaysShowGamesInSidebar) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar - } - }) - await writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar - } - }) - }} - title="This setting will make it so when you are on a page like this, the games won't disappear." - /> - { - if (!normalConfig) return - setUseWineOnUnixWhenNeeded(!useWineOnUnixWhenNeeded) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded - } - }) - await writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded - } - }) - }} - className={platform() == 'linux' ? '' : 'hidden'} - /> - - + { + await settings?.set('notificationsAllowed', !notificationsAllowed) + }} + title='This setting does as you expect, allow the launcher to send notifications for when stuff like downloading is done.' + /> + { + await settings?.set( + 'sidebarAlwaysShowGames', + !sidebarAlwaysShowGames + ) + }} + title="This setting will make it so when you are on a page like this, the games won't disappear." + /> + { + await settings?.set('unixUseWine', !unixUseWine) + }} + className={platform() == 'linux' ? '' : 'hidden'} + /> + + { + await settings?.set('unixUseWine', e.target.value) + }} + className={`input-field my-1 ${ + platform() == 'linux' && unixUseWine ? '' : 'hidden' + }`} + > +
+ + { - if (!normalConfig) return - const newTheme = parseInt(e.target.value) - setTheme(newTheme) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - theme: newTheme - } - }) - await writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - theme: newTheme - } - }) - }} - > - - - - - -
+ > + + + + +
- )} +

{ - await copyToClipboard(`v${version}`, normalConfig) - }} + onClick={async () => + await copyToClipboard(`v${version}`, notificationsAllowed) + } title='The current launcher version.' > v{version} diff --git a/src/componets/Sidebar.tsx b/src/componets/Sidebar.tsx index de4fa31..f48d98e 100644 --- a/src/componets/Sidebar.tsx +++ b/src/componets/Sidebar.tsx @@ -27,7 +27,6 @@ const lexend = Lexend({ export default function Sidebar () { const { - normalConfig, getListOfGames, setShowPopup, setPopupMode, @@ -36,7 +35,9 @@ export default function Sidebar () { downloadedVersionsConfig, getVersionInfo, category, - setCategory + setCategory, + sidebarAlwaysShowGames, + unixUseWine } = useGlobal() const pathname = usePathname() @@ -104,7 +105,7 @@ export default function Sidebar () { ? 'active' : '' } ml-auto w-50 ${ - normalConfig?.settings.alwaysShowGamesInSidebar || + sidebarAlwaysShowGames || pathname === '/' || pathname.startsWith('/game') ? '' @@ -136,11 +137,7 @@ export default function Sidebar () { const info = getVersionInfo(v) if (!info) return false - if ( - platform() == 'linux' && - info.wine && - !normalConfig?.settings.useWineOnUnixWhenNeeded - ) + if (platform() == 'linux' && info.wine && !unixUseWine) return false return info.game === i.id && info.category === Number(key) @@ -161,7 +158,7 @@ export default function Sidebar () { ? 'active' : '' } ml-auto w-47.5 ${ - normalConfig?.settings.alwaysShowGamesInSidebar || + sidebarAlwaysShowGames || pathname === '/' || pathname.startsWith('/game') ? '' diff --git a/src/componets/popups/Downloads.tsx b/src/componets/popups/Downloads.tsx index b82c1ee..09423ff 100644 --- a/src/componets/popups/Downloads.tsx +++ b/src/componets/popups/Downloads.tsx @@ -21,8 +21,8 @@ export default function DownloadsPopup () { setDownloadProgress, downloadQueue, setDownloadQueue, - normalConfig, - setDownloadedVersionsConfig + setDownloadedVersionsConfig, + notificationsAllowed } = useGlobal() return ( @@ -123,7 +123,7 @@ export default function DownloadsPopup () { : d ) ) - if (normalConfig?.settings.allowNotifications) + if (notificationsAllowed) await notifyUser( 'Download Failed', `The download for version ${ diff --git a/src/lib/BazookaManager.ts b/src/lib/BazookaManager.ts index 81ec1be..39e2934 100644 --- a/src/lib/BazookaManager.ts +++ b/src/lib/BazookaManager.ts @@ -1,5 +1,4 @@ import { app } from '@tauri-apps/api' -import { NormalConfig } from '@/types/NormalConfig' import { BaseDirectory, create, @@ -10,80 +9,6 @@ import { } from '@tauri-apps/plugin-fs' import { VersionsConfig } from '@/types/VersionsConfig' -export async function readNormalConfig (): Promise { - const version = await app.getVersion() - try { - const options = { - baseDir: BaseDirectory.AppLocalData - } - const doesFolderExist = await exists('', options) - const doesConfigExist = await exists('config.json', options) - if (!doesFolderExist || !doesConfigExist) { - if (!doesFolderExist) { - await mkdir('', options) - } - const file = await create('config.json', options) - await file.write( - new TextEncoder().encode( - JSON.stringify(new NormalConfig(version), null, 2) - ) - ) - await file.close() - return new NormalConfig(version) - } - const config = await readTextFile('config.json', options) - const raw = JSON.parse(config) - if ( - raw.settings && - raw.settings.theme && - (raw.version == '1.0.0' || - raw.version == '1.1.0' || - raw.version == '1.1.1' || - raw.version == '1.2.0' || - raw.version == '1.3.0' || - raw.version == '1.3.1' || - raw.version == '1.4.0' || - raw.version == '1.5.0' || - raw.version == '1.5.1' || - raw.version == '1.5.2' || - raw.version == '1.5.3' || - raw.version == '1.5.4') - ) { - const parsed = Number(raw.settings.theme) - if (parsed == 3) raw.settings.theme = 2 - if (parsed == 4) raw.settings.theme = 3 - else if (parsed != 0 && parsed != 1) raw.settings.theme = 0 - } - raw.version = version - writeNormalConfig(raw) - return NormalConfig.import(raw) - } catch { - return new NormalConfig(version) - } -} - -export async function writeNormalConfig (data: NormalConfig) { - const options = { - baseDir: BaseDirectory.AppLocalData - } - const doesFolderExist = await exists('', options) - const doesConfigExist = await exists('config.json', options) - if (!doesFolderExist || !doesConfigExist) { - if (!doesFolderExist) { - await mkdir('', options) - } - const file = await create('config.json', options) - await file.write(new TextEncoder().encode(JSON.stringify(data, null, 2))) - await file.close() - } else { - await writeFile( - 'config.json', - new TextEncoder().encode(JSON.stringify(data, null, 2)), - options - ) - } -} - export async function readVersionsConfig (): Promise { const version = await app.getVersion() try { diff --git a/src/lib/Clipboard.ts b/src/lib/Clipboard.ts index de0204b..ee93c9a 100644 --- a/src/lib/Clipboard.ts +++ b/src/lib/Clipboard.ts @@ -1,10 +1,11 @@ -import { NormalConfig } from '@/types/NormalConfig' +import { writeText } from '@tauri-apps/plugin-clipboard-manager' import { notifyUser } from './Notifications' export async function copyToClipboard ( text: string, - normalConfig: NormalConfig | null + notificationsAllowed: boolean ) { - if (normalConfig?.settings.allowNotifications) + await writeText(text) + if (notificationsAllowed) await notifyUser('Copied', 'Text "' + text + '" copied to clipboard') } diff --git a/src/types/NormalConfig.ts b/src/types/NormalConfig.ts deleted file mode 100644 index f921b0e..0000000 --- a/src/types/NormalConfig.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { SettingsType } from './SettingsType' - -type NormalConfigData = { - version: string - settings?: Partial -} - -export class NormalConfig { - constructor ( - public version: string, - public settings: SettingsType = new SettingsType() - ) {} - - static import (data: NormalConfigData) { - const cfg = new NormalConfig(data.version) - if (data.settings) { - cfg.settings = { ...cfg.settings, ...data.settings } - } - return cfg - } -} diff --git a/src/types/SettingsType.ts b/src/types/SettingsType.ts deleted file mode 100644 index d756909..0000000 --- a/src/types/SettingsType.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class SettingsType { - constructor ( - public allowNotifications: boolean = true, - public alwaysShowGamesInSidebar: boolean = true, - public useWineOnUnixWhenNeeded: boolean = false, - public wineOnUnixCommand: string = 'wine %path%', - public theme: number = 0 - ) {} -}