From ecd4bff8823aac71328cee3a1adf852b55335095 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 17:40:24 -0700 Subject: [PATCH 01/15] get language despite admin or not --- src-tauri/src/lang.rs | 6 ++++-- src-tauri/src/system_helpers.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lang.rs b/src-tauri/src/lang.rs index 23c518e..8a7f53d 100644 --- a/src-tauri/src/lang.rs +++ b/src-tauri/src/lang.rs @@ -1,9 +1,11 @@ +use crate::system_helpers::*; + #[tauri::command] pub async fn get_lang(window: tauri::Window, lang: String) -> String { let lang = lang.to_lowercase(); // Send contents of language file back - let contents = match std::fs::read_to_string(format!("./lang/{}.json", lang)) { + let contents = match std::fs::read_to_string(format!("{}/lang/{}.json", install_location(), lang)) { Ok(x) => x, Err(e) => { emit_lang_err(window, format!("Failed to read language file: {}", e)); @@ -19,7 +21,7 @@ pub async fn get_languages() -> std::collections::HashMap { // for each lang file, set the key as the filename and the value as the lang_name contained in the file let mut languages = std::collections::HashMap::new(); - let mut lang_files = std::fs::read_dir("./lang").unwrap(); + let mut lang_files = std::fs::read_dir(format!("{}/lang", install_location())).unwrap(); while let Some(entry) = lang_files.next() { let entry = entry.unwrap(); diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 4a79d79..bafcef9 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -54,3 +54,14 @@ pub fn open_in_browser(url: String) { Err(e) => println!("Failed to open URL: {}", e), }; } + +pub fn install_location() -> String { + let mut exe_path = std::env::current_exe().unwrap(); + + // Get the path to the executable. + exe_path.pop(); + + println!("{}", exe_path.to_str().unwrap().to_string()); + + return exe_path.to_str().unwrap().to_string(); +} \ No newline at end of file From 7d0326dcdf017f2cfaf03cf37abad4040656f2ac Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 17:44:53 -0700 Subject: [PATCH 02/15] fix background --- src-tauri/src/system_helpers.rs | 2 -- src/ui/App.css | 7 ++----- src/ui/App.tsx | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index bafcef9..a6379e9 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -61,7 +61,5 @@ pub fn install_location() -> String { // Get the path to the executable. exe_path.pop(); - println!("{}", exe_path.to_str().unwrap().to_string()); - return exe_path.to_str().unwrap().to_string(); } \ No newline at end of file diff --git a/src/ui/App.css b/src/ui/App.css index 21d1f5c..bece781 100644 --- a/src/ui/App.css +++ b/src/ui/App.css @@ -27,11 +27,8 @@ select:focus { } .App { - background-repeat: no-repeat; - background-size: cover; - -webkit-background-size: cover; - -moz-background-size: cover; - -o-background-size: cover; + background-size: contain !important; + background-position: center; } .TopButton { diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 7312d53..47b62a4 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -117,7 +117,7 @@ class App extends React.Component { return (
Date: Wed, 1 Jun 2022 17:49:10 -0700 Subject: [PATCH 03/15] fixes --- src/ui/App.css | 4 ++-- src/ui/App.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/App.css b/src/ui/App.css index bece781..99074c7 100644 --- a/src/ui/App.css +++ b/src/ui/App.css @@ -27,8 +27,8 @@ select:focus { } .App { - background-size: contain !important; - background-position: center; + background-size: cover !important; + background-position: center !important; } .TopButton { diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 47b62a4..4d329d7 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -76,8 +76,8 @@ class App extends React.Component { const cert_generated = await getConfigOption('cert_generated') const game_exe = await getConfigOption('game_install_path') const custom_bg = await getConfigOption('customBackground') - const game_path = game_exe.substring(0, game_exe.lastIndexOf('\\')) - const root_path = game_path.substring(0, game_path.lastIndexOf('\\')) + const game_path = game_exe.substring(0, game_exe.replace(/\\/g, '/').lastIndexOf('/')) + const root_path = game_path.substring(0, game_path.replace(/\\/g, '/').lastIndexOf('/')) if(!custom_bg) { if(game_path) { From 53f42be9677efea66dd17fbe74f8bc9d38b21f8a Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 18:08:50 -0700 Subject: [PATCH 04/15] move image files to local bg folder --- src-tauri/src/main.rs | 19 +++++++++++++------ src-tauri/src/system_helpers.rs | 21 +++++++++++++++++++++ src/ui/App.tsx | 8 +++----- src/ui/components/menu/Options.tsx | 9 ++++++++- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e2bce0b..6d4c3d1 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -29,6 +29,12 @@ lazy_static! { fn main() { process_watcher(); + // Make BG folder if it doesn't exist + let bg_folder = format!("{}/bg", system_helpers::install_location()); + if !std::path::Path::new(&bg_folder).exists() { + std::fs::create_dir_all(&bg_folder).unwrap(); + } + tauri::Builder::default() .invoke_handler(tauri::generate_handler![ enable_process_watcher, @@ -42,6 +48,8 @@ fn main() { system_helpers::run_program, system_helpers::run_jar, system_helpers::open_in_browser, + system_helpers::get_local_bg_path, + system_helpers::copy_file, proxy::set_proxy_addr, proxy::generate_ca_files, unzip::unzip, @@ -137,6 +145,7 @@ async fn req_get(url: String) -> String { #[tauri::command] async fn get_bg_file(bg_path: String) -> String { + let install_loc = system_helpers::install_location(); let query = web::query("https://api.grasscutters.xyz/cultivation/query").await; let response_data: APIQuery = match serde_json::from_str(&query) { Ok(data) => data, @@ -149,9 +158,8 @@ async fn get_bg_file(bg_path: String) -> String { let file_name = response_data.bg_file.to_string(); // First we see if the file already exists in our local bg folder. - if file_helpers::dir_exists(format!(".\\bg\\{}", file_name).as_str()) { - let cwd = std::env::current_dir().unwrap(); - return format!("{}\\{}", cwd.display(), response_data.bg_file.as_str()); + if file_helpers::dir_exists(format!("{}\\bg\\{}", install_loc, file_name).as_str()) { + return format!("{}\\{}", install_loc, response_data.bg_file.as_str()); } // Now we check if the bg folder, which is one directory above the game_path, exists. @@ -169,13 +177,12 @@ async fn get_bg_file(bg_path: String) -> String { } // The image exists, lets copy it to our local '\bg' folder. - let bg_img_path_local = format!(".\\bg\\{}", file_name.as_str()); + let bg_img_path_local = format!("{}\\bg\\{}", install_loc, file_name.as_str()); return match std::fs::copy(bg_img_path, bg_img_path_local) { Ok(_) => { // Copy was successful, lets return true. - let cwd = std::env::current_dir().unwrap(); - format!("{}\\{}", cwd.display(), response_data.bg_file.as_str()) + format!("{}\\{}", install_loc, response_data.bg_file.as_str()) } Err(e) => { // Copy failed, lets return false diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index a6379e9..905782e 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -3,6 +3,7 @@ use std::thread; use std::process::Command; use tauri; use open; +use crate::system_helpers; #[tauri::command] pub fn run_program(path: String) { @@ -55,6 +56,26 @@ pub fn open_in_browser(url: String) { }; } +#[tauri::command] +pub fn get_local_bg_path() -> String { + // Get the local BG folder. + return format!("{}/bg", system_helpers::install_location()) +} + +#[tauri::command] +pub fn copy_file(path: String, new_path: String) -> bool { + let filename = &path.split("/").last().unwrap(); + + // Copy old to new + match std::fs::copy(&path, format!("{}/{}", new_path, filename)) { + Ok(_) => true, + Err(e) => { + println!("Failed to copy file: {}", e); + false + } + } +} + pub fn install_location() -> String { let mut exe_path = std::env::current_exe().unwrap(); diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 4d329d7..e822019 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -88,11 +88,11 @@ class App extends React.Component { bgLoc && this.setState({ bgFile: bgLoc - }) + }, this.forceUpdate) } } else this.setState({ bgFile: custom_bg - }) + }, this.forceUpdate) if (!cert_generated) { // Generate the certificate @@ -109,15 +109,13 @@ class App extends React.Component { isDownloading: downloadHandler.getDownloads().filter(d => d.status !== 'finished')?.length > 0 }) }, 1000) - - console.log('mounting app component with background: ' + this.state.bgFile) } render() { return (
void; @@ -80,8 +81,14 @@ export default class Options extends React.Component { }) } - setCustomBackground(value: string) { + async setCustomBackground(value: string) { setConfigOption('customBackground', value) + + // Copy the file over to the local directory + invoke('copy_file', { + path: value.replace(/\\/g, '/'), + newPath: await invoke('get_local_bg_path') + }) } render() { From a1f768140d45f7da761dcd5d308887918715f076 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 18:13:25 -0700 Subject: [PATCH 05/15] fix bg file path not showing --- src/ui/components/common/TextInput.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ui/components/common/TextInput.tsx b/src/ui/components/common/TextInput.tsx index 2d8dbe2..596b0d6 100644 --- a/src/ui/components/common/TextInput.tsx +++ b/src/ui/components/common/TextInput.tsx @@ -30,12 +30,6 @@ export default class TextInput extends React.Component { } static getDerivedStateFromProps(props: IProps, state: IState) { - if (!props.readOnly) { - return { - value: state.value - } - } - return { value: props.value || '' } } From aedd7ecf3c8f2350adfe546ab8804bb91eaa391b Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 18:52:32 -0700 Subject: [PATCH 06/15] proper setting and getting local files --- src-tauri/src/main.rs | 13 ++++++------- src-tauri/src/system_helpers.rs | 15 ++++++++------- src-tauri/tauri.conf.json | 11 ++++++++++- src/ui/App.tsx | 6 ++++-- src/ui/components/menu/Options.tsx | 8 ++++++-- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6d4c3d1..16318bc 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -48,7 +48,6 @@ fn main() { system_helpers::run_program, system_helpers::run_jar, system_helpers::open_in_browser, - system_helpers::get_local_bg_path, system_helpers::copy_file, proxy::set_proxy_addr, proxy::generate_ca_files, @@ -144,8 +143,8 @@ async fn req_get(url: String) -> String { } #[tauri::command] -async fn get_bg_file(bg_path: String) -> String { - let install_loc = system_helpers::install_location(); +async fn get_bg_file(bg_path: String, appdata: String) -> String { + let copy_loc = appdata; let query = web::query("https://api.grasscutters.xyz/cultivation/query").await; let response_data: APIQuery = match serde_json::from_str(&query) { Ok(data) => data, @@ -158,8 +157,8 @@ async fn get_bg_file(bg_path: String) -> String { let file_name = response_data.bg_file.to_string(); // First we see if the file already exists in our local bg folder. - if file_helpers::dir_exists(format!("{}\\bg\\{}", install_loc, file_name).as_str()) { - return format!("{}\\{}", install_loc, response_data.bg_file.as_str()); + if file_helpers::dir_exists(format!("{}\\bg\\{}", copy_loc, file_name).as_str()) { + return format!("{}\\{}", copy_loc, response_data.bg_file.as_str()); } // Now we check if the bg folder, which is one directory above the game_path, exists. @@ -177,12 +176,12 @@ async fn get_bg_file(bg_path: String) -> String { } // The image exists, lets copy it to our local '\bg' folder. - let bg_img_path_local = format!("{}\\bg\\{}", install_loc, file_name.as_str()); + let bg_img_path_local = format!("{}\\bg\\{}", copy_loc, file_name.as_str()); return match std::fs::copy(bg_img_path, bg_img_path_local) { Ok(_) => { // Copy was successful, lets return true. - format!("{}\\{}", install_loc, response_data.bg_file.as_str()) + format!("{}\\{}", copy_loc, response_data.bg_file.as_str()) } Err(e) => { // Copy failed, lets return false diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 905782e..8beb1e1 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -3,7 +3,8 @@ use std::thread; use std::process::Command; use tauri; use open; -use crate::system_helpers; + +use crate::file_helpers; #[tauri::command] pub fn run_program(path: String) { @@ -56,15 +57,15 @@ pub fn open_in_browser(url: String) { }; } -#[tauri::command] -pub fn get_local_bg_path() -> String { - // Get the local BG folder. - return format!("{}/bg", system_helpers::install_location()) -} - #[tauri::command] pub fn copy_file(path: String, new_path: String) -> bool { let filename = &path.split("/").last().unwrap(); + let mut new_path_buf = std::path::PathBuf::from(&new_path); + + // If the new path doesn't exist, create it. + if !file_helpers::dir_exists(new_path_buf.pop().to_string().as_str()) { + std::fs::create_dir_all(&new_path).unwrap(); + } // Copy old to new match std::fs::copy(&path, format!("{}/{}", new_path, filename)) { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index a8c7ea7..6992257 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -18,6 +18,15 @@ "$DATA/cultivation/*" ] }, + "protocol": { + "all": true, + "asset": true, + "assetScope": [ + "$DATA", + "$DATA/cultivation", + "$DATA/cultivation/*" + ] + }, "all": true }, "bundle": { @@ -54,7 +63,7 @@ } }, "security": { - "csp": null + "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost" }, "updater": { "active": false diff --git a/src/ui/App.tsx b/src/ui/App.tsx index e822019..be28e0e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -20,6 +20,7 @@ import { getConfigOption, setConfigOption } from '../utils/configuration' import { invoke } from '@tauri-apps/api' import { dataDir } from '@tauri-apps/api/path' import { appWindow } from '@tauri-apps/api/window' +import { convertFileSrc } from '@tauri-apps/api/tauri' interface IProps { [key: string]: never; @@ -83,7 +84,8 @@ class App extends React.Component { if(game_path) { // Get the bg by invoking, then set the background to that bg. const bgLoc: string = await invoke('get_bg_file', { - bgPath: root_path + bgPath: root_path, + appdata: await dataDir() }) bgLoc && this.setState({ @@ -91,7 +93,7 @@ class App extends React.Component { }, this.forceUpdate) } } else this.setState({ - bgFile: custom_bg + bgFile: convertFileSrc(custom_bg) }, this.forceUpdate) if (!cert_generated) { diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index e29ac2c..76c35cd 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -7,6 +7,7 @@ import { setConfigOption, getConfig, getConfigOption } from '../../../utils/conf import Checkbox from '../common/Checkbox' import Divider from './Divider' import { invoke } from '@tauri-apps/api' +import { dataDir } from '@tauri-apps/api/path' interface IProps { closeFn: () => void; @@ -82,12 +83,15 @@ export default class Options extends React.Component { } async setCustomBackground(value: string) { - setConfigOption('customBackground', value) + const filename = value.replace(/\\/g, '/').split('/').pop() + const localBgPath = (await dataDir() as string).replace(/\\/g, '/') + + setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) // Copy the file over to the local directory invoke('copy_file', { path: value.replace(/\\/g, '/'), - newPath: await invoke('get_local_bg_path') + newPath: `${localBgPath}cultivation/bg/` }) } From c1973a2d2eac2ae589bb2eee36c25b1f5a31eefc Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 18:59:33 -0700 Subject: [PATCH 07/15] reload launcher on bg set --- src/ui/components/menu/Options.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index 76c35cd..5f4a053 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -38,6 +38,7 @@ export default class Options extends React.Component { } this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this) + this.setCustomBackground = this.setCustomBackground.bind(this) } async componentDidMount() { @@ -86,13 +87,15 @@ export default class Options extends React.Component { const filename = value.replace(/\\/g, '/').split('/').pop() const localBgPath = (await dataDir() as string).replace(/\\/g, '/') - setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) + await setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) // Copy the file over to the local directory - invoke('copy_file', { + await invoke('copy_file', { path: value.replace(/\\/g, '/'), newPath: `${localBgPath}cultivation/bg/` }) + + window.location.reload() } render() { From 54d400d67b00397c430a5f3eebc41b4226fbfa4a Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 19:04:21 -0700 Subject: [PATCH 08/15] differ between URL and file custom bg --- src/ui/App.tsx | 19 ++++++++++++++++--- src/ui/components/menu/Options.tsx | 29 ++++++++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index be28e0e..2d6cb6e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -92,9 +92,22 @@ class App extends React.Component { bgFile: bgLoc }, this.forceUpdate) } - } else this.setState({ - bgFile: convertFileSrc(custom_bg) - }, this.forceUpdate) + } else { + const isUrl = /^(?:http(s)?:\/\/)/gm.test(custom_bg) + + console.log(isUrl) + + + if (!isUrl) { + this.setState({ + bgFile: convertFileSrc(custom_bg) + }, this.forceUpdate) + } else { + this.setState({ + bgFile: custom_bg + }, this.forceUpdate) + } + } if (!cert_generated) { // Generate the certificate diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index 5f4a053..de66999 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -84,18 +84,25 @@ export default class Options extends React.Component { } async setCustomBackground(value: string) { - const filename = value.replace(/\\/g, '/').split('/').pop() - const localBgPath = (await dataDir() as string).replace(/\\/g, '/') + const isUrl = /^(?:http(s)?:\/\/)/gm.test(value) - await setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) - - // Copy the file over to the local directory - await invoke('copy_file', { - path: value.replace(/\\/g, '/'), - newPath: `${localBgPath}cultivation/bg/` - }) - - window.location.reload() + if (!isUrl) { + const filename = value.replace(/\\/g, '/').split('/').pop() + const localBgPath = (await dataDir() as string).replace(/\\/g, '/') + + await setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) + + // Copy the file over to the local directory + await invoke('copy_file', { + path: value.replace(/\\/g, '/'), + newPath: `${localBgPath}cultivation/bg/` + }) + + window.location.reload() + } else { + await setConfigOption('customBackground', value) + window.location.reload() + } } render() { From fe48eb3c670902b164d25972e25c228a42bef289 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 19:04:36 -0700 Subject: [PATCH 09/15] remove logging --- src/ui/App.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 2d6cb6e..5b8dce1 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -95,9 +95,6 @@ class App extends React.Component { } else { const isUrl = /^(?:http(s)?:\/\/)/gm.test(custom_bg) - console.log(isUrl) - - if (!isUrl) { this.setState({ bgFile: convertFileSrc(custom_bg) From e71ca9ff403e88d2da2fa8c466025afc46d6af0c Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 19:20:43 -0700 Subject: [PATCH 10/15] validate url backgrounds --- src-tauri/src/main.rs | 3 ++- src-tauri/src/web.rs | 10 ++++++++++ src/ui/App.tsx | 11 +++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 16318bc..3d2418d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -57,7 +57,8 @@ fn main() { downloader::download_file, downloader::stop_download, lang::get_lang, - lang::get_languages + lang::get_languages, + web::valid_url ]) .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 420a05b..c155f86 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -5,4 +5,14 @@ pub(crate) async fn query(site: &str) -> String { let response = client.get(site).header(USER_AGENT, "cultivation").send().await.unwrap(); return response.text().await.unwrap(); +} + +#[tauri::command] +pub(crate) async fn valid_url(url: String) -> bool { + // Check if we get a 200 response + let client = reqwest::Client::new(); + + let response = client.get(url).header(USER_AGENT, "cultivation").send().await.unwrap(); + + return response.status().as_str() == "200"; } \ No newline at end of file diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 5b8dce1..4822a5e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -35,6 +35,8 @@ interface IState { bgFile: string; } +const DEFAULT_BG = 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png' + const downloadHandler = new DownloadHandler() class App extends React.Component { @@ -46,7 +48,7 @@ class App extends React.Component { miniDownloadsOpen: false, downloadsOpen: false, gameDownloadsOpen: false, - bgFile: 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png', + bgFile: DEFAULT_BG, } listen('lang_error', (payload) => { @@ -100,8 +102,13 @@ class App extends React.Component { bgFile: convertFileSrc(custom_bg) }, this.forceUpdate) } else { + // Check if URL returns a valid image. + const isValid = await invoke('valid_url', { + url: custom_bg + }) + this.setState({ - bgFile: custom_bg + bgFile: isValid ? custom_bg : DEFAULT_BG }, this.forceUpdate) } } From 3611cf1a152e7700763f87bfcfe4e907995c7bfd Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 19:31:43 -0700 Subject: [PATCH 11/15] bg changes --- src/ui/App.tsx | 2 +- src/ui/components/menu/Options.tsx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 4822a5e..8490b11 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -82,7 +82,7 @@ class App extends React.Component { const game_path = game_exe.substring(0, game_exe.replace(/\\/g, '/').lastIndexOf('/')) const root_path = game_path.substring(0, game_path.replace(/\\/g, '/').lastIndexOf('/')) - if(!custom_bg) { + if(!custom_bg || !/png|jpg|jpeg$/.test(custom_bg)) { if(game_path) { // Get the bg by invoking, then set the background to that bg. const bgLoc: string = await invoke('get_bg_file', { diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index de66999..03b8826 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -86,6 +86,8 @@ export default class Options extends React.Component { async setCustomBackground(value: string) { const isUrl = /^(?:http(s)?:\/\/)/gm.test(value) + if (!value) return await setConfigOption('customBackground', '') + if (!isUrl) { const filename = value.replace(/\\/g, '/').split('/').pop() const localBgPath = (await dataDir() as string).replace(/\\/g, '/') From 7de67e9c42ab6663d8f9adc18ae500d30137cad3 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 20:03:45 -0700 Subject: [PATCH 12/15] right bar extension --- src/ui/components/RightBar.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/components/RightBar.css b/src/ui/components/RightBar.css index b1effd5..dd0218b 100644 --- a/src/ui/components/RightBar.css +++ b/src/ui/components/RightBar.css @@ -7,14 +7,14 @@ align-items: center; justify-content: flex-start; - height: calc(100vh - 190px); + height: 100vh; width: 80px; right: 0%; z-index: 99; background-color: rgba(77, 77, 77, 0.6); - z-index: 99; + z-index: 999; } .BarImg:hover { From adb4b9458588331ca067a4acaddd063ad1ab3868 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 22:15:10 -0700 Subject: [PATCH 13/15] resource button is enabled after repo download --- src/ui/components/menu/Downloads.tsx | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/ui/components/menu/Downloads.tsx b/src/ui/components/menu/Downloads.tsx index 5bc75a3..6fb891f 100644 --- a/src/ui/components/menu/Downloads.tsx +++ b/src/ui/components/menu/Downloads.tsx @@ -10,6 +10,7 @@ import './Downloads.css' import Divider from './Divider' import { getConfigOption, setConfigOption } from '../../../utils/configuration' import { invoke } from '@tauri-apps/api' +import { listen } from '@tauri-apps/api/event' 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' @@ -48,12 +49,16 @@ export default class Downloads extends React.Component { this.downloadGrasscutterStable = this.downloadGrasscutterStable.bind(this) this.downloadGrasscutterLatest = this.downloadGrasscutterLatest.bind(this) this.downloadResources = this.downloadResources.bind(this) - this.disableButtons = this.disableButtons.bind(this) + this.toggleButtons = this.toggleButtons.bind(this) } async componentDidMount() { const gc_path = await getConfigOption('grasscutter_path') + listen('jar_extracted', () => { + this.setState({ grasscutter_set: true }, this.forceUpdate) + }) + if (!gc_path || gc_path === '') { this.setState({ grasscutter_set: false, @@ -102,43 +107,43 @@ export default class Downloads extends React.Component { async downloadGrasscutterStableRepo() { const folder = await this.getGrasscutterFolder() this.props.downloadManager.addDownload(STABLE_REPO_DOWNLOAD, folder + '\\grasscutter_repo.zip', () =>{ - unzip(folder + '\\grasscutter_repo.zip', folder + '\\') + unzip(folder + '\\grasscutter_repo.zip', folder + '\\', this.toggleButtons) }) - this.disableButtons() + this.toggleButtons() } async downloadGrasscutterDevRepo() { const folder = await this.getGrasscutterFolder() this.props.downloadManager.addDownload(DEV_REPO_DOWNLOAD, folder + '\\grasscutter_repo.zip', () =>{ - unzip(folder + '\\grasscutter_repo.zip', folder + '\\') + unzip(folder + '\\grasscutter_repo.zip', folder + '\\', this.toggleButtons) }) - this.disableButtons() + this.toggleButtons() } async downloadGrasscutterStable() { const folder = await this.getGrasscutterFolder() this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.zip', () =>{ - unzip(folder + '\\grasscutter.zip', folder + '\\') + unzip(folder + '\\grasscutter.zip', folder + '\\', this.toggleButtons) }) // Also add repo download this.downloadGrasscutterStableRepo() - this.disableButtons() + this.toggleButtons() } async downloadGrasscutterLatest() { const folder = await this.getGrasscutterFolder() this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.zip', () =>{ - unzip(folder + '\\grasscutter.zip', folder + '\\') + unzip(folder + '\\grasscutter.zip', folder + '\\', this.toggleButtons) }) // Also add repo download this.downloadGrasscutterDevRepo() - this.disableButtons() + this.toggleButtons() } async downloadResources() { @@ -150,18 +155,23 @@ export default class Downloads extends React.Component { path: folder + '\\Resources', newName: 'resources' }) + + this.toggleButtons() }) }) - this.disableButtons() + this.toggleButtons() } - disableButtons() { + async toggleButtons() { + const gc_path = await getConfigOption('grasscutter_path') + // Set states since we know we are downloading something if this is called this.setState({ grasscutter_downloading: this.props.downloadManager.downloadingJar(), resources_downloading: this.props.downloadManager.downloadingResources(), - repo_downloading: this.props.downloadManager.downloadingRepo() + repo_downloading: this.props.downloadManager.downloadingRepo(), + grasscutter_set: gc_path && gc_path !== '', }) } From 91581f620a6f05d27d517fae59d155c4440f18ad Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 22:17:58 -0700 Subject: [PATCH 14/15] alert when game is not found --- src/ui/components/ServerLaunchSection.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index e4953c5..cb58e15 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -107,7 +107,12 @@ export default class ServerLaunchSection extends React.Component } // Launch the program - await invoke('run_program', { path: config.game_install_path }) + const gameExists = await invoke('dir_exists', { + path: config.game_install_path + }) + + if (gameExists) await invoke('run_program', { path: config.game_install_path }) + else alert('Game not found!') } async launchServer() { From 5aaa85939cce95529bc9af91117cb3e50ef6c4b5 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Thu, 2 Jun 2022 16:46:57 -0700 Subject: [PATCH 15/15] new bg --- src/ui/App.tsx | 2 +- src/ui/components/ServerLaunchSection.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 8490b11..147cf29 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -35,7 +35,7 @@ interface IState { bgFile: string; } -const DEFAULT_BG = 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png' +const DEFAULT_BG = 'https://api.grasscutters.xyz/content/bgfile' const downloadHandler = new DownloadHandler() diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index cb58e15..ea7a4f5 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -112,7 +112,7 @@ export default class ServerLaunchSection extends React.Component }) if (gameExists) await invoke('run_program', { path: config.game_install_path }) - else alert('Game not found!') + else alert('Game not found! At: ' + config.game_install_path) } async launchServer() {