From f60f96fa8727d47678fb702cdad38dbd32348e82 Mon Sep 17 00:00:00 2001 From: Hydroxycarbamide Date: Sun, 4 Sep 2022 16:39:56 +0200 Subject: [PATCH] Added selector for revanced cli --- .eslintrc.cjs | 1 + src-tauri/src/main.rs | 59 ++++++++++++------------------ src/App.svelte | 83 +++++++++++++++++++++++-------------------- src/lib/Asset.ts | 4 +++ src/lib/Release.ts | 6 ++++ src/lib/Revanced.ts | 8 +++++ src/lib/Select.svelte | 25 +++++++++++++ 7 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 src/lib/Asset.ts create mode 100644 src/lib/Release.ts create mode 100644 src/lib/Revanced.ts create mode 100644 src/lib/Select.svelte diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 089e574..1708c93 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -25,6 +25,7 @@ module.exports = { } ], rules: { + 'import/no-mutable-exports': 'off', // to dismiss `export let prop = 'default'` warning }, settings: { 'svelte3/typescript': () => require('typescript'), diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index af5257d..17dcb37 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,21 +3,17 @@ windows_subsystem = "windows" )] -use std::io::Cursor; -use std::path::PathBuf; -use std::io::copy; use std::path::Path; use std::process::Command; use std::fs::File; use std::io::{self, Write}; use tempdir::TempDir; -use reqwest; mod partial_download; fn main() { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![java_version, download_revanced_cli]) + .invoke_handler(tauri::generate_handler![java_version, use_revanced_cli]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } @@ -39,22 +35,23 @@ fn java_version() -> Result { } #[tauri::command] -fn download_revanced_cli() -> Result { - let response = match download_revanced_cli_in_tmp() { +fn use_revanced_cli( + apk_url: String, + cli_url: String, + patches_url: String, + integrations_url: String, + device: String, + options: Vec +) -> Result { + let response = match use_revanced(cli_url) { Ok(response) => response, Err(_) => return Err("Could not create temp dir".into()), }; Ok(response.into()) } -fn download_revanced_cli_somewhere(tmp_dir_path: &Path) -> Result { - let target = "https://github.com/revanced/revanced-cli/releases/download/v2.9.5/revanced-cli-2.9.5-all.jar"; - - let fname = tmp_dir_path.join("revanced_cli.jar"); - let path = fname.clone(); - let string_path = path - .to_str() - .expect("Could not read path"); +fn download_in_dir(tmp_dir_path: &Path, target: &str, filename: &str) -> Result { + let fname = tmp_dir_path.join(filename); let dest = { println!("will be located under: '{:?}'", fname); match File::create(fname) { @@ -62,41 +59,29 @@ fn download_revanced_cli_somewhere(tmp_dir_path: &Path) -> Result return Err("Could not create file".to_owned()), } }; - partial_download::download(target, &dest).; - - let stdout = match Command::new("java") - .arg("-jar") - .arg(string_path) - .arg("--version") - .output() { - Ok(result) => result.stdout.clone(), - Err(_e) => return Err("revanced-cli version not found".into()), - }; - - let s = std::str::from_utf8(&stdout) - .expect("Could not read output"); - - println!("{}", s); - Ok(s.into()) + partial_download::download(target, &dest) + .expect("Failed to download"); + + Ok(format!("Success downloading {}", target)) } -fn download_revanced_cli_in_tmp() -> Result { +fn use_revanced( + cli_url: String +) -> Result { let tmp_dir = TempDir::new("example")?; let file_path = tmp_dir.path().join("my-temporary-note.txt"); - let mut tmp_file = File::create(file_path.clone())?; - writeln!(tmp_file, "Brian was here. Briefly."); match file_path.to_str() { None => println!("No file path for the file"), Some(path) => println!("{}", path) } - let response = match download_revanced_cli_somewhere(tmp_dir.path()) { + let filename = "revanced_cli.jar"; + let response = match download_in_dir(tmp_dir.path(), cli_url.as_str(), filename) { Ok(response) => response, - Err(errmsg) => panic!("{}", errmsg), + Err(e) => e, }; - drop(tmp_file); tmp_dir.close()?; Ok(response) } \ No newline at end of file diff --git a/src/App.svelte b/src/App.svelte index 3398adf..f104d39 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,9 +1,14 @@
- -

Vite + Svelte

- - +

{version}

+ + + {#if options !== undefined} + {#each options as [key, value]} + + {/each} + {/if} + \ No newline at end of file