From 12b6593c6d819bda68624a82427a5d84f022dffb Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sun, 8 Oct 2023 19:44:56 -0700 Subject: [PATCH] feat: multi-platform vencordorion updater --- src-tauri/src/injection/injection_runner.rs | 2 +- src-tauri/src/release.rs | 18 ++-- updater/Cargo.lock | 113 ++++++++++++++++++++ updater/Cargo.toml | 1 + updater/src/main.rs | 51 ++++----- 5 files changed, 149 insertions(+), 36 deletions(-) diff --git a/src-tauri/src/injection/injection_runner.rs b/src-tauri/src/injection/injection_runner.rs index 96cff125..4660928a 100644 --- a/src-tauri/src/injection/injection_runner.rs +++ b/src-tauri/src/injection/injection_runner.rs @@ -9,7 +9,7 @@ use crate::{ static mut TAURI_INJECTED: bool = false; -fn injection_dir(win: tauri::Window) -> PathBuf { +pub fn injection_dir(win: tauri::Window) -> PathBuf { let local_config_dir = std::env::current_exe() .unwrap() .parent() diff --git a/src-tauri/src/release.rs b/src-tauri/src/release.rs index a494806a..c25deebf 100644 --- a/src-tauri/src/release.rs +++ b/src-tauri/src/release.rs @@ -1,5 +1,7 @@ use std::io::BufRead; +use crate::injection::{injection_runner::injection_dir, self}; + #[derive(serde::Serialize, serde::Deserialize)] pub struct Release { pub tag_name: String, @@ -37,10 +39,6 @@ pub async fn update_check() -> Vec { println!("Checking for updates..."); - // For now, non-windows should just return - #[cfg(not(target_os = "windows"))] - return to_update; - if maybe_latest_injection_release().await { println!("Available update for Vencordorion!"); to_update.push("vencordorion".to_string()); @@ -52,12 +50,15 @@ pub async fn update_check() -> Vec { } #[tauri::command] -pub async fn do_update(to_update: Vec) -> () { +pub async fn do_update(win: tauri::Window, to_update: Vec) -> () { let mut args = vec![]; if to_update.contains(&"vencordorion".to_string()) { + let injection_path = injection_dir(win); + let injection_path = format!("{}", injection_path.to_str().unwrap()); println!("Updating Vencordorion..."); - args.push("--vencord"); + args.push(String::from("--vencord")); + args.push(injection_path); } if args.len() > 0 { @@ -79,12 +80,7 @@ pub async fn do_update(to_update: Vec) -> () { } } -// TODO: Test platforms other than Windows -#[cfg(not(target_os = "windows"))] -pub async fn maybe_latest_injection_release() -> bool { false } - #[tauri::command] -#[cfg(target_os = "windows")] pub async fn maybe_latest_injection_release() -> bool { // See if there is a new release in Vencordorion let url = "https://api.github.com/repos/SpikeHD/Vencordorion/releases/latest"; diff --git a/updater/Cargo.lock b/updater/Cargo.lock index 034b0596..af9e22aa 100644 --- a/updater/Cargo.lock +++ b/updater/Cargo.lock @@ -17,6 +17,54 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -83,6 +131,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "core-foundation" version = "0.9.3" @@ -244,6 +338,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -732,6 +832,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "sudo" version = "0.6.0" @@ -899,6 +1005,7 @@ dependencies = [ name = "updater" version = "0.1.0" dependencies = [ + "clap", "is_elevated", "reqwest", "serde_json", @@ -916,6 +1023,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/updater/Cargo.toml b/updater/Cargo.toml index 2f952f0b..9948485e 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] serde_json = "1.0" reqwest = { version = "0.11.14", features = ["blocking"] } +clap = { version = "4.3.21", features = ["derive"] } #[cfg(not(target_os = "windows"))] sudo = "0.6.0" diff --git a/updater/src/main.rs b/updater/src/main.rs index a9aa3b95..d660e492 100644 --- a/updater/src/main.rs +++ b/updater/src/main.rs @@ -1,6 +1,22 @@ -use std::process::{Command, exit}; +use std::path::PathBuf; +use clap::{command, Parser}; + +/// If you are reading this, you probably don't need to be. Dorion updates on it's own, silly! +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +pub struct Args { + /// Update Dorion + #[arg(short = 'm', long)] + main: Option, + + /// Path to injection folder + #[arg(short = 'v', long)] + vencord: Option, +} pub fn main() { + let args = Args::parse(); + // This should always be run by Dorion itself, which means it will likely not have admin perms, so we request them before anything else #[cfg(target_os = "windows")] if is_elevated::is_elevated() == false { @@ -9,24 +25,13 @@ pub fn main() { #[cfg(not(target_os = "windows"))] sudo::escalate_if_needed().expect("Failed to escalate as root"); - - // Two args, --main and --vencord, since we may need to update one or both - let args: Vec = std::env::args().collect(); - - if args.len() < 2 { - println!("No arguments provided, exiting"); - return; - } - - let main = args.contains(&String::from("--main")); - let vencord = args.contains(&String::from("--vencord")); - - if main { + + if args.main.is_some() { update_main(); } - if vencord { - update_vencordorion(); + if args.vencord.is_some() { + update_vencordorion(PathBuf::from(args.vencord.unwrap())); } } @@ -34,7 +39,7 @@ pub fn main() { pub fn reopen_as_elevated() { let install = std::env::current_exe().unwrap(); - Command::new("powershell.exe") + std::process::Command::new("powershell.exe") .arg("powershell") .arg(format!( "-command \"&{{Start-Process -filepath '{}' -verb runas -ArgumentList \"{}\"}}\"", @@ -48,7 +53,7 @@ pub fn reopen_as_elevated() { exit(0); } -pub fn update_vencordorion() { +pub fn update_vencordorion(path: PathBuf) { let url = "https://api.github.com/repos/SpikeHD/Vencordorion/releases/latest"; let client = reqwest::blocking::Client::new(); let response = client @@ -87,13 +92,11 @@ pub fn update_vencordorion() { .unwrap(); // Write both to disk - let mut css_path = std::env::current_exe().unwrap(); - css_path.pop(); - css_path.push("injection/browser.css"); + let mut css_path = path.clone(); + css_path.push("browser.css"); - let mut js_path = std::env::current_exe().unwrap(); - js_path.pop(); - js_path.push("injection/browser.js"); + let mut js_path = path.clone(); + js_path.push("browser.js"); std::fs::write(css_path, css_response.text().unwrap()).unwrap(); std::fs::write(js_path, js_response.text().unwrap()).unwrap();