Switch to Tauris json store management for settings
This commit is contained in:
16 files changed
+205
-306
No files matched your search
@@ -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=="],
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<SetStateAction<boolean>>
|
||||
downloadedVersionsConfig: VersionsConfig | null
|
||||
setDownloadedVersionsConfig: Dispatch<SetStateAction<VersionsConfig | null>>
|
||||
normalConfig: NormalConfig | null
|
||||
setNormalConfig: Dispatch<SetStateAction<NormalConfig | null>>
|
||||
managingVersion: string | null
|
||||
setManagingVersion: Dispatch<SetStateAction<string | null>>
|
||||
setSelectedGame: Dispatch<SetStateAction<number | null>>
|
||||
@@ -63,6 +61,12 @@ type GlobalCtxType = {
|
||||
setViewingInfoFromDownloads: Dispatch<SetStateAction<boolean>>
|
||||
showModInfo: Mod | null
|
||||
setShowModInfo: Dispatch<SetStateAction<Mod | null>>
|
||||
settings: Store | null
|
||||
notificationsAllowed: boolean
|
||||
sidebarAlwaysShowGames: boolean
|
||||
unixUseWine: boolean
|
||||
unixWineCommand: string
|
||||
theme: string
|
||||
}
|
||||
|
||||
const GlobalCtx = createContext<GlobalCtxType | null>(null)
|
||||
|
||||
+9
-17
@@ -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 <p>Invalid game</p>
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
+136
-37
@@ -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<VersionsConfig | null>(null)
|
||||
const [normalConfig, setNormalConfig] = useState<NormalConfig | null>(null)
|
||||
|
||||
const [showPopup, setShowPopup] = useState(false)
|
||||
const [popupMode, setPopupMode] = useState<null | number>(null)
|
||||
@@ -84,20 +84,25 @@ export default function RootLayout ({
|
||||
const pathname = usePathname()
|
||||
const revisionCheck = useRef(false)
|
||||
|
||||
const [settings, setSettings] = useState<Store | null>(null)
|
||||
|
||||
const [notificationsAllowed, setNotificationsAllowed] =
|
||||
useState<boolean>(false)
|
||||
const [sidebarAlwaysShowGames, setSidebarAlwaysShowGames] =
|
||||
useState<boolean>(false)
|
||||
const [unixUseWine, setUnixUseWine] = useState<boolean>(false)
|
||||
const [unixWineCommand, setUnixWineCommand] = useState<string>('wine %path%')
|
||||
const [theme, setTheme] = useState<string>('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<boolean>('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<boolean>('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<T> (key: string, fn: (v: T | undefined) => void) {
|
||||
settings!.get<T>(key).then(fn)
|
||||
unlisteners.push(settings!.onKeyChange<T>(key, fn))
|
||||
}
|
||||
|
||||
watch<string>('theme', v => setTheme(v ?? 'dark'))
|
||||
watch<boolean>('notificationsAllowed', v =>
|
||||
setNotificationsAllowed(v ?? true)
|
||||
)
|
||||
watch<boolean>('sidebarAlwaysShowGames', v =>
|
||||
setSidebarAlwaysShowGames(v ?? true)
|
||||
)
|
||||
watch<boolean>('unixUseWine', v => setUnixUseWine(v ?? false))
|
||||
watch<string>('unixWineCommand', v =>
|
||||
setUnixWineCommand(v ?? 'wine %path%')
|
||||
)
|
||||
|
||||
return () => {
|
||||
unlisteners.forEach(u => u.then(fn => fn()))
|
||||
}
|
||||
}, [settings])
|
||||
|
||||
return (
|
||||
<>
|
||||
<html lang='en' className={roboto.className}>
|
||||
<body
|
||||
className={
|
||||
normalConfig?.settings.theme === 1
|
||||
? 'red-theme'
|
||||
: normalConfig?.settings.theme === 2
|
||||
? 'blue-theme'
|
||||
: normalConfig?.settings.theme === 3
|
||||
? 'purple-theme'
|
||||
: 'dark-theme'
|
||||
}
|
||||
>
|
||||
<body className={theme + '-theme'}>
|
||||
{loading ? (
|
||||
<>
|
||||
<div
|
||||
@@ -675,8 +770,6 @@ export default function RootLayout ({
|
||||
setFadeOut,
|
||||
downloadedVersionsConfig,
|
||||
setDownloadedVersionsConfig,
|
||||
normalConfig,
|
||||
setNormalConfig,
|
||||
managingVersion,
|
||||
setManagingVersion,
|
||||
getVersionInfo,
|
||||
@@ -696,7 +789,13 @@ export default function RootLayout ({
|
||||
selectedGame,
|
||||
setViewingInfoFromDownloads,
|
||||
showModInfo,
|
||||
setShowModInfo
|
||||
setShowModInfo,
|
||||
settings,
|
||||
notificationsAllowed,
|
||||
sidebarAlwaysShowGames,
|
||||
unixUseWine,
|
||||
unixWineCommand,
|
||||
theme
|
||||
}}
|
||||
>
|
||||
<div
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ export default function Installs () {
|
||||
setFadeOut,
|
||||
setSelectedVersionList,
|
||||
downloadedVersionsConfig,
|
||||
normalConfig,
|
||||
setSelectedGame,
|
||||
getListOfGames,
|
||||
getVersionsAmountData,
|
||||
@@ -32,7 +31,7 @@ export default function Installs () {
|
||||
useEffect(() => {
|
||||
if (!showPopup) return
|
||||
setSelectedVersionList([])
|
||||
}, [normalConfig, setSelectedVersionList, showPopup])
|
||||
}, [setSelectedVersionList, showPopup])
|
||||
|
||||
return (
|
||||
<div className='mx-4 mt-4'>
|
||||
|
||||
+30
-127
@@ -1,141 +1,61 @@
|
||||
'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 (
|
||||
<>
|
||||
<p className='text-3xl ml-4 mt-4'>Settings</p>
|
||||
{loaded && (
|
||||
<div className='ml-4 mt-4 bg-(--col1) border border-(--col3) rounded-lg p-4 w-fit h-fit'>
|
||||
<Setting
|
||||
label='Allow sending notifications'
|
||||
value={allowNotifications}
|
||||
value={notificationsAllowed}
|
||||
onChange={async () => {
|
||||
if (!normalConfig) return
|
||||
setAllowNotifications(!allowNotifications)
|
||||
setNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
allowNotifications: !allowNotifications
|
||||
}
|
||||
})
|
||||
await writeNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
allowNotifications: !allowNotifications
|
||||
}
|
||||
})
|
||||
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.'
|
||||
/>
|
||||
<Setting
|
||||
label='Always show games in sidebar'
|
||||
value={alwaysShowGamesInSidebar}
|
||||
value={sidebarAlwaysShowGames}
|
||||
onChange={async () => {
|
||||
if (!normalConfig) return
|
||||
setAlwaysShowGamesInSidebar(!alwaysShowGamesInSidebar)
|
||||
setNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar
|
||||
}
|
||||
})
|
||||
await writeNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar
|
||||
}
|
||||
})
|
||||
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."
|
||||
/>
|
||||
<Setting
|
||||
label='Use wine when needed to launch games'
|
||||
value={useWineOnUnixWhenNeeded}
|
||||
value={unixUseWine}
|
||||
onChange={async () => {
|
||||
if (!normalConfig) return
|
||||
setUseWineOnUnixWhenNeeded(!useWineOnUnixWhenNeeded)
|
||||
setNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded
|
||||
}
|
||||
})
|
||||
await writeNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded
|
||||
}
|
||||
})
|
||||
await settings?.set('unixUseWine', !unixUseWine)
|
||||
}}
|
||||
className={platform() == 'linux' ? '' : 'hidden'}
|
||||
/>
|
||||
<p hidden={!(platform() == 'linux' && useWineOnUnixWhenNeeded)}>
|
||||
Wine Command:
|
||||
</p>
|
||||
<p hidden={!(platform() == 'linux' && unixUseWine)}>Wine Command:</p>
|
||||
<input
|
||||
type='text'
|
||||
value={wineOnUnixCommand}
|
||||
value={unixWineCommand}
|
||||
onChange={async e => {
|
||||
if (!normalConfig) return
|
||||
setWineOnUnixCommand(e.target.value)
|
||||
setNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
wineOnUnixCommand: e.target.value
|
||||
}
|
||||
})
|
||||
await writeNormalConfig({
|
||||
...normalConfig,
|
||||
settings: {
|
||||
...normalConfig.settings,
|
||||
wineOnUnixCommand: e.target.value
|
||||
}
|
||||
})
|
||||
await settings?.set('unixUseWine', e.target.value)
|
||||
}}
|
||||
className={`input-field my-1 ${
|
||||
platform() == 'linux' && useWineOnUnixWhenNeeded ? '' : 'hidden'
|
||||
platform() == 'linux' && unixUseWine ? '' : 'hidden'
|
||||
}`}
|
||||
></input>
|
||||
<div title='The theme you want the launcher to use.'>
|
||||
@@ -144,38 +64,21 @@ export default function Settings () {
|
||||
className='ml-2 bg-(--col2) border border-(--col4) rounded-md'
|
||||
value={theme}
|
||||
onChange={async e => {
|
||||
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 settings?.set('theme', e.target.value)
|
||||
}}
|
||||
>
|
||||
<option value={0}>Dark (default)</option>
|
||||
<option value={1}>Red</option>
|
||||
<option value={2}>Blue</option>
|
||||
<option value={3}>Purple</option>
|
||||
<option value={'dark'}>Dark (default)</option>
|
||||
<option value={'red'}>Red</option>
|
||||
<option value={'blue'}>Blue</option>
|
||||
<option value={'purple'}>Purple</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<p
|
||||
className='fixed bottom-1.5 right-1.5 rounded-md cursor-pointer px-1 border z-100 transition-colors btntheme1'
|
||||
onClick={async () => {
|
||||
await copyToClipboard(`v${version}`, normalConfig)
|
||||
}}
|
||||
onClick={async () =>
|
||||
await copyToClipboard(`v${version}`, notificationsAllowed)
|
||||
}
|
||||
title='The current launcher version.'
|
||||
>
|
||||
v{version}
|
||||
|
||||
@@ -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')
|
||||
? ''
|
||||
|
||||
@@ -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 ${
|
||||
|
||||
@@ -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<NormalConfig> {
|
||||
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<VersionsConfig> {
|
||||
const version = await app.getVersion()
|
||||
try {
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { SettingsType } from './SettingsType'
|
||||
|
||||
type NormalConfigData = {
|
||||
version: string
|
||||
settings?: Partial<SettingsType>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
) {}
|
||||
}
|
||||
Reference in new issue
Block a user