Add managing versions menu & fix a typo
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
"@tauri-apps/plugin-notification": "2.3.0",
|
"@tauri-apps/plugin-notification": "2.3.0",
|
||||||
"@tauri-apps/plugin-opener": "2.4.0",
|
"@tauri-apps/plugin-opener": "2.4.0",
|
||||||
"@tauri-apps/plugin-os": "2.3.0",
|
"@tauri-apps/plugin-os": "2.3.0",
|
||||||
"axios": "1.10.0",
|
"axios": "1.11.0",
|
||||||
"date-fns": "4.1.0",
|
"date-fns": "4.1.0",
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
"react-dom": "19.1.0"
|
"react-dom": "19.1.0"
|
||||||
|
|||||||
@@ -259,6 +259,49 @@ fn get_keys_config(key: i8) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn uninstall_version(app: AppHandle, name: String) {
|
||||||
|
let game_path = app
|
||||||
|
.path()
|
||||||
|
.app_local_data_dir()
|
||||||
|
.unwrap()
|
||||||
|
.join("game")
|
||||||
|
.join(&name);
|
||||||
|
if game_path.exists() {
|
||||||
|
if let Err(_) = tokio::fs::remove_dir_all(&game_path).await {
|
||||||
|
app.emit("version-failed", &name).unwrap();
|
||||||
|
} else {
|
||||||
|
app.emit("version-uninstalled", &name).unwrap();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.emit("version-uninstalled", &name).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn open_folder(app: AppHandle, name: String) {
|
||||||
|
let game_path = app
|
||||||
|
.path()
|
||||||
|
.app_local_data_dir()
|
||||||
|
.unwrap()
|
||||||
|
.join("game")
|
||||||
|
.join(&name);
|
||||||
|
if game_path.exists() {
|
||||||
|
app.opener()
|
||||||
|
.open_path(game_path.to_string_lossy(), None::<&str>)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
app.dialog()
|
||||||
|
.message(format!(
|
||||||
|
"Game folder \"{}\" not found.",
|
||||||
|
game_path.display()
|
||||||
|
))
|
||||||
|
.kind(MessageDialogKind::Error)
|
||||||
|
.title("Folder not found")
|
||||||
|
.show(|_| {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
@@ -278,7 +321,9 @@ pub fn run() {
|
|||||||
download,
|
download,
|
||||||
launch_game,
|
launch_game,
|
||||||
download_leaderboard,
|
download_leaderboard,
|
||||||
get_keys_config
|
get_keys_config,
|
||||||
|
uninstall_version,
|
||||||
|
open_folder
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|||||||
62
src/main.tsx
62
src/main.tsx
@@ -50,8 +50,15 @@ function App () {
|
|||||||
const [downloadedVersionsConfig, setDownloadedVersionsConfig] =
|
const [downloadedVersionsConfig, setDownloadedVersionsConfig] =
|
||||||
useState<VersionsConfig | null>(null)
|
useState<VersionsConfig | null>(null)
|
||||||
const [normalConfig, setNormalConfig] = useState<NormalConfig | null>(null)
|
const [normalConfig, setNormalConfig] = useState<NormalConfig | null>(null)
|
||||||
|
const [managingVersion, setManagingVersion] =
|
||||||
|
useState<DownloadedVersion | null>(null)
|
||||||
|
|
||||||
function runNext () {
|
function runNext () {
|
||||||
|
if (activeDownloads.current === 0 && queue.current.length === 0) {
|
||||||
|
setFadeOut(true)
|
||||||
|
setTimeout(() => setShowPopup(false), 200)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (activeDownloads.current >= 3 || queue.current.length === 0) return
|
if (activeDownloads.current >= 3 || queue.current.length === 0) return
|
||||||
activeDownloads.current++
|
activeDownloads.current++
|
||||||
const next = queue.current.shift()
|
const next = queue.current.shift()
|
||||||
@@ -133,10 +140,32 @@ function App () {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const unlistenUninstalled = listen<string>(
|
||||||
|
'version-uninstalled',
|
||||||
|
async event => {
|
||||||
|
const versionName = event.payload
|
||||||
|
setDownloadedVersionsConfig(prev => {
|
||||||
|
if (!prev) return prev
|
||||||
|
const updatedList = prev.list.filter(
|
||||||
|
v => v.version.version !== versionName
|
||||||
|
)
|
||||||
|
const updatedConfig = { ...prev, list: updatedList }
|
||||||
|
writeVersionsConfig(updatedConfig)
|
||||||
|
if (popupMode === 2) {
|
||||||
|
setManagingVersion(null)
|
||||||
|
setFadeOut(true)
|
||||||
|
setTimeout(() => setShowPopup(false), 200)
|
||||||
|
}
|
||||||
|
return updatedConfig
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unlistenProgress.then(f => f())
|
unlistenProgress.then(f => f())
|
||||||
unlistenDone.then(f => f())
|
unlistenDone.then(f => f())
|
||||||
unlistenFailed.then(f => f())
|
unlistenFailed.then(f => f())
|
||||||
|
unlistenUninstalled.then(f => f())
|
||||||
}
|
}
|
||||||
}, [downloadedVersionsConfig])
|
}, [downloadedVersionsConfig])
|
||||||
|
|
||||||
@@ -246,6 +275,7 @@ function App () {
|
|||||||
setVersionList={setVersionList}
|
setVersionList={setVersionList}
|
||||||
downloadedVersionsConfig={downloadedVersionsConfig}
|
downloadedVersionsConfig={downloadedVersionsConfig}
|
||||||
normalConfig={normalConfig}
|
normalConfig={normalConfig}
|
||||||
|
setManagingVersion={setManagingVersion}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
} else if (hash === '#settings') {
|
} else if (hash === '#settings') {
|
||||||
@@ -411,6 +441,38 @@ function App () {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
) : popupMode === 2 ? (
|
||||||
|
managingVersion ? (
|
||||||
|
<>
|
||||||
|
<p className='text-xl text-center'>
|
||||||
|
Manage version {managingVersion.version.displayName}
|
||||||
|
</p>
|
||||||
|
<div className='popup-content flex flex-col items-center justify-center gap-2 h-full'>
|
||||||
|
<button
|
||||||
|
className='button'
|
||||||
|
onClick={() =>
|
||||||
|
invoke('uninstall_version', {
|
||||||
|
name: managingVersion.version.version
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Uninstall
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className='button'
|
||||||
|
onClick={async () =>
|
||||||
|
invoke('open_folder', {
|
||||||
|
name: managingVersion.version.version
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Open Folder
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className='text-xl text-center'>No version selected</p>
|
||||||
|
)
|
||||||
) : null}
|
) : null}
|
||||||
{popupMode == 0 && versionList != null && (
|
{popupMode == 0 && versionList != null && (
|
||||||
<div className='flex justify-center'>
|
<div className='flex justify-center'>
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ export default function Installs ({
|
|||||||
setSelectedVersionList,
|
setSelectedVersionList,
|
||||||
setVersionList,
|
setVersionList,
|
||||||
downloadedVersionsConfig,
|
downloadedVersionsConfig,
|
||||||
normalConfig
|
normalConfig,
|
||||||
|
setManagingVersion
|
||||||
}: InstallsProps) {
|
}: InstallsProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showPopup) return
|
if (!showPopup) return
|
||||||
@@ -49,7 +50,7 @@ export default function Installs ({
|
|||||||
return (
|
return (
|
||||||
<div className='mx-4 mt-4'>
|
<div className='mx-4 mt-4'>
|
||||||
<div className='flex justify-between items-center mb-4'>
|
<div className='flex justify-between items-center mb-4'>
|
||||||
<p className='text-3xl'>Install</p>
|
<p className='text-3xl'>Installs</p>
|
||||||
<button
|
<button
|
||||||
className='button text-3xl'
|
className='button text-3xl'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -75,10 +76,21 @@ export default function Installs ({
|
|||||||
</p>
|
</p>
|
||||||
<p className='text-gray-400 text-md'>
|
<p className='text-gray-400 text-md'>
|
||||||
Installed{' '}
|
Installed{' '}
|
||||||
{format(new Date(entry.installDate), 'yyyy/MM/dd')}
|
{format(new Date(entry.installDate), 'MM/dd/yyyy')}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-row items-center gap-2'>
|
<div className='flex flex-row items-center gap-2'>
|
||||||
|
<button
|
||||||
|
className='button'
|
||||||
|
onClick={async () => {
|
||||||
|
setManagingVersion(entry)
|
||||||
|
setPopupMode(2)
|
||||||
|
setShowPopup(true)
|
||||||
|
setFadeOut(false)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Manage
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
className='button'
|
className='button'
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { DownloadedVersion } from './DownloadedVersion'
|
||||||
import { DownloadProgress } from './DownloadProgress'
|
import { DownloadProgress } from './DownloadProgress'
|
||||||
import { LauncherVersion } from './LauncherVersion'
|
import { LauncherVersion } from './LauncherVersion'
|
||||||
import { NormalConfig } from './NormalConfig'
|
import { NormalConfig } from './NormalConfig'
|
||||||
@@ -13,4 +14,5 @@ export type InstallsProps = {
|
|||||||
setVersionList: (v: null | LauncherVersion[]) => void
|
setVersionList: (v: null | LauncherVersion[]) => void
|
||||||
downloadedVersionsConfig: VersionsConfig | null
|
downloadedVersionsConfig: VersionsConfig | null
|
||||||
normalConfig: NormalConfig | null
|
normalConfig: NormalConfig | null
|
||||||
|
setManagingVersion: (v: DownloadedVersion | null) => void
|
||||||
}
|
}
|
||||||
|
|||||||
12
yarn.lock
12
yarn.lock
@@ -820,13 +820,13 @@ asynckit@^0.4.0:
|
|||||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||||
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
|
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
|
||||||
|
|
||||||
axios@1.10.0:
|
axios@1.11.0:
|
||||||
version "1.10.0"
|
version "1.11.0"
|
||||||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.10.0.tgz#af320aee8632eaf2a400b6a1979fa75856f38d54"
|
resolved "https://registry.yarnpkg.com/axios/-/axios-1.11.0.tgz#c2ec219e35e414c025b2095e8b8280278478fdb6"
|
||||||
integrity sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw==
|
integrity sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==
|
||||||
dependencies:
|
dependencies:
|
||||||
follow-redirects "^1.15.6"
|
follow-redirects "^1.15.6"
|
||||||
form-data "^4.0.0"
|
form-data "^4.0.4"
|
||||||
proxy-from-env "^1.1.0"
|
proxy-from-env "^1.1.0"
|
||||||
|
|
||||||
browserslist@^4.24.0:
|
browserslist@^4.24.0:
|
||||||
@@ -997,7 +997,7 @@ follow-redirects@^1.15.6:
|
|||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
|
||||||
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
|
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
|
||||||
|
|
||||||
form-data@^4.0.0:
|
form-data@^4.0.4:
|
||||||
version "4.0.4"
|
version "4.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
|
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
|
||||||
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
|
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
|
||||||
|
|||||||
Reference in New Issue
Block a user