Skip to content

Commit

Permalink
fix(win): i hate windows so so so much
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Oct 9, 2023
1 parent a3e1341 commit bf8c376
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
31 changes: 15 additions & 16 deletions src-tauri/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,29 @@ pub async fn update_check() -> Vec<String> {

#[tauri::command]
pub async fn do_update(win: tauri::Window, to_update: Vec<String>) {
let mut args = vec![];
let updater_path = updater_dir(&win);
let mut updater = std::process::Command::new(updater_path);

if to_update.contains(&"vencordorion".to_string()) {
let injection_path = injection_dir(&win);
let injection_path = injection_path.to_str().unwrap().to_string();
println!("Updating Vencordorion...");
args.push(String::from("--vencord"));
args.push(injection_path);
}

if !args.is_empty() {
// Run the updater as a seperate process
let updater_path = updater_dir(&win);
let mut updater = std::process::Command::new(updater_path);
updater.arg(String::from("--vencord"));
updater.arg(
injection_path
.into_os_string()
.into_string()
.unwrap()
.replace("\\", "/")
);
}

for arg in args {
updater.arg(arg);
}
let mut process = updater.spawn().unwrap();

let mut process = updater.spawn().unwrap();
// Wait for the updater to finish
process.wait().unwrap();

// Wait for the updater to finish
process.wait().unwrap();
}
win.emit("update_complete", {}).unwrap();
}

#[tauri::command]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"html/notification.html",
"html/extra.css",
"icons/icon*.ico",
"updater"
"updater*"
],
"shortDescription": "",
"targets": "all",
Expand Down
29 changes: 16 additions & 13 deletions updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,34 @@ pub fn needs_to_elevate(path: PathBuf) -> bool {
path2.pop();
path2.push("browser.js");

let css_exists = std::fs::metadata(path).is_ok();
let js_exists = std::fs::metadata(path2).is_ok();
let css_meta = std::fs::metadata(path).is_ok();
let js_meta = std::fs::metadata(path2).is_ok();

println!("Permissions for CSS: {}", css_exists);
println!("Permissions for JS: {}", js_exists);
println!("Permissions for CSS: {}", css_meta);
println!("Permissions for JS: {}", js_meta);

return css_exists && js_exists;
return !css_meta || !js_meta;
}

#[cfg(target_os = "windows")]
pub fn reopen_as_elevated() {
let install = std::env::current_exe().unwrap();

std::process::Command::new("powershell.exe")
.arg("powershell")
.arg(format!(
"-command \"&{{Start-Process -filepath '{}' -verb runas -ArgumentList \"{}\"}}\"",
install.to_str().unwrap(),
std::process::Command::new("powershell")
.arg("Start-Process")
.arg("-FilePath")
.arg(install.to_str().unwrap())
.arg("-Verb")
.arg("runas")
.arg("-ArgumentList")
.arg(
// Grab all args except first
std::env::args().skip(1).collect::<Vec<String>>().join(" ")
))
std::env::args().skip(1).collect::<Vec<String>>().join(",")
)
.spawn()
.expect("Error starting exec as admin");

exit(0);
std::process::exit(0);
}

pub fn update_vencordorion(path: PathBuf) {
Expand Down

0 comments on commit bf8c376

Please sign in to comment.