Switch to Tauris json store management for settings
This commit is contained in:
16 files changed
+239
-340
No files matched your search
@@ -17,6 +17,7 @@
|
|||||||
"@tauri-apps/plugin-notification": "2.3.3",
|
"@tauri-apps/plugin-notification": "2.3.3",
|
||||||
"@tauri-apps/plugin-opener": "2.5.3",
|
"@tauri-apps/plugin-opener": "2.5.3",
|
||||||
"@tauri-apps/plugin-os": "2.3.2",
|
"@tauri-apps/plugin-os": "2.3.2",
|
||||||
|
"@tauri-apps/plugin-store": "2.4.2",
|
||||||
"@tauri-apps/plugin-window-state": "2.4.1",
|
"@tauri-apps/plugin-window-state": "2.4.1",
|
||||||
"next": "16.2.1",
|
"next": "16.2.1",
|
||||||
"pretty-bytes": "7.1.0",
|
"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-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=="],
|
"@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=="],
|
"@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-notification": "2.3.3",
|
||||||
"@tauri-apps/plugin-opener": "2.5.3",
|
"@tauri-apps/plugin-opener": "2.5.3",
|
||||||
"@tauri-apps/plugin-os": "2.3.2",
|
"@tauri-apps/plugin-os": "2.3.2",
|
||||||
|
"@tauri-apps/plugin-store": "2.4.2",
|
||||||
"@tauri-apps/plugin-window-state": "2.4.1",
|
"@tauri-apps/plugin-window-state": "2.4.1",
|
||||||
"next": "16.2.1",
|
"next": "16.2.1",
|
||||||
"pretty-bytes": "7.1.0",
|
"pretty-bytes": "7.1.0",
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ openssl = { version = "0.10.76", features = ["v110", "vendored"] }
|
|||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
tauri-plugin-http = "2.5.7"
|
tauri-plugin-http = "2.5.7"
|
||||||
dashmap = "6.1.0"
|
dashmap = "6.1.0"
|
||||||
|
tauri-plugin-store = "2.4.2"
|
||||||
|
|
||||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||||
tauri-plugin-single-instance = "2.4.0"
|
tauri-plugin-single-instance = "2.4.0"
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
"notification:default",
|
"notification:default",
|
||||||
"clipboard-manager:default",
|
"clipboard-manager:default",
|
||||||
"clipboard-manager:allow-write-text",
|
"clipboard-manager:allow-write-text",
|
||||||
|
"store:default",
|
||||||
|
"store:allow-load",
|
||||||
|
"store:allow-save",
|
||||||
"fs:allow-applocaldata-read",
|
"fs:allow-applocaldata-read",
|
||||||
"fs:allow-applocaldata-write",
|
"fs:allow-applocaldata-write",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -620,6 +620,7 @@ async fn cancel_download(name: String) {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_store::Builder::new().build())
|
||||||
.plugin(tauri_plugin_http::init())
|
.plugin(tauri_plugin_http::init())
|
||||||
.plugin(
|
.plugin(
|
||||||
tauri_plugin_prevent_default::Builder::new()
|
tauri_plugin_prevent_default::Builder::new()
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import {
|
|||||||
} from 'react'
|
} from 'react'
|
||||||
import { DownloadProgress } from '@/types/DownloadProgress'
|
import { DownloadProgress } from '@/types/DownloadProgress'
|
||||||
import { VersionsConfig } from '@/types/VersionsConfig'
|
import { VersionsConfig } from '@/types/VersionsConfig'
|
||||||
import { NormalConfig } from '@/types/NormalConfig'
|
|
||||||
import { ServerVersionsResponse } from '@/types/ServerVersionsResponse'
|
import { ServerVersionsResponse } from '@/types/ServerVersionsResponse'
|
||||||
import { GameVersion } from '@/types/GameVersion'
|
import { GameVersion } from '@/types/GameVersion'
|
||||||
import { Game } from '@/types/Game'
|
import { Game } from '@/types/Game'
|
||||||
import { Mod } from '@/types/Mod'
|
import { Mod } from '@/types/Mod'
|
||||||
|
import { Store } from '@tauri-apps/plugin-store'
|
||||||
|
|
||||||
type GlobalCtxType = {
|
type GlobalCtxType = {
|
||||||
serverVersionList: ServerVersionsResponse | null
|
serverVersionList: ServerVersionsResponse | null
|
||||||
@@ -29,8 +29,6 @@ type GlobalCtxType = {
|
|||||||
setFadeOut: Dispatch<SetStateAction<boolean>>
|
setFadeOut: Dispatch<SetStateAction<boolean>>
|
||||||
downloadedVersionsConfig: VersionsConfig | null
|
downloadedVersionsConfig: VersionsConfig | null
|
||||||
setDownloadedVersionsConfig: Dispatch<SetStateAction<VersionsConfig | null>>
|
setDownloadedVersionsConfig: Dispatch<SetStateAction<VersionsConfig | null>>
|
||||||
normalConfig: NormalConfig | null
|
|
||||||
setNormalConfig: Dispatch<SetStateAction<NormalConfig | null>>
|
|
||||||
managingVersion: string | null
|
managingVersion: string | null
|
||||||
setManagingVersion: Dispatch<SetStateAction<string | null>>
|
setManagingVersion: Dispatch<SetStateAction<string | null>>
|
||||||
setSelectedGame: Dispatch<SetStateAction<number | null>>
|
setSelectedGame: Dispatch<SetStateAction<number | null>>
|
||||||
@@ -63,6 +61,12 @@ type GlobalCtxType = {
|
|||||||
setViewingInfoFromDownloads: Dispatch<SetStateAction<boolean>>
|
setViewingInfoFromDownloads: Dispatch<SetStateAction<boolean>>
|
||||||
showModInfo: Mod | null
|
showModInfo: Mod | null
|
||||||
setShowModInfo: Dispatch<SetStateAction<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)
|
const GlobalCtx = createContext<GlobalCtxType | null>(null)
|
||||||
|
|||||||
+9
-17
@@ -21,7 +21,6 @@ export default function Installs () {
|
|||||||
setFadeOut,
|
setFadeOut,
|
||||||
setSelectedVersionList,
|
setSelectedVersionList,
|
||||||
downloadedVersionsConfig,
|
downloadedVersionsConfig,
|
||||||
normalConfig,
|
|
||||||
setManagingVersion,
|
setManagingVersion,
|
||||||
getVersionInfo,
|
getVersionInfo,
|
||||||
getGameInfo,
|
getGameInfo,
|
||||||
@@ -31,7 +30,9 @@ export default function Installs () {
|
|||||||
setCategory,
|
setCategory,
|
||||||
setDownloadedVersionsConfig,
|
setDownloadedVersionsConfig,
|
||||||
downloadVersions,
|
downloadVersions,
|
||||||
downloadProgress
|
downloadProgress,
|
||||||
|
unixUseWine,
|
||||||
|
unixWineCommand
|
||||||
} = useGlobal()
|
} = useGlobal()
|
||||||
|
|
||||||
const params = useSearchParams()
|
const params = useSearchParams()
|
||||||
@@ -43,7 +44,7 @@ export default function Installs () {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showPopup) return
|
if (!showPopup) return
|
||||||
setSelectedVersionList([])
|
setSelectedVersionList([])
|
||||||
}, [normalConfig, setSelectedVersionList, showPopup])
|
}, [setSelectedVersionList, showPopup])
|
||||||
|
|
||||||
if (!id || !game) return <p>Invalid game</p>
|
if (!id || !game) return <p>Invalid game</p>
|
||||||
|
|
||||||
@@ -129,11 +130,7 @@ export default function Installs () {
|
|||||||
const info = getVersionInfo(v)
|
const info = getVersionInfo(v)
|
||||||
if (!info) return false
|
if (!info) return false
|
||||||
|
|
||||||
if (
|
if (platform() == 'linux' && info.wine && !unixUseWine)
|
||||||
platform() == 'linux' &&
|
|
||||||
info.wine &&
|
|
||||||
!normalConfig?.settings.useWineOnUnixWhenNeeded
|
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return info.game === id && info.category === Number(key)
|
return info.game === id && info.category === Number(key)
|
||||||
@@ -168,8 +165,7 @@ export default function Installs () {
|
|||||||
if (
|
if (
|
||||||
platform() == 'linux' &&
|
platform() == 'linux' &&
|
||||||
info.wine &&
|
info.wine &&
|
||||||
!normalConfig?.settings
|
!unixUseWine
|
||||||
.useWineOnUnixWhenNeeded
|
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
return (
|
return (
|
||||||
@@ -200,11 +196,7 @@ export default function Installs () {
|
|||||||
.filter(v => {
|
.filter(v => {
|
||||||
const info = getVersionInfo(v)
|
const info = getVersionInfo(v)
|
||||||
if (!info) return false
|
if (!info) return false
|
||||||
if (
|
if (platform() == 'linux' && info.wine && !unixUseWine)
|
||||||
platform() == 'linux' &&
|
|
||||||
info.wine &&
|
|
||||||
!normalConfig?.settings.useWineOnUnixWhenNeeded
|
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
return (
|
return (
|
||||||
info.game === id &&
|
info.game === id &&
|
||||||
@@ -299,9 +291,9 @@ export default function Installs () {
|
|||||||
useWine: !!(
|
useWine: !!(
|
||||||
platform() == 'linux' &&
|
platform() == 'linux' &&
|
||||||
verInfo.wine &&
|
verInfo.wine &&
|
||||||
normalConfig?.settings.useWineOnUnixWhenNeeded
|
unixUseWine
|
||||||
),
|
),
|
||||||
wineCommand: normalConfig?.settings.wineOnUnixCommand
|
wineCommand: unixWineCommand
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
onContextMenu={e => {
|
onContextMenu={e => {
|
||||||
|
|||||||
+136
-37
@@ -7,13 +7,8 @@ import { DownloadProgress } from '@/types/DownloadProgress'
|
|||||||
import { invoke } from '@tauri-apps/api/core'
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faChevronLeft, faXmark } from '@fortawesome/free-solid-svg-icons'
|
import { faChevronLeft, faXmark } from '@fortawesome/free-solid-svg-icons'
|
||||||
import {
|
import { readVersionsConfig, writeVersionsConfig } from '@/lib/BazookaManager'
|
||||||
readNormalConfig,
|
|
||||||
readVersionsConfig,
|
|
||||||
writeVersionsConfig
|
|
||||||
} from '@/lib/BazookaManager'
|
|
||||||
import { VersionsConfig } from '@/types/VersionsConfig'
|
import { VersionsConfig } from '@/types/VersionsConfig'
|
||||||
import { NormalConfig } from '@/types/NormalConfig'
|
|
||||||
import { app } from '@tauri-apps/api'
|
import { app } from '@tauri-apps/api'
|
||||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||||
import { GlobalProvider } from './GlobalProvider'
|
import { GlobalProvider } from './GlobalProvider'
|
||||||
@@ -24,12 +19,16 @@ import { Game } from '@/types/Game'
|
|||||||
import { listen } from '@tauri-apps/api/event'
|
import { listen } from '@tauri-apps/api/event'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import { arch, platform } from '@tauri-apps/plugin-os'
|
import { arch, platform } from '@tauri-apps/plugin-os'
|
||||||
import { notifyUser } from '@/lib/Notifications'
|
|
||||||
import {
|
import {
|
||||||
isPermissionGranted,
|
isPermissionGranted,
|
||||||
requestPermission
|
requestPermission
|
||||||
} from '@tauri-apps/plugin-notification'
|
} 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 { fetch } from '@tauri-apps/plugin-http'
|
||||||
import { verifySignature } from '@/lib/Util'
|
import { verifySignature } from '@/lib/Util'
|
||||||
import { getCurrentWindow, UserAttentionType } from '@tauri-apps/api/window'
|
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 ManageVersionPopup from '@/componets/popups/ManageVersion'
|
||||||
import ModDownloadsPopup from '@/componets/popups/ModDownloads'
|
import ModDownloadsPopup from '@/componets/popups/ModDownloads'
|
||||||
import { Mod } from '@/types/Mod'
|
import { Mod } from '@/types/Mod'
|
||||||
|
import { load, Store } from '@tauri-apps/plugin-store'
|
||||||
|
import { notifyUser } from '@/lib/Notifications'
|
||||||
|
|
||||||
const roboto = Roboto({
|
const roboto = Roboto({
|
||||||
subsets: ['latin']
|
subsets: ['latin']
|
||||||
@@ -62,7 +63,6 @@ export default function RootLayout ({
|
|||||||
|
|
||||||
const [downloadedVersionsConfig, setDownloadedVersionsConfig] =
|
const [downloadedVersionsConfig, setDownloadedVersionsConfig] =
|
||||||
useState<VersionsConfig | null>(null)
|
useState<VersionsConfig | null>(null)
|
||||||
const [normalConfig, setNormalConfig] = useState<NormalConfig | null>(null)
|
|
||||||
|
|
||||||
const [showPopup, setShowPopup] = useState(false)
|
const [showPopup, setShowPopup] = useState(false)
|
||||||
const [popupMode, setPopupMode] = useState<null | number>(null)
|
const [popupMode, setPopupMode] = useState<null | number>(null)
|
||||||
@@ -84,20 +84,25 @@ export default function RootLayout ({
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const revisionCheck = useRef(false)
|
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[] {
|
function getSpecialVersionsList (game?: number): GameVersion[] {
|
||||||
if (!normalConfig || !serverVersionList) return []
|
if (!serverVersionList) return []
|
||||||
|
|
||||||
return serverVersionList.versions
|
return serverVersionList.versions
|
||||||
.filter(
|
.filter(
|
||||||
v => !Object.keys(downloadedVersionsConfig?.list ?? []).includes(v.id)
|
v => !Object.keys(downloadedVersionsConfig?.list ?? []).includes(v.id)
|
||||||
)
|
)
|
||||||
.filter(v => {
|
.filter(v => {
|
||||||
if (
|
if (platformName == 'linux' && v.wine && unixUseWine) return false
|
||||||
platformName == 'linux' &&
|
|
||||||
v.wine &&
|
|
||||||
!normalConfig.settings.useWineOnUnixWhenNeeded
|
|
||||||
)
|
|
||||||
return false
|
|
||||||
|
|
||||||
if (game && v.game != game) return false
|
if (game && v.game != game) return false
|
||||||
if (category != -1 && v.category != category) return false
|
if (category != -1 && v.category != category) return false
|
||||||
@@ -150,8 +155,7 @@ export default function RootLayout ({
|
|||||||
} | null {
|
} | null {
|
||||||
if (!downloadedVersionsConfig || !serverVersionList) return null
|
if (!downloadedVersionsConfig || !serverVersionList) return null
|
||||||
|
|
||||||
const allowWine =
|
const allowWine = platformName !== 'linux' || unixUseWine
|
||||||
platformName !== 'linux' || normalConfig?.settings.useWineOnUnixWhenNeeded
|
|
||||||
|
|
||||||
const installed = Object.keys(downloadedVersionsConfig.list).filter(v => {
|
const installed = Object.keys(downloadedVersionsConfig.list).filter(v => {
|
||||||
const info = getVersionInfo(v)
|
const info = getVersionInfo(v)
|
||||||
@@ -353,10 +357,85 @@ export default function RootLayout ({
|
|||||||
setLoadingText('Failed to download versions list.')
|
setLoadingText('Failed to download versions list.')
|
||||||
return
|
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()
|
const versionsConfig = await readVersionsConfig()
|
||||||
setDownloadedVersionsConfig(versionsConfig)
|
setDownloadedVersionsConfig(versionsConfig)
|
||||||
setNormalConfig(normalConfig)
|
setSettings(settingsLocal)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
||||||
if (!(await isPermissionGranted())) {
|
if (!(await isPermissionGranted())) {
|
||||||
@@ -475,7 +554,7 @@ export default function RootLayout ({
|
|||||||
: d
|
: d
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (normalConfig?.settings.allowNotifications)
|
if (await settings?.get<boolean>('notifications-allowed'))
|
||||||
await notifyUser(
|
await notifyUser(
|
||||||
'Download Failed',
|
'Download Failed',
|
||||||
`The download for version ${info.displayName} has failed.`
|
`The download for version ${info.displayName} has failed.`
|
||||||
@@ -560,7 +639,7 @@ export default function RootLayout ({
|
|||||||
: d
|
: d
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (normalConfig?.settings.allowNotifications)
|
if (await settings?.get<boolean>('notifications-allowed'))
|
||||||
await notifyUser(
|
await notifyUser(
|
||||||
'Download Failed',
|
'Download Failed',
|
||||||
`The download for version ${info.displayName} has failed.`
|
`The download for version ${info.displayName} has failed.`
|
||||||
@@ -581,7 +660,7 @@ export default function RootLayout ({
|
|||||||
getVersionInfo,
|
getVersionInfo,
|
||||||
getGameInfo,
|
getGameInfo,
|
||||||
downloadProgress,
|
downloadProgress,
|
||||||
normalConfig
|
settings
|
||||||
])
|
])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -612,20 +691,36 @@ export default function RootLayout ({
|
|||||||
})()
|
})()
|
||||||
}, [serverVersionList, downloadedVersionsConfig, downloadVersions])
|
}, [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<html lang='en' className={roboto.className}>
|
<html lang='en' className={roboto.className}>
|
||||||
<body
|
<body className={theme + '-theme'}>
|
||||||
className={
|
|
||||||
normalConfig?.settings.theme === 1
|
|
||||||
? 'red-theme'
|
|
||||||
: normalConfig?.settings.theme === 2
|
|
||||||
? 'blue-theme'
|
|
||||||
: normalConfig?.settings.theme === 3
|
|
||||||
? 'purple-theme'
|
|
||||||
: 'dark-theme'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -675,8 +770,6 @@ export default function RootLayout ({
|
|||||||
setFadeOut,
|
setFadeOut,
|
||||||
downloadedVersionsConfig,
|
downloadedVersionsConfig,
|
||||||
setDownloadedVersionsConfig,
|
setDownloadedVersionsConfig,
|
||||||
normalConfig,
|
|
||||||
setNormalConfig,
|
|
||||||
managingVersion,
|
managingVersion,
|
||||||
setManagingVersion,
|
setManagingVersion,
|
||||||
getVersionInfo,
|
getVersionInfo,
|
||||||
@@ -696,7 +789,13 @@ export default function RootLayout ({
|
|||||||
selectedGame,
|
selectedGame,
|
||||||
setViewingInfoFromDownloads,
|
setViewingInfoFromDownloads,
|
||||||
showModInfo,
|
showModInfo,
|
||||||
setShowModInfo
|
setShowModInfo,
|
||||||
|
settings,
|
||||||
|
notificationsAllowed,
|
||||||
|
sidebarAlwaysShowGames,
|
||||||
|
unixUseWine,
|
||||||
|
unixWineCommand,
|
||||||
|
theme
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
+1
-2
@@ -20,7 +20,6 @@ export default function Installs () {
|
|||||||
setFadeOut,
|
setFadeOut,
|
||||||
setSelectedVersionList,
|
setSelectedVersionList,
|
||||||
downloadedVersionsConfig,
|
downloadedVersionsConfig,
|
||||||
normalConfig,
|
|
||||||
setSelectedGame,
|
setSelectedGame,
|
||||||
getListOfGames,
|
getListOfGames,
|
||||||
getVersionsAmountData,
|
getVersionsAmountData,
|
||||||
@@ -32,7 +31,7 @@ export default function Installs () {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showPopup) return
|
if (!showPopup) return
|
||||||
setSelectedVersionList([])
|
setSelectedVersionList([])
|
||||||
}, [normalConfig, setSelectedVersionList, showPopup])
|
}, [setSelectedVersionList, showPopup])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mx-4 mt-4'>
|
<div className='mx-4 mt-4'>
|
||||||
|
|||||||
+64
-161
@@ -1,181 +1,84 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { Setting } from '@/componets/Setting'
|
import { Setting } from '@/componets/Setting'
|
||||||
import { writeNormalConfig } from '@/lib/BazookaManager'
|
|
||||||
import { useGlobal } from '@/app/GlobalProvider'
|
import { useGlobal } from '@/app/GlobalProvider'
|
||||||
import { copyToClipboard } from '@/lib/Clipboard'
|
import { copyToClipboard } from '@/lib/Clipboard'
|
||||||
import { platform } from '@tauri-apps/plugin-os'
|
import { platform } from '@tauri-apps/plugin-os'
|
||||||
|
|
||||||
export default function Settings () {
|
export default function Settings () {
|
||||||
const [allowNotifications, setAllowNotifications] = useState(false)
|
const {
|
||||||
const [alwaysShowGamesInSidebar, setAlwaysShowGamesInSidebar] =
|
settings,
|
||||||
useState(false)
|
version,
|
||||||
const [useWineOnUnixWhenNeeded, setUseWineOnUnixWhenNeeded] = useState(false)
|
notificationsAllowed,
|
||||||
const [wineOnUnixCommand, setWineOnUnixCommand] = useState('wine %path%')
|
sidebarAlwaysShowGames,
|
||||||
const [theme, setTheme] = useState(0)
|
unixUseWine,
|
||||||
|
unixWineCommand,
|
||||||
const [loaded, setLoaded] = useState(false)
|
theme
|
||||||
const { normalConfig, setNormalConfig, version } = useGlobal()
|
} = 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])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p className='text-3xl ml-4 mt-4'>Settings</p>
|
<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'>
|
||||||
<div className='ml-4 mt-4 bg-(--col1) border border-(--col3) rounded-lg p-4 w-fit h-fit'>
|
<Setting
|
||||||
<Setting
|
label='Allow sending notifications'
|
||||||
label='Allow sending notifications'
|
value={notificationsAllowed}
|
||||||
value={allowNotifications}
|
onChange={async () => {
|
||||||
onChange={async () => {
|
await settings?.set('notificationsAllowed', !notificationsAllowed)
|
||||||
if (!normalConfig) return
|
}}
|
||||||
setAllowNotifications(!allowNotifications)
|
title='This setting does as you expect, allow the launcher to send notifications for when stuff like downloading is done.'
|
||||||
setNormalConfig({
|
/>
|
||||||
...normalConfig,
|
<Setting
|
||||||
settings: {
|
label='Always show games in sidebar'
|
||||||
...normalConfig.settings,
|
value={sidebarAlwaysShowGames}
|
||||||
allowNotifications: !allowNotifications
|
onChange={async () => {
|
||||||
}
|
await settings?.set(
|
||||||
})
|
'sidebarAlwaysShowGames',
|
||||||
await writeNormalConfig({
|
!sidebarAlwaysShowGames
|
||||||
...normalConfig,
|
)
|
||||||
settings: {
|
}}
|
||||||
...normalConfig.settings,
|
title="This setting will make it so when you are on a page like this, the games won't disappear."
|
||||||
allowNotifications: !allowNotifications
|
/>
|
||||||
}
|
<Setting
|
||||||
})
|
label='Use wine when needed to launch games'
|
||||||
}}
|
value={unixUseWine}
|
||||||
title='This setting does as you expect, allow the launcher to send notifications for when stuff like downloading is done.'
|
onChange={async () => {
|
||||||
/>
|
await settings?.set('unixUseWine', !unixUseWine)
|
||||||
<Setting
|
}}
|
||||||
label='Always show games in sidebar'
|
className={platform() == 'linux' ? '' : 'hidden'}
|
||||||
value={alwaysShowGamesInSidebar}
|
/>
|
||||||
onChange={async () => {
|
<p hidden={!(platform() == 'linux' && unixUseWine)}>Wine Command:</p>
|
||||||
if (!normalConfig) return
|
<input
|
||||||
setAlwaysShowGamesInSidebar(!alwaysShowGamesInSidebar)
|
type='text'
|
||||||
setNormalConfig({
|
value={unixWineCommand}
|
||||||
...normalConfig,
|
onChange={async e => {
|
||||||
settings: {
|
await settings?.set('unixUseWine', e.target.value)
|
||||||
...normalConfig.settings,
|
}}
|
||||||
alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar
|
className={`input-field my-1 ${
|
||||||
}
|
platform() == 'linux' && unixUseWine ? '' : 'hidden'
|
||||||
})
|
}`}
|
||||||
await writeNormalConfig({
|
></input>
|
||||||
...normalConfig,
|
<div title='The theme you want the launcher to use.'>
|
||||||
settings: {
|
<label className='text-lg'>Theme:</label>
|
||||||
...normalConfig.settings,
|
<select
|
||||||
alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar
|
className='ml-2 bg-(--col2) border border-(--col4) rounded-md'
|
||||||
}
|
value={theme}
|
||||||
})
|
|
||||||
}}
|
|
||||||
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}
|
|
||||||
onChange={async () => {
|
|
||||||
if (!normalConfig) return
|
|
||||||
setUseWineOnUnixWhenNeeded(!useWineOnUnixWhenNeeded)
|
|
||||||
setNormalConfig({
|
|
||||||
...normalConfig,
|
|
||||||
settings: {
|
|
||||||
...normalConfig.settings,
|
|
||||||
useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded
|
|
||||||
}
|
|
||||||
})
|
|
||||||
await writeNormalConfig({
|
|
||||||
...normalConfig,
|
|
||||||
settings: {
|
|
||||||
...normalConfig.settings,
|
|
||||||
useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
className={platform() == 'linux' ? '' : 'hidden'}
|
|
||||||
/>
|
|
||||||
<p hidden={!(platform() == 'linux' && useWineOnUnixWhenNeeded)}>
|
|
||||||
Wine Command:
|
|
||||||
</p>
|
|
||||||
<input
|
|
||||||
type='text'
|
|
||||||
value={wineOnUnixCommand}
|
|
||||||
onChange={async e => {
|
onChange={async e => {
|
||||||
if (!normalConfig) return
|
await settings?.set('theme', e.target.value)
|
||||||
setWineOnUnixCommand(e.target.value)
|
|
||||||
setNormalConfig({
|
|
||||||
...normalConfig,
|
|
||||||
settings: {
|
|
||||||
...normalConfig.settings,
|
|
||||||
wineOnUnixCommand: e.target.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
await writeNormalConfig({
|
|
||||||
...normalConfig,
|
|
||||||
settings: {
|
|
||||||
...normalConfig.settings,
|
|
||||||
wineOnUnixCommand: e.target.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
className={`input-field my-1 ${
|
>
|
||||||
platform() == 'linux' && useWineOnUnixWhenNeeded ? '' : 'hidden'
|
<option value={'dark'}>Dark (default)</option>
|
||||||
}`}
|
<option value={'red'}>Red</option>
|
||||||
></input>
|
<option value={'blue'}>Blue</option>
|
||||||
<div title='The theme you want the launcher to use.'>
|
<option value={'purple'}>Purple</option>
|
||||||
<label className='text-lg'>Theme:</label>
|
</select>
|
||||||
<select
|
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<option value={0}>Dark (default)</option>
|
|
||||||
<option value={1}>Red</option>
|
|
||||||
<option value={2}>Blue</option>
|
|
||||||
<option value={3}>Purple</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
<p
|
<p
|
||||||
className='fixed bottom-1.5 right-1.5 rounded-md cursor-pointer px-1 border z-100 transition-colors btntheme1'
|
className='fixed bottom-1.5 right-1.5 rounded-md cursor-pointer px-1 border z-100 transition-colors btntheme1'
|
||||||
onClick={async () => {
|
onClick={async () =>
|
||||||
await copyToClipboard(`v${version}`, normalConfig)
|
await copyToClipboard(`v${version}`, notificationsAllowed)
|
||||||
}}
|
}
|
||||||
title='The current launcher version.'
|
title='The current launcher version.'
|
||||||
>
|
>
|
||||||
v{version}
|
v{version}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ const lexend = Lexend({
|
|||||||
|
|
||||||
export default function Sidebar () {
|
export default function Sidebar () {
|
||||||
const {
|
const {
|
||||||
normalConfig,
|
|
||||||
getListOfGames,
|
getListOfGames,
|
||||||
setShowPopup,
|
setShowPopup,
|
||||||
setPopupMode,
|
setPopupMode,
|
||||||
@@ -36,7 +35,9 @@ export default function Sidebar () {
|
|||||||
downloadedVersionsConfig,
|
downloadedVersionsConfig,
|
||||||
getVersionInfo,
|
getVersionInfo,
|
||||||
category,
|
category,
|
||||||
setCategory
|
setCategory,
|
||||||
|
sidebarAlwaysShowGames,
|
||||||
|
unixUseWine
|
||||||
} = useGlobal()
|
} = useGlobal()
|
||||||
|
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
@@ -104,7 +105,7 @@ export default function Sidebar () {
|
|||||||
? 'active'
|
? 'active'
|
||||||
: ''
|
: ''
|
||||||
} ml-auto w-50 ${
|
} ml-auto w-50 ${
|
||||||
normalConfig?.settings.alwaysShowGamesInSidebar ||
|
sidebarAlwaysShowGames ||
|
||||||
pathname === '/' ||
|
pathname === '/' ||
|
||||||
pathname.startsWith('/game')
|
pathname.startsWith('/game')
|
||||||
? ''
|
? ''
|
||||||
@@ -136,11 +137,7 @@ export default function Sidebar () {
|
|||||||
const info = getVersionInfo(v)
|
const info = getVersionInfo(v)
|
||||||
if (!info) return false
|
if (!info) return false
|
||||||
|
|
||||||
if (
|
if (platform() == 'linux' && info.wine && !unixUseWine)
|
||||||
platform() == 'linux' &&
|
|
||||||
info.wine &&
|
|
||||||
!normalConfig?.settings.useWineOnUnixWhenNeeded
|
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return info.game === i.id && info.category === Number(key)
|
return info.game === i.id && info.category === Number(key)
|
||||||
@@ -161,7 +158,7 @@ export default function Sidebar () {
|
|||||||
? 'active'
|
? 'active'
|
||||||
: ''
|
: ''
|
||||||
} ml-auto w-47.5 ${
|
} ml-auto w-47.5 ${
|
||||||
normalConfig?.settings.alwaysShowGamesInSidebar ||
|
sidebarAlwaysShowGames ||
|
||||||
pathname === '/' ||
|
pathname === '/' ||
|
||||||
pathname.startsWith('/game')
|
pathname.startsWith('/game')
|
||||||
? ''
|
? ''
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ export default function DownloadsPopup () {
|
|||||||
setDownloadProgress,
|
setDownloadProgress,
|
||||||
downloadQueue,
|
downloadQueue,
|
||||||
setDownloadQueue,
|
setDownloadQueue,
|
||||||
normalConfig,
|
setDownloadedVersionsConfig,
|
||||||
setDownloadedVersionsConfig
|
notificationsAllowed
|
||||||
} = useGlobal()
|
} = useGlobal()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -123,7 +123,7 @@ export default function DownloadsPopup () {
|
|||||||
: d
|
: d
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (normalConfig?.settings.allowNotifications)
|
if (notificationsAllowed)
|
||||||
await notifyUser(
|
await notifyUser(
|
||||||
'Download Failed',
|
'Download Failed',
|
||||||
`The download for version ${
|
`The download for version ${
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { app } from '@tauri-apps/api'
|
import { app } from '@tauri-apps/api'
|
||||||
import { NormalConfig } from '@/types/NormalConfig'
|
|
||||||
import {
|
import {
|
||||||
BaseDirectory,
|
BaseDirectory,
|
||||||
create,
|
create,
|
||||||
@@ -10,80 +9,6 @@ import {
|
|||||||
} from '@tauri-apps/plugin-fs'
|
} from '@tauri-apps/plugin-fs'
|
||||||
import { VersionsConfig } from '@/types/VersionsConfig'
|
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> {
|
export async function readVersionsConfig (): Promise<VersionsConfig> {
|
||||||
const version = await app.getVersion()
|
const version = await app.getVersion()
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { NormalConfig } from '@/types/NormalConfig'
|
import { writeText } from '@tauri-apps/plugin-clipboard-manager'
|
||||||
import { notifyUser } from './Notifications'
|
import { notifyUser } from './Notifications'
|
||||||
|
|
||||||
export async function copyToClipboard (
|
export async function copyToClipboard (
|
||||||
text: string,
|
text: string,
|
||||||
normalConfig: NormalConfig | null
|
notificationsAllowed: boolean
|
||||||
) {
|
) {
|
||||||
if (normalConfig?.settings.allowNotifications)
|
await writeText(text)
|
||||||
|
if (notificationsAllowed)
|
||||||
await notifyUser('Copied', 'Text "' + text + '" copied to clipboard')
|
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