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::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
use std::io::{self};
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
mod partial_download;
|
mod partial_download;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
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!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,42 @@ fn use_revanced_cli(
|
||||||
device: String,
|
device: String,
|
||||||
options: Vec<String>
|
options: Vec<String>
|
||||||
) -> Result<String, 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,
|
Ok(response) => response,
|
||||||
Err(_) => return Err("Could not create temp dir".into()),
|
Err(_) => return Err("Could not create temp dir".into()),
|
||||||
};
|
};
|
||||||
Ok(response.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> {
|
fn download_in_dir(tmp_dir_path: &Path, target: &str, filename: &str) -> Result<String, String> {
|
||||||
let fname = tmp_dir_path.join(filename);
|
let fname = tmp_dir_path.join(filename);
|
||||||
let dest = {
|
let dest = {
|
||||||
|
@ -66,22 +95,53 @@ fn download_in_dir(tmp_dir_path: &Path, target: &str, filename: &str) -> Result<
|
||||||
}
|
}
|
||||||
|
|
||||||
fn use_revanced(
|
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> {
|
) -> Result<String, io::Error> {
|
||||||
let tmp_dir = TempDir::new("example")?;
|
let tmp_dir = TempDir::new("revanced-builder")?;
|
||||||
let file_path = tmp_dir.path().join("my-temporary-note.txt");
|
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)
|
|
||||||
|
tmp_dir.close()?;
|
||||||
|
Ok("Success".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
let filename = "revanced_cli.jar";
|
fn download_resources(
|
||||||
let response = match download_in_dir(tmp_dir.path(), cli_url.as_str(), filename) {
|
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,
|
Ok(response) => response,
|
||||||
Err(e) => e,
|
Err(e) => e,
|
||||||
};
|
};
|
||||||
|
|
||||||
tmp_dir.close()?;
|
let revanced_patches_filename = "revanced_patches.jar";
|
||||||
Ok(response)
|
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(())
|
||||||
}
|
}
|
130
src/App.svelte
130
src/App.svelte
|
@ -6,9 +6,21 @@ import type { Asset } from './lib/Asset';
|
||||||
import Select from './lib/Select.svelte';
|
import Select from './lib/Select.svelte';
|
||||||
|
|
||||||
let version: string = '';
|
let version: string = '';
|
||||||
|
|
||||||
|
let devices: string[];
|
||||||
|
|
||||||
let revancedCliReleases: Map<string, Release> | undefined;
|
let revancedCliReleases: Map<string, Release> | undefined;
|
||||||
let selected: string;
|
let revancedVersions: Array<Array<string>> | undefined;
|
||||||
let versions: Array<Array<string>> | undefined;
|
let selectedRevancedVersion: string;
|
||||||
|
|
||||||
|
let patchesReleases: Map<string, Release> | undefined;
|
||||||
|
let patchesVersions: Array<Array<string>> | undefined;
|
||||||
|
let selectedPatchesVersion: string;
|
||||||
|
|
||||||
|
let integrationsReleases: Map<string, Release> | undefined;
|
||||||
|
let integrationsVersions: Array<Array<string>> | undefined;
|
||||||
|
let selectedIntegrationsVersion: string;
|
||||||
|
|
||||||
const getJavaVersion = () => {
|
const getJavaVersion = () => {
|
||||||
invoke('java_version')
|
invoke('java_version')
|
||||||
.then((message: string) => {
|
.then((message: string) => {
|
||||||
|
@ -16,31 +28,10 @@ import type { Asset } from './lib/Asset';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getRevanced: () => Revanced = () => {
|
const getDevices = () => {
|
||||||
const cliUrl = revancedCliReleases
|
invoke('get_devices')
|
||||||
.get(selected)
|
.then((response: string[]) => {
|
||||||
.assets
|
devices = response;
|
||||||
.find((asset: Asset) => asset.name.match(/^revanced-cli(.*).jar$/gm))
|
|
||||||
.browser_download_url;
|
|
||||||
return ({
|
|
||||||
apkUrl: '',
|
|
||||||
cliUrl,
|
|
||||||
patchesUrl: '',
|
|
||||||
integrationsUrl: '',
|
|
||||||
device: '',
|
|
||||||
options: [],
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const useRevancedCli = () => {
|
|
||||||
const args = JSON.parse(JSON.stringify(getRevanced()));
|
|
||||||
console.log(args);
|
|
||||||
invoke('use_revanced_cli', args)
|
|
||||||
.then((success: string) => {
|
|
||||||
version = success;
|
|
||||||
})
|
|
||||||
.catch((error: string) => {
|
|
||||||
version = error;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,21 +42,96 @@ import type { Asset } from './lib/Asset';
|
||||||
revancedCliReleases = new Map(data.map(
|
revancedCliReleases = new Map(data.map(
|
||||||
(release) => [release.name, release],
|
(release) => [release.name, release],
|
||||||
));
|
));
|
||||||
versions = Array.from(revancedCliReleases).map((value) => [value[0], value[1].name]);
|
revancedVersions = Array.from(revancedCliReleases)
|
||||||
|
.map((value) => [value[0], value[1].name]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const patchesReleasesUrl = 'https://api.github.com/repos/revanced/revanced-patches/releases';
|
||||||
|
fetch(patchesReleasesUrl)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
patchesReleases = new Map(data.map(
|
||||||
|
(release) => [release.name, release],
|
||||||
|
));
|
||||||
|
patchesVersions = Array.from(patchesReleases)
|
||||||
|
.map((value) => [value[0], value[1].name]);
|
||||||
|
});
|
||||||
|
|
||||||
|
const integrationsReleasesUrl = 'https://api.github.com/repos/revanced/revanced-integrations/releases';
|
||||||
|
fetch(integrationsReleasesUrl)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
integrationsReleases = new Map(data.map(
|
||||||
|
(release) => [release.name, release],
|
||||||
|
));
|
||||||
|
integrationsVersions = Array.from(integrationsReleases)
|
||||||
|
.map((value) => [value[0], value[1].name]);
|
||||||
|
});
|
||||||
|
|
||||||
|
const getRevanced: () => Revanced = () => {
|
||||||
|
const cliUrl = revancedCliReleases
|
||||||
|
.get(selectedRevancedVersion)
|
||||||
|
.assets
|
||||||
|
.find((asset: Asset) => asset.name.match(/^revanced-cli(.*).jar$/gm))
|
||||||
|
.browser_download_url;
|
||||||
|
|
||||||
|
const patchesUrl = revancedCliReleases
|
||||||
|
.get(selectedRevancedVersion)
|
||||||
|
.assets
|
||||||
|
.find((asset: Asset) => asset.name.match(/^revanced-cli(.*).jar$/gm))
|
||||||
|
.browser_download_url;
|
||||||
|
|
||||||
|
const integrationsUrl = revancedCliReleases
|
||||||
|
.get(selectedRevancedVersion)
|
||||||
|
.assets
|
||||||
|
.find((asset: Asset) => asset.name.match(/^revanced-cli(.*).jar$/gm))
|
||||||
|
.browser_download_url;
|
||||||
|
return ({
|
||||||
|
apkUrl: '',
|
||||||
|
cliUrl,
|
||||||
|
patchesUrl,
|
||||||
|
integrationsUrl,
|
||||||
|
device: '',
|
||||||
|
options: [],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const useRevancedCli = () => {
|
||||||
|
const args = JSON.parse(JSON.stringify(getRevanced()));
|
||||||
|
invoke('use_revanced_cli', args)
|
||||||
|
.then((success: string) => {
|
||||||
|
version = success;
|
||||||
|
})
|
||||||
|
.catch((error: string) => {
|
||||||
|
version = error;
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<button on:click={getJavaVersion}>Get java version</button>
|
<button class="btn" on:click={getJavaVersion}>Get java version</button>
|
||||||
<button on:click={useRevancedCli}>Download revanced</button>
|
<button class="btn" on:click={getDevices}>Refresh device list</button>
|
||||||
|
<button class="btn" on:click={useRevancedCli}>Download revanced</button>
|
||||||
<p>{version}</p>
|
<p>{version}</p>
|
||||||
<Select
|
<Select
|
||||||
id="revanced-cli-versions"
|
id="revanced-cli-versions"
|
||||||
defaultText={'Select the revanced-cli version'}
|
defaultText={'Select the revanced-cli version'}
|
||||||
options={versions}
|
options={revancedVersions}
|
||||||
bind:selected={selected}
|
bind:selected={selectedRevancedVersion}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
id="revanced-patches-versions"
|
||||||
|
defaultText={'Select the revanced-patches version'}
|
||||||
|
options={patchesVersions}
|
||||||
|
bind:selected={selectedPatchesVersion}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
id="revanced-integrations-versions"
|
||||||
|
defaultText={'Select the revanced-integrations version'}
|
||||||
|
options={integrationsVersions}
|
||||||
|
bind:selected={selectedIntegrationsVersion}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -2,32 +2,6 @@
|
||||||
|
|
||||||
@tailwind base;
|
@tailwind base;
|
||||||
|
|
||||||
:root {
|
|
||||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
-webkit-text-size-adjust: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -36,15 +10,6 @@ body {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
max-width: 1280px;
|
max-width: 1280px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
@ -52,38 +17,17 @@ h1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
color: #213547;
|
|
||||||
background-color: #ffffff;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
|
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
.btn {
|
||||||
|
@apply py-2.5 px-5 mr-2 mb-2 text-sm font-medium
|
||||||
|
text-gray-900 focus:outline-none bg-white rounded-lg
|
||||||
|
border border-gray-200 hover:bg-gray-100
|
||||||
|
hover:text-blue-700 focus:z-10 focus:ring-4
|
||||||
|
focus:ring-gray-200 dark:focus:ring-gray-700
|
||||||
|
dark:bg-gray-800 dark:text-gray-400
|
||||||
|
dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<script lang="ts">
|
|
||||||
let count: number = 0
|
|
||||||
const increment = () => {
|
|
||||||
count += 1
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button on:click={increment}>
|
|
||||||
count is {count}
|
|
||||||
</button>
|
|
Loading…
Add table
Add a link
Reference in a new issue