From aa10a908ad15f70d3a0e80e9ea4b198d31e4efd2 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 13 Jul 2022 23:43:55 -0700 Subject: [PATCH] idk some wip shit --- src-tauri/src/main.rs | 3 +- src-tauri/src/web.rs | 6 ++++ src/ui/components/menu/Downloads.tsx | 6 ---- src/utils/resources.ts | 45 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/utils/resources.ts diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 216f855..fbec631 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -49,7 +49,8 @@ fn main() { downloader::stop_download, lang::get_lang, lang::get_languages, - web::valid_url + web::valid_url, + web::web_get ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/web.rs b/src-tauri/src/web.rs index af5864d..d363039 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -15,4 +15,10 @@ pub(crate) async fn valid_url(url: String) -> bool { let response = client.get(url).header(USER_AGENT, "cultivation").send().await.unwrap(); response.status().as_str() == "200" +} + +#[tauri::command] +pub async fn web_get(url: String) -> String { + // Send a GET request to the specified URL and send the response body back to the client. + query(&url).await } \ No newline at end of file diff --git a/src/ui/components/menu/Downloads.tsx b/src/ui/components/menu/Downloads.tsx index 0368a46..a12716e 100644 --- a/src/ui/components/menu/Downloads.tsx +++ b/src/ui/components/menu/Downloads.tsx @@ -13,12 +13,6 @@ import { invoke } from '@tauri-apps/api' import { listen } from '@tauri-apps/api/event' import HelpButton from '../common/HelpButton' -const STABLE_REPO_DOWNLOAD = 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip' -const DEV_REPO_DOWNLOAD = 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/development.zip' -const STABLE_DOWNLOAD = 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/stable/Grasscutter.zip' -const DEV_DOWNLOAD = 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/development/Grasscutter.zip' -const RESOURCES_DOWNLOAD = 'https://github.com/Koko-boya/Grasscutter_Resources/archive/refs/heads/main.zip' - interface IProps { closeFn: () => void; downloadManager: DownloadHandler; diff --git a/src/utils/resources.ts b/src/utils/resources.ts new file mode 100644 index 0000000..92f1168 --- /dev/null +++ b/src/utils/resources.ts @@ -0,0 +1,45 @@ +import { invoke } from '@tauri-apps/api' +import { getConfig } from './configuration' + +const globals = { + '2.8.0': { + game: '2.8.0', + metadata: '2.8.0', + resources: 'https://gitlab.com/yukiz/GrasscutterResources/-/archive/2.8/GrasscutterResources-2.8.zip', + stableJar: '', + devJar: 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/2.8/Grasscutter.zip', + stable: '', + dev: 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/2.8.zip' + }, + '2.7.0': { + game: '2.7.0', + metadata: null, + resources: 'https://github.com/Koko-boya/Grasscutter_Resources/archive/refs/heads/main.zip', + stableJar: 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/stable/Grasscutter.zip', + devJar: 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/development/Grasscutter.zip', + stable: 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip', + dev: 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/development.zip' + }, + '2.6.0': { + game: '2.6.0', + metadata: null, + resources: 'https://github.com/Koko-boya/Grasscutter_Resources/archive/0e99a59218a346c2d56c54953f99077882de4a6d.zip', + stableJar: 'https://github.com/Grasscutters/Grasscutter/releases/download/v1.1.0/grasscutter-1.1.0.jar', + stable: 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/2.6.zip', + dev: '' + } +} + +export async function cacheLauncherResources() { + const versionAPIUrl = 'https://sdk-os-static.mihoyo.com/hk4e_global/mdk/launcher/api/resource?channel_id=1&key=gcStgarh&launcher_id=10&sub_channel_id=0' + + // Get versions from API + const versions = JSON.parse(await invoke('web_get', { + url: versionAPIUrl + })) + + if (!versions || versions.retcode !== 0) { + console.log('Failed to get versions from API') + return false + } +} \ No newline at end of file