begin CLI options

This commit is contained in:
SpikeHD
2022-08-27 00:54:14 -07:00
parent d28e0a1bc8
commit 4de8a43c3a
5 changed files with 112 additions and 49 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "cultivation", "name": "cultivation",
"version": "1.0.7", "version": "1.0.8",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1.0.0-rc.5", "@tauri-apps/api": "^1.0.0-rc.5",

27
src-tauri/Cargo.lock generated
View File

@@ -713,6 +713,16 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "ctrlc"
version = "3.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173"
dependencies = [
"nix",
"winapi",
]
[[package]] [[package]]
name = "cty" name = "cty"
version = "0.2.2" version = "0.2.2"
@@ -724,6 +734,7 @@ name = "cultivation"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cc", "cc",
"ctrlc",
"duct", "duct",
"file_diff", "file_diff",
"futures-util", "futures-util",
@@ -1910,9 +1921,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.126" version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]] [[package]]
name = "libdbus-sys" name = "libdbus-sys"
@@ -2172,6 +2183,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "nix"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
dependencies = [
"autocfg",
"bitflags",
"cfg-if 1.0.0",
"libc",
]
[[package]] [[package]]
name = "nodrop" name = "nodrop"
version = "0.1.14" version = "0.1.14"

View File

@@ -62,6 +62,7 @@ regex = "1"
# other # other
file_diff = "1.0.0" file_diff = "1.0.0"
rust-ini = "0.18.0" rust-ini = "0.18.0"
ctrlc = "3.2.3"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode

View File

@@ -4,7 +4,9 @@
)] )]
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::io::Write;
use std::{collections::HashMap, sync::Mutex}; use std::{collections::HashMap, sync::Mutex};
use tauri::async_runtime::block_on;
use std::thread; use std::thread;
use structs::APIQuery; use structs::APIQuery;
@@ -23,57 +25,94 @@ mod web;
static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new())); static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new()));
fn try_flush() {
std::io::stdout().flush().unwrap_or(())
}
fn has_arg(args: &Vec<String>, arg: &str) -> bool {
args.contains(&arg.to_string())
}
async fn arg_handler(args: &Vec<String>) {
if has_arg(args, "--proxy") {
let mut pathbuf = tauri::api::path::data_dir().unwrap();
pathbuf.push("cultivation");
pathbuf.push("ca");
connect(8035, pathbuf.to_str().unwrap().to_string()).await;
}
}
fn main() { fn main() {
// Always set CWD to the location of the executable. // Always set CWD to the location of the executable.
let mut exe_path = std::env::current_exe().unwrap(); let mut exe_path = std::env::current_exe().unwrap();
exe_path.pop(); exe_path.pop();
std::env::set_current_dir(&exe_path).unwrap(); std::env::set_current_dir(&exe_path).unwrap();
tauri::Builder::default() let args: Vec<String> = std::env::args().collect();
.invoke_handler(tauri::generate_handler![
enable_process_watcher, block_on(arg_handler(&args));
connect,
disconnect, // For disabled GUI
req_get, ctrlc::set_handler(|| {
get_bg_file, std::process::exit(0);
is_game_running, })
get_theme_list, .unwrap_or(());
system_helpers::run_command,
system_helpers::run_program, if !has_arg(&args, "--no-gui") {
system_helpers::run_program_relative, tauri::Builder::default()
system_helpers::run_jar, .invoke_handler(tauri::generate_handler![
system_helpers::open_in_browser, enable_process_watcher,
system_helpers::install_location, connect,
system_helpers::is_elevated, disconnect,
system_helpers::set_migoto_target, req_get,
system_helpers::wipe_registry, get_bg_file,
proxy::set_proxy_addr, is_game_running,
proxy::generate_ca_files, get_theme_list,
unzip::unzip, system_helpers::run_command,
file_helpers::rename, system_helpers::run_program,
file_helpers::dir_create, system_helpers::run_program_relative,
file_helpers::dir_exists, system_helpers::run_jar,
file_helpers::dir_is_empty, system_helpers::open_in_browser,
file_helpers::dir_delete, system_helpers::install_location,
file_helpers::copy_file, system_helpers::is_elevated,
file_helpers::copy_file_with_new_name, system_helpers::set_migoto_target,
file_helpers::delete_file, system_helpers::wipe_registry,
file_helpers::are_files_identical, proxy::set_proxy_addr,
file_helpers::read_file, proxy::generate_ca_files,
file_helpers::write_file, unzip::unzip,
downloader::download_file, file_helpers::rename,
downloader::stop_download, file_helpers::dir_create,
lang::get_lang, file_helpers::dir_exists,
lang::get_languages, file_helpers::dir_is_empty,
web::valid_url, file_helpers::dir_delete,
web::web_get, file_helpers::copy_file,
gamebanana::get_download_links, file_helpers::copy_file_with_new_name,
gamebanana::list_submissions, file_helpers::delete_file,
gamebanana::list_mods, file_helpers::are_files_identical,
metadata_patcher::patch_metadata file_helpers::read_file,
]) file_helpers::write_file,
.run(tauri::generate_context!()) downloader::download_file,
.expect("error while running tauri application"); downloader::stop_download,
lang::get_lang,
lang::get_languages,
web::valid_url,
web::web_get,
gamebanana::get_download_links,
gamebanana::list_submissions,
gamebanana::list_mods,
metadata_patcher::patch_metadata
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
} else {
try_flush();
println!("Press enter or CTRL-C twice to quit...");
std::io::stdin().read_line(&mut String::new()).unwrap();
}
// Always disconnect upon closing the program
disconnect();
} }
#[tauri::command] #[tauri::command]

View File

@@ -7,7 +7,7 @@
}, },
"package": { "package": {
"productName": "Cultivation", "productName": "Cultivation",
"version": "1.0.7" "version": "1.0.8"
}, },
"tauri": { "tauri": {
"allowlist": { "allowlist": {