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(())
|
||||
}
|
132
src/App.svelte
132
src/App.svelte
|
@ -1,14 +1,26 @@
|
|||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import type { Asset } from './lib/Asset';
|
||||
import type { Asset } from './lib/Asset';
|
||||
import type { Release } from './lib/Release';
|
||||
import type { Revanced } from './lib/Revanced';
|
||||
import Select from './lib/Select.svelte';
|
||||
|
||||
let version: string = '';
|
||||
|
||||
let devices: string[];
|
||||
|
||||
let revancedCliReleases: Map<string, Release> | undefined;
|
||||
let selected: string;
|
||||
let versions: Array<Array<string>> | undefined;
|
||||
let revancedVersions: 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 = () => {
|
||||
invoke('java_version')
|
||||
.then((message: string) => {
|
||||
|
@ -16,31 +28,10 @@ import type { Asset } from './lib/Asset';
|
|||
});
|
||||
};
|
||||
|
||||
const getRevanced: () => Revanced = () => {
|
||||
const cliUrl = revancedCliReleases
|
||||
.get(selected)
|
||||
.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()));
|
||||
console.log(args);
|
||||
invoke('use_revanced_cli', args)
|
||||
.then((success: string) => {
|
||||
version = success;
|
||||
})
|
||||
.catch((error: string) => {
|
||||
version = error;
|
||||
const getDevices = () => {
|
||||
invoke('get_devices')
|
||||
.then((response: string[]) => {
|
||||
devices = response;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -51,21 +42,96 @@ import type { Asset } from './lib/Asset';
|
|||
revancedCliReleases = new Map(data.map(
|
||||
(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>
|
||||
|
||||
<main>
|
||||
|
||||
<div class="card">
|
||||
<button on:click={getJavaVersion}>Get java version</button>
|
||||
<button on:click={useRevancedCli}>Download revanced</button>
|
||||
<button class="btn" on:click={getJavaVersion}>Get java version</button>
|
||||
<button class="btn" on:click={getDevices}>Refresh device list</button>
|
||||
<button class="btn" on:click={useRevancedCli}>Download revanced</button>
|
||||
<p>{version}</p>
|
||||
<Select
|
||||
id="revanced-cli-versions"
|
||||
defaultText={'Select the revanced-cli version'}
|
||||
options={versions}
|
||||
bind:selected={selected}
|
||||
options={revancedVersions}
|
||||
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>
|
||||
|
||||
|
|
|
@ -2,32 +2,6 @@
|
|||
|
||||
@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 {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
|
@ -36,15 +10,6 @@ body {
|
|||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
|
@ -52,38 +17,17 @@ h1 {
|
|||
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 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