From b16104963ca9d89e1e8a463b3de6d523c5eb789f Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 2 Jun 2022 19:47:55 -0400 Subject: [PATCH 1/8] Use the Grasscutter API to get the background file --- src/ui/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 7312d53..08724c6 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -45,7 +45,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: 'https://api.grasscutters.xyz/content/bgfile', } listen('lang_error', (payload) => { From 2007157e4c9eaa1398cc38e7a2dd8c74674a55f9 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:00:25 -0400 Subject: [PATCH 2/8] Add dependencies for elevation --- src-tauri/Cargo.lock | 94 ++++++++++++++++++++++++++++++++++++++++++++ src-tauri/Cargo.toml | 8 +++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 4749215..d51bb42 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -207,6 +216,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.0" @@ -722,11 +746,13 @@ dependencies = [ "futures-util", "http", "hudsucker", + "is_elevated", "lazy_static", "open", "rcgen", "registry", "reqwest", + "runas", "rustls-pemfile", "serde", "serde_json", @@ -974,6 +1000,15 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -1288,6 +1323,12 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + [[package]] name = "gio" version = "0.15.11" @@ -1773,6 +1814,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +[[package]] +name = "is_elevated" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5299060ff5db63e788015dcb9525ad9b84f4fd9717ed2cbdeba5018cbf42f9b5" +dependencies = [ + "winapi", +] + [[package]] name = "itertools" version = "0.10.3" @@ -2041,6 +2091,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "minisign-verify" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881" + [[package]] name = "miniz_oxide" version = "0.5.1" @@ -2320,6 +2376,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.28.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +dependencies = [ + "memchr", +] + [[package]] name = "oid-registry" version = "0.4.0" @@ -3108,6 +3173,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "runas" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a620b0994a180cdfa25c0439e6d58c0628272571501880d626ffff58e96a0799" +dependencies = [ + "cc", + "which", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustc_version" version = "0.3.3" @@ -3779,6 +3860,7 @@ checksum = "a34cef4a0ebee0230baaa319b1709c4336f4add550149d2b005a9a5dc5d33617" dependencies = [ "anyhow", "attohttpc", + "base64", "bincode", "cocoa", "dirs-next", @@ -3792,6 +3874,7 @@ dependencies = [ "heck 0.4.0", "http", "ignore", + "minisign-verify", "notify-rust", "objc", "once_cell", @@ -3823,6 +3906,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "windows 0.30.0", + "zip 0.6.2", ] [[package]] @@ -4606,6 +4690,16 @@ dependencies = [ "cc", ] +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "failure", + "libc", +] + [[package]] name = "wildmatch" version = "2.1.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ebcda71..78b766f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,9 +16,9 @@ tauri-build = { version = "1.0.0-rc.8", features = [] } [dependencies] serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.0.0-rc.9", features = ["api-all"] } +tauri = { version = "1.0.0-rc.9", features = ["api-all", "updater"] } -# For process info +# Access system process info. sysinfo = "0.23.12" # ZIP-archive library. @@ -38,6 +38,10 @@ open = "2.1.2" serde_json = "1" base64 = "0.13.0" +# System process elevation. +is_elevated = "0.1.2" +runas = "0.2.1" + # Dependencies for the HTTP(S) proxy. http = "0.2" hudsucker = "0.17.2" From 0b24a2bb22cd7a263b1f4f128d1aa9a6e5803601 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:01:13 -0400 Subject: [PATCH 3/8] Elevation check & comment fixes --- src-tauri/src/main.rs | 16 +++++++++------- src-tauri/src/system_helpers.rs | 5 +++++ src/ui/{Test.tsx => Debug.tsx} | 13 +++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) rename src/ui/{Test.tsx => Debug.tsx} (70%) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0f1aae1..1cbc020 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -27,9 +27,10 @@ lazy_static! { } fn main() { + // Start the game process watcher. process_watcher(); - // Make BG folder if it doesn't exist + // 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(); @@ -51,6 +52,7 @@ fn main() { system_helpers::open_in_browser, system_helpers::copy_file, system_helpers::install_location, + system_helpers::is_elevated, proxy::set_proxy_addr, proxy::generate_ca_files, unzip::unzip, @@ -73,17 +75,17 @@ fn process_watcher() { // Start a thread so as to not block the main thread. thread::spawn(|| { - let mut s = System::new_all(); + let mut system = System::new_all(); loop { // Refresh system info - s.refresh_all(); + system.refresh_all(); // Grab the game process name let proc = WATCH_GAME_PROCESS.lock().unwrap().to_string(); if !&proc.is_empty() { - let proc_with_name = s.processes_by_exact_name(&proc); + let proc_with_name = system.processes_by_exact_name(&proc); let mut exists = false; for _p in proc_with_name { @@ -107,7 +109,7 @@ fn is_game_running() -> bool { // Grab the game process name let proc = WATCH_GAME_PROCESS.lock().unwrap().to_string(); - return !&proc.is_empty(); + return !proc.is_empty(); } #[tauri::command] @@ -146,8 +148,8 @@ async fn req_get(url: String) -> String { } #[tauri::command] -async fn get_theme_list(dataDir: String) -> Vec> { - let theme_loc = format!("{}/themes", dataDir); +async fn get_theme_list(data_dir: String) -> Vec> { + let theme_loc = format!("{}/themes", data_dir); // Ensure folder exists if !std::path::Path::new(&theme_loc).exists() { diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 5d608c2..56f7843 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -85,4 +85,9 @@ pub fn install_location() -> String { exe_path.pop(); return exe_path.to_str().unwrap().to_string(); +} + +#[tauri::command] +pub fn is_elevated() -> bool { + return is_elevated::is_elevated(); } \ No newline at end of file diff --git a/src/ui/Test.tsx b/src/ui/Debug.tsx similarity index 70% rename from src/ui/Test.tsx rename to src/ui/Debug.tsx index dd01349..845574e 100644 --- a/src/ui/Test.tsx +++ b/src/ui/Debug.tsx @@ -18,11 +18,19 @@ async function generateCertificates() { await invoke('generate_ca_files', { path: await dataDir() + '\\cultivation' }) } +async function generateCertInfo() { + console.log({ + certificatePath: await dataDir() + '\\cultivation\\ca', + isAdmin: await invoke('is_elevated') + }) + alert('check your dev console and send that in #cultivation') +} + function none() { alert('none') } -class Test extends React.Component{ +class Debug extends React.Component{ render() { return (
@@ -30,9 +38,10 @@ class Test extends React.Component{ +
) } } -export default Test \ No newline at end of file +export default Debug \ No newline at end of file From 9ef816aad8b8f3b1f9bd123e8396512b8fdc6b8a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:01:57 -0400 Subject: [PATCH 4/8] Add descriptions, updater, bundle language with installer, and WiX config --- src-tauri/resources/wix.wxs | 7 +++++++ src-tauri/tauri.conf.json | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src-tauri/resources/wix.wxs diff --git a/src-tauri/resources/wix.wxs b/src-tauri/resources/wix.wxs new file mode 100644 index 0000000..b6f12ea --- /dev/null +++ b/src-tauri/resources/wix.wxs @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 38087a7..7aa97df 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -31,7 +31,7 @@ }, "bundle": { "active": true, - "category": "DeveloperTool", + "category": "Game", "copyright": "", "deb": { "depends": [] @@ -45,7 +45,8 @@ "icons/icon.ico" ], "identifier": "xyz.grasscutters", - "longDescription": "", + "shortDescription": "A game launcher.", + "longDescription": "A launcher for a certain anime game that proxies all related game traffic to external servers.", "macOS": { "entitlements": null, "exceptionDomain": "", @@ -53,20 +54,30 @@ "providerShortName": null, "signingIdentity": null }, - "resources": [], - "shortDescription": "", + "resources": [ + "lang/*.json" + ], "targets": "all", "windows": { + "allowDowngrades": false, "certificateThumbprint": null, "digestAlgorithm": "sha256", - "timestampUrl": "" + "timestampUrl": "", + "wix": { + "fragmentPaths": ["resources/wix.wxs"] + } } }, "security": { "csp": "default-src 'self' https://asset.localhost; img-src 'self'; img-src https://* asset: https://asset.localhost" }, "updater": { - "active": false + "active": false, + "dialog": true, + "endpoints": [ + "https://api.grasscutters.xyz/cultivation/update?version={{current_version}}" + ], + "pubkey": "" }, "windows": [ { From c571e23726b663546b0d0e908ccda4c2defb84fb Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:02:22 -0400 Subject: [PATCH 5/8] Change `dataDir` to `data_dir` to match Rust naming scheme --- src/utils/themes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/themes.ts b/src/utils/themes.ts index e0c3309..24f9d44 100644 --- a/src/utils/themes.ts +++ b/src/utils/themes.ts @@ -39,7 +39,7 @@ const defaultTheme = { export async function getThemeList() { // Do some invoke to backend to get the theme list const themes = await invoke('get_theme_list', { - dataDir: `${await dataDir()}/cultivation` + data_dir: `${await dataDir()}/cultivation` }) as BackendThemeList[] const list: ThemeList[] = [ // ALWAYS include default theme From 41138f9fbd4ae1b3b25cb29134e3bd130c545a6a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:02:41 -0400 Subject: [PATCH 6/8] Remove unnecessary `px` suffixes --- src/ui/components/ServerLaunchSection.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/components/ServerLaunchSection.css b/src/ui/components/ServerLaunchSection.css index 80351e2..18c19a4 100644 --- a/src/ui/components/ServerLaunchSection.css +++ b/src/ui/components/ServerLaunchSection.css @@ -19,7 +19,7 @@ #playButton .BigButton { height: 100%; - box-shadow: 0px 0px 5px 3px rgba(0, 0, 0, 0.2); + box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.2); } #serverControls { @@ -39,7 +39,7 @@ #serverControls .CheckboxDisplay { margin-right: 6px; - box-shadow: 0px 0px 5px 4px rgba(0, 0, 0, 0.2); + box-shadow: 0 0 5px 4px rgba(0, 0, 0, 0.2); } #serverControls .Checkbox label { @@ -80,7 +80,7 @@ border-radius: 6px; height: 18px; - box-shadow: 0px 0px 5px 3px rgba(0, 0, 0, 0.2); + box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.2); } .ServerConfig .TextInputWrapper { From 68f609893c967253c7330fc8f8aaaadd590ad648 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:03:08 -0400 Subject: [PATCH 7/8] Install certificate into the user's root instead of the system's root --- src-tauri/src/proxy.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index ff90811..164e001 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -164,7 +164,7 @@ pub fn generate_ca_files(path: &str) { params.key_usages = vec![ KeyUsagePurpose::DigitalSignature, KeyUsagePurpose::KeyCertSign, - KeyUsagePurpose::CrlSign, + KeyUsagePurpose::CrlSign ]; // Create certificate. @@ -203,7 +203,7 @@ pub fn generate_ca_files(path: &str) { */ pub fn install_ca_files(path: &str) { if cfg!(target_os = "windows") { - run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\cert.crt", path).to_string()); + run_command(format!("certutil -user -addstore \"Root\" {}\\ca\\cert.crt", path).to_string()); } else { run_command(format!("security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {}/ca/cert.crt", path).to_string()); } From 0ff75f629c529b61d64e3668279cc8dc63a6c3c2 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 6 Jun 2022 00:03:24 -0400 Subject: [PATCH 8/8] Remove unneeded import --- src/ui/App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 581a48f..13a812a 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -18,7 +18,7 @@ import Game from './components/menu/Game' import RightBar from './components/RightBar' import { getConfigOption, setConfigOption } from '../utils/configuration' import { invoke } from '@tauri-apps/api' -import { appDir, dataDir } from '@tauri-apps/api/path' +import { dataDir } from '@tauri-apps/api/path' import { appWindow } from '@tauri-apps/api/window' import { convertFileSrc } from '@tauri-apps/api/tauri' import { getTheme, loadTheme } from '../utils/themes' @@ -87,7 +87,7 @@ class App extends React.Component { const theme = await getConfigOption('theme') if (theme && theme !== 'default') { const themeObj = await getTheme(theme) - loadTheme(themeObj, document) + await loadTheme(themeObj, document) } if(!custom_bg || !/png|jpg|jpeg$/.test(custom_bg)) { @@ -103,7 +103,7 @@ class App extends React.Component { }, this.forceUpdate) } } else { - const isUrl = /^(?:http(s)?:\/\/)/gm.test(custom_bg) + const isUrl = /^http(s)?:\/\//gm.test(custom_bg) if (!isUrl) { const isValid = await invoke('dir_exists', {