Implement download integrations and patches and devices detection
This commit is contained in:
parent
f60f96fa87
commit
24c668d43d
4 changed files with 186 additions and 126 deletions
|
@ -6,14 +6,14 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::io::{self};
|
||||
use tempdir::TempDir;
|
||||
|
||||
mod partial_download;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![java_version, use_revanced_cli])
|
||||
.invoke_handler(tauri::generate_handler![java_version, use_revanced_cli, get_devices])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -43,13 +43,42 @@ fn use_revanced_cli(
|
|||
device: String,
|
||||
options: Vec<String>
|
||||
) -> Result<String, String> {
|
||||
let response = match use_revanced(cli_url) {
|
||||
let response = match use_revanced(
|
||||
apk_url,
|
||||
cli_url,
|
||||
patches_url,
|
||||
integrations_url,
|
||||
device,
|
||||
options,
|
||||
) {
|
||||
Ok(response) => response,
|
||||
Err(_) => return Err("Could not create temp dir".into()),
|
||||
};
|
||||
Ok(response.into())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_devices() -> Result<Vec<String>, String> {
|
||||
let stdout = match Command::new("adb")
|
||||
.arg("devices")
|
||||
.output() {
|
||||
Ok(result) => result.stdout.clone(),
|
||||
Err(_e) => return Err("Java version not found".into()),
|
||||
};
|
||||
|
||||
let s = std::str::from_utf8(&stdout)
|
||||
.expect("Could not read output");
|
||||
|
||||
println!("{}", s);
|
||||
let devices: Vec<_> = s
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
|
||||
Ok(devices.into())
|
||||
}
|
||||
|
||||
fn download_in_dir(tmp_dir_path: &Path, target: &str, filename: &str) -> Result<String, String> {
|
||||
let fname = tmp_dir_path.join(filename);
|
||||
let dest = {
|
||||
|
@ -66,22 +95,53 @@ fn download_in_dir(tmp_dir_path: &Path, target: &str, filename: &str) -> Result<
|
|||
}
|
||||
|
||||
fn use_revanced(
|
||||
cli_url: String
|
||||
apk_url: String,
|
||||
cli_url: String,
|
||||
patches_url: String,
|
||||
integrations_url: String,
|
||||
device: String,
|
||||
options: Vec<String>
|
||||
) -> Result<String, io::Error> {
|
||||
let tmp_dir = TempDir::new("example")?;
|
||||
let file_path = tmp_dir.path().join("my-temporary-note.txt");
|
||||
let tmp_dir = TempDir::new("revanced-builder")?;
|
||||
let _download_success = download_resources(
|
||||
&tmp_dir,
|
||||
apk_url,
|
||||
cli_url,
|
||||
patches_url,
|
||||
integrations_url
|
||||
);
|
||||
|
||||
match file_path.to_str() {
|
||||
None => println!("No file path for the file"),
|
||||
Some(path) => println!("{}", path)
|
||||
}
|
||||
|
||||
let filename = "revanced_cli.jar";
|
||||
let response = match download_in_dir(tmp_dir.path(), cli_url.as_str(), filename) {
|
||||
|
||||
|
||||
tmp_dir.close()?;
|
||||
Ok("Success".into())
|
||||
}
|
||||
|
||||
fn download_resources(
|
||||
tmp_dir: &TempDir,
|
||||
apk_url: String,
|
||||
cli_url: String,
|
||||
patches_url: String,
|
||||
integrations_url: String,
|
||||
) -> Result<(), io::Error> {
|
||||
let revanced_cli_filename = "revanced_cli.jar";
|
||||
let cli_download_response = match download_in_dir(tmp_dir.path(), cli_url.as_str(), revanced_cli_filename) {
|
||||
Ok(response) => response,
|
||||
Err(e) => e,
|
||||
};
|
||||
|
||||
tmp_dir.close()?;
|
||||
Ok(response)
|
||||
|
||||
let revanced_patches_filename = "revanced_patches.jar";
|
||||
let patches_download_response = match download_in_dir(tmp_dir.path(), patches_url.as_str(), revanced_patches_filename) {
|
||||
Ok(response) => response,
|
||||
Err(e) => e,
|
||||
};
|
||||
|
||||
let revanced_integrations_filename = "integrations.apk";
|
||||
let integrations_download_response = match download_in_dir(tmp_dir.path(), integrations_url.as_str(), revanced_integrations_filename) {
|
||||
Ok(response) => response,
|
||||
Err(e) => e,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue