Add relaunch, reset, delete download cache, delete invalid games buttons to settings page
This commit is contained in:
2 files changed
+257
-111
No files matched your search
@@ -20,6 +20,7 @@
|
|||||||
"core:window:allow-request-user-attention",
|
"core:window:allow-request-user-attention",
|
||||||
"core:webview:allow-create-webview-window",
|
"core:webview:allow-create-webview-window",
|
||||||
"fs:default",
|
"fs:default",
|
||||||
|
"fs:allow-remove",
|
||||||
"dialog:default",
|
"dialog:default",
|
||||||
"dialog:allow-open",
|
"dialog:allow-open",
|
||||||
"notification:default",
|
"notification:default",
|
||||||
|
|||||||
+256
-111
@@ -4,15 +4,20 @@ import { Setting } from '@/components/Setting'
|
|||||||
import { useGlobal } from '@/providers/GlobalProvider'
|
import { useGlobal } from '@/providers/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'
|
||||||
import { open } from '@tauri-apps/plugin-dialog'
|
import { message, open } from '@tauri-apps/plugin-dialog'
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
import Dropdown from '@/components/Dropdown'
|
import Dropdown from '@/components/Dropdown'
|
||||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
|
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||||
|
import { relaunch } from '@tauri-apps/plugin-process'
|
||||||
|
import { BaseDirectory, exists, readDir, remove } from '@tauri-apps/plugin-fs'
|
||||||
|
|
||||||
export default function Settings () {
|
export default function Settings () {
|
||||||
const {
|
const {
|
||||||
settings,
|
settings,
|
||||||
|
versions,
|
||||||
|
account,
|
||||||
version,
|
version,
|
||||||
|
versionsList,
|
||||||
notificationsAllowed,
|
notificationsAllowed,
|
||||||
sidebarAlwaysShowGames,
|
sidebarAlwaysShowGames,
|
||||||
linuxUseWine,
|
linuxUseWine,
|
||||||
@@ -26,121 +31,261 @@ export default function Settings () {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p className='text-3xl ml-4 mt-4'>Settings</p>
|
<p className='text-3xl ml-4 mt-4'>Settings</p>
|
||||||
<div className='ml-4 mt-4 bg-(--col1) border border-(--col3) rounded-lg p-4 w-fit h-fit'>
|
<div className='flex flex-row p-4 gap-4'>
|
||||||
<Setting
|
<div className='bg-(--col1) border border-(--col3) rounded-lg p-4 w-fit h-fit'>
|
||||||
label='Allow sending notifications'
|
<Setting
|
||||||
value={notificationsAllowed}
|
label='Allow sending notifications'
|
||||||
onChange={async () => {
|
value={notificationsAllowed}
|
||||||
await settings?.set('notificationsAllowed', !notificationsAllowed)
|
onChange={async () => {
|
||||||
}}
|
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.'
|
}}
|
||||||
/>
|
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'
|
<Setting
|
||||||
value={sidebarAlwaysShowGames}
|
label='Always show games in sidebar'
|
||||||
onChange={async () => {
|
value={sidebarAlwaysShowGames}
|
||||||
await settings?.set(
|
onChange={async () => {
|
||||||
'sidebarAlwaysShowGames',
|
await settings?.set(
|
||||||
!sidebarAlwaysShowGames
|
'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 if needed'
|
|
||||||
value={linuxUseWine}
|
|
||||||
onChange={async () => {
|
|
||||||
await settings?.set('linuxUseWine', !linuxUseWine)
|
|
||||||
}}
|
|
||||||
className={platform() == 'linux' ? '' : 'hidden'}
|
|
||||||
/>
|
|
||||||
{platform() == 'linux' && linuxUseWine && (
|
|
||||||
<>
|
|
||||||
<p>Wine Command:</p>
|
|
||||||
<input
|
|
||||||
type='text'
|
|
||||||
value={linuxWineCommand}
|
|
||||||
onChange={async e =>
|
|
||||||
await settings?.set('linuxWineCommand', e.target.value)
|
|
||||||
}
|
|
||||||
className='input-field my-1'
|
|
||||||
></input>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Setting
|
|
||||||
label='Use custom data location'
|
|
||||||
value={!!customDataLocation}
|
|
||||||
disabled={downloadProgress.length > 0}
|
|
||||||
onChange={async () => {
|
|
||||||
if (customDataLocation) {
|
|
||||||
try {
|
|
||||||
setMovingData(true)
|
|
||||||
await invoke('move_game_data', { destination: '' })
|
|
||||||
await settings?.set('customDataLocation', '')
|
|
||||||
await invoke('restart_app')
|
|
||||||
} catch {
|
|
||||||
setMovingData(false)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const selected = await open({
|
|
||||||
directory: true,
|
|
||||||
title: 'Select data location'
|
|
||||||
})
|
|
||||||
if (!selected || typeof selected !== 'string') return
|
|
||||||
try {
|
|
||||||
setMovingData(true)
|
|
||||||
await invoke('move_game_data', { destination: selected })
|
|
||||||
await settings?.set('customDataLocation', selected)
|
|
||||||
await invoke('restart_app')
|
|
||||||
} catch {
|
|
||||||
setMovingData(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
title='Move game data to a custom storage location, like a different disk.'
|
|
||||||
/>
|
|
||||||
{customDataLocation && (
|
|
||||||
<p className='text-sm opacity-50 ml-6 -mt-1 mb-2'>
|
|
||||||
{customDataLocation}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<div className='flex flex-row gap-2 items-center'>
|
|
||||||
<p
|
|
||||||
title='The theme you want the launcher to use.'
|
|
||||||
className='text-lg'
|
|
||||||
>
|
|
||||||
Theme:
|
|
||||||
</p>
|
|
||||||
<Dropdown
|
|
||||||
value={theme}
|
|
||||||
options={[
|
|
||||||
{ label: 'Dark', value: 'dark' },
|
|
||||||
{ label: 'Red', value: 'red' },
|
|
||||||
{ label: 'Blue', value: 'blue' },
|
|
||||||
{ label: 'Purple', value: 'purple' }
|
|
||||||
]}
|
|
||||||
onChange={async val => {
|
|
||||||
await settings?.set('theme', val)
|
|
||||||
|
|
||||||
const window = await WebviewWindow.getByLabel(
|
|
||||||
'berrydashleaderboards'
|
|
||||||
)
|
)
|
||||||
if (window) {
|
}}
|
||||||
await window.close()
|
title="This setting will make it so when you are on a page like this, the games won't disappear."
|
||||||
|
/>
|
||||||
new WebviewWindow('berrydashleaderboards', {
|
<Setting
|
||||||
title: 'Berry Dash Leaderboards',
|
label='Use wine if needed'
|
||||||
url:
|
value={linuxUseWine}
|
||||||
'https://games.lncvrt.xyz/game/berry-dash/leaderboards?launcher=1&theme=' +
|
onChange={async () => {
|
||||||
val,
|
await settings?.set('linuxUseWine', !linuxUseWine)
|
||||||
width: 800,
|
}}
|
||||||
height: 600,
|
className={platform() == 'linux' ? '' : 'hidden'}
|
||||||
resizable: false,
|
/>
|
||||||
maximizable: false
|
{platform() == 'linux' && linuxUseWine && (
|
||||||
|
<>
|
||||||
|
<p>Wine Command:</p>
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
value={linuxWineCommand}
|
||||||
|
onChange={async e =>
|
||||||
|
await settings?.set('linuxWineCommand', e.target.value)
|
||||||
|
}
|
||||||
|
className='input-field my-1'
|
||||||
|
></input>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Setting
|
||||||
|
label='Use custom data location'
|
||||||
|
value={!!customDataLocation}
|
||||||
|
disabled={downloadProgress.length > 0}
|
||||||
|
onChange={async () => {
|
||||||
|
if (customDataLocation) {
|
||||||
|
try {
|
||||||
|
setMovingData(true)
|
||||||
|
await invoke('move_game_data', { destination: '' })
|
||||||
|
await settings?.set('customDataLocation', '')
|
||||||
|
await invoke('restart_app')
|
||||||
|
} catch {
|
||||||
|
setMovingData(false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const selected = await open({
|
||||||
|
directory: true,
|
||||||
|
title: 'Select data location'
|
||||||
})
|
})
|
||||||
|
if (!selected || typeof selected !== 'string') return
|
||||||
|
try {
|
||||||
|
setMovingData(true)
|
||||||
|
await invoke('move_game_data', { destination: selected })
|
||||||
|
await settings?.set('customDataLocation', selected)
|
||||||
|
await invoke('restart_app')
|
||||||
|
} catch {
|
||||||
|
setMovingData(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
title='Move game data to a custom storage location, like a different disk.'
|
||||||
/>
|
/>
|
||||||
|
{customDataLocation && (
|
||||||
|
<p className='text-sm opacity-50 ml-6 -mt-1 mb-2'>
|
||||||
|
{customDataLocation}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<div className='flex flex-row gap-2 items-center'>
|
||||||
|
<p
|
||||||
|
title='The theme you want the launcher to use.'
|
||||||
|
className='text-lg'
|
||||||
|
>
|
||||||
|
Theme:
|
||||||
|
</p>
|
||||||
|
<Dropdown
|
||||||
|
value={theme}
|
||||||
|
options={[
|
||||||
|
{ label: 'Dark', value: 'dark' },
|
||||||
|
{ label: 'Red', value: 'red' },
|
||||||
|
{ label: 'Blue', value: 'blue' },
|
||||||
|
{ label: 'Purple', value: 'purple' }
|
||||||
|
]}
|
||||||
|
onChange={async val => {
|
||||||
|
await settings?.set('theme', val)
|
||||||
|
|
||||||
|
const window = await WebviewWindow.getByLabel(
|
||||||
|
'berrydashleaderboards'
|
||||||
|
)
|
||||||
|
if (window) {
|
||||||
|
await window.close()
|
||||||
|
|
||||||
|
new WebviewWindow('berrydashleaderboards', {
|
||||||
|
title: 'Berry Dash Leaderboards',
|
||||||
|
url:
|
||||||
|
'https://games.lncvrt.xyz/game/berry-dash/leaderboards?launcher=1&theme=' +
|
||||||
|
val,
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
resizable: false,
|
||||||
|
maximizable: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='bg-(--col1) border border-(--col3) rounded-lg p-4 w-fit h-fit flex flex-col gap-2'>
|
||||||
|
<button
|
||||||
|
className='button btntheme1'
|
||||||
|
title="Restarts the launcher. I don't think I needed to add this description."
|
||||||
|
onClick={async () => await relaunch()}
|
||||||
|
>
|
||||||
|
Restart launcher
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className='button btntheme1'
|
||||||
|
title='Completely reset the launcher, delete games, logout of account & reset settings.'
|
||||||
|
onClick={async () => {
|
||||||
|
if (
|
||||||
|
await exists(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'game',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await remove(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'game',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
await exists(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'downloads',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await remove(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'downloads',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
await settings?.clear()
|
||||||
|
await versions?.clear()
|
||||||
|
await account?.clear()
|
||||||
|
await relaunch()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reset launcher
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className='button btntheme1'
|
||||||
|
title='If you pause or cancel a download, it will be removed here.'
|
||||||
|
onClick={async () => {
|
||||||
|
if (
|
||||||
|
await exists(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'downloads',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await remove(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'downloads',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete download cache
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className='button btntheme1'
|
||||||
|
title='If you had a game that was downloaded before it was taken down after you downloaded it, it will get removed here.'
|
||||||
|
onClick={async () => {
|
||||||
|
const items = await readDir(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) + 'game',
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const removed: string[] = []
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.isFile || item.isSymlink) continue
|
||||||
|
if (
|
||||||
|
!Object.entries(versionsList).find(v => v[0] == item.name)
|
||||||
|
) {
|
||||||
|
removed.push(item.name)
|
||||||
|
await remove(
|
||||||
|
(customDataLocation ? customDataLocation + '/' : null) +
|
||||||
|
'game/' +
|
||||||
|
item.name,
|
||||||
|
{
|
||||||
|
baseDir: customDataLocation
|
||||||
|
? undefined
|
||||||
|
: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message(
|
||||||
|
'Removed the following game items: ' +
|
||||||
|
(removed.length == 0 ? '(none)' : removed.join(', ')),
|
||||||
|
{ title: 'Sucessfully cleaned games folder', kind: 'info' }
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete invalid/unavailable games
|
||||||
|
</button>
|
||||||
|
<p className='text-center'>Hover buttons for descriptions</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p
|
<p
|
||||||
|
|||||||
Reference in new issue
Block a user