Skip to content

Commit

Permalink
Add CLI flag
Browse files Browse the repository at this point in the history
  • Loading branch information
NotThorny committed Jun 19, 2023
1 parent 77a904d commit 01f773d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
args.flag("h", "help", "Print various CLI args");
args.flag("p", "proxy", "Start the proxy server");
args.flag("G", "launch-game", "Launch the game");
args.flag("o", "other-redirects", "Redirect other certain anime games");
args.flag(
"A",
"no-admin",
Expand Down Expand Up @@ -142,6 +143,10 @@ async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
pathbuf.push("cultivation");
pathbuf.push("ca");

if args.value_of("other_redirects")? {
proxy::set_redirect_more();
}

connect(8035, pathbuf.to_str().unwrap().to_string()).await;
}

Expand Down Expand Up @@ -207,6 +212,7 @@ fn main() -> Result<(), ArgsError> {
system_helpers::run_un_elevated,
proxy::set_proxy_addr,
proxy::generate_ca_files,
proxy::set_redirect_more,
release::get_latest_release,
unzip::unzip,
file_helpers::rename,
Expand Down
14 changes: 13 additions & 1 deletion src-tauri/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn shutdown_signal() {

// Global ver for getting server address.
static SERVER: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new("http://localhost:443".to_string()));
static REDIRECT_MORE: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));

#[derive(Clone)]
struct ProxyHandler;
Expand All @@ -52,6 +53,11 @@ pub fn set_proxy_addr(addr: String) {
println!("Set server to {}", SERVER.lock().unwrap());
}

#[tauri::command]
pub fn set_redirect_more() {
*REDIRECT_MORE.lock().unwrap() = true;
}

#[async_trait]
impl HttpHandler for ProxyHandler {
async fn handle_request(
Expand All @@ -61,7 +67,13 @@ impl HttpHandler for ProxyHandler {
) -> RequestOrResponse {
let uri = req.uri().to_string();

match get_config().redirect_more {
let mut more = get_config().redirect_more;

if *REDIRECT_MORE.lock().unwrap() {
more = Some(true);
}

match more {
Some(true) => {
if uri.contains("hoyoverse.com")
|| uri.contains("mihoyo.com")
Expand Down

0 comments on commit 01f773d

Please sign in to comment.