Skip to content

Commit

Permalink
Merge pull request #14 from thulasi-ram/main
Browse files Browse the repository at this point in the history
Release 0.6.0
  • Loading branch information
thulasi-ram authored Feb 20, 2024
2 parents db8d793 + 8e10684 commit 0f1f007
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 226 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ on:
workflow_dispatch:
inputs:
user_input_version:
description: 'Version /tag to target'
description: "Version /tag to target"
release:
types: [created]
types: [released, published]

jobs:
generate_updater_json:
runs-on: ubuntu-latest
steps:
- run: |
# https://dev.to/mrmike/github-action-handling-input-default-value-5f2g
USER_INPUT_VERSION=${{ github.event.inputs.user_input_version }}
echo "user_input_version=${USER_INPUT_VERSION:-"latest"}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
cache-dependency-path: 'package-lock.json'
cache: "npm"
cache-dependency-path: "package-lock.json"
- env:
GH_TOKEN: ${{ github.token }}
RELEASE_EVENT: ${{github.event.release}}
RELEASE_TAG: ${{github.event.inputs.user_input_version}}
RELEASE_EVENT: ${{ github.event.release }}
RELEASE_TAG: ${{ github.event.inputs.user_input_version }}
run: |
cd ./scripts
npm ci
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This software is in beta 🚧

Simple Android Debloater is a free and open source project to disable unwanted system apps that careers / OEMs force install in our mobile phones.
Simple Android Debloater is a free and open source project to disable unwanted system apps that carriers / OEMs force install in our mobile phones.

This is an attempt like [Universal Android Debloater](https://github.com/0x192/universal-android-debloater/) built with [Tauri](https://tauri.app/) and [Sveltekit](https://kit.svelte.dev/).

Expand Down Expand Up @@ -116,4 +116,4 @@ Run rust and node at once:

- [x] Import CSV and Bulk Enable / Disable

- [ ] SDK Compatability checks
- [ ] SDK Compatability checks
98 changes: 25 additions & 73 deletions scripts/updater_template.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
import { Octokit } from '@octokit/core';
import fs from 'fs';
import fetch from 'node-fetch';

let template_json = {
version: '0.5.0',
notes: 'Test version',
pub_date: '2023-06-22T19:25:57Z',
platforms: {
// 'darwin-x86_64': {
// signature: 'Content of app.tar.gz.sig',
// url: 'https://github.com/username/reponame/releases/download/v1.0.0/app-x86_64.app.tar.gz'
// },
// 'darwin-aarch64': {
// signature: 'Content of app.tar.gz.sig',
// url: 'https://github.com/username/reponame/releases/download/v1.0.0/app-aarch64.app.tar.gz'
// },
// 'linux-x86_64': {
// signature: 'Content of app.AppImage.tar.gz.sig',
// url: 'https://github.com/username/reponame/releases/download/v1.0.0/app-amd64.AppImage.tar.gz'
// },
// 'windows-x86_64': {
// signature: 'Content of app-setup.nsis.sig or app.msi.sig, depending on the chosen format',
// url: 'https://github.com/username/reponame/releases/download/v1.0.0/app-x64-setup.nsis.zip'
// }
}
};
import { release } from 'os';

const octokit = new Octokit({
auth: process.env.GH_TOKEN
Expand Down Expand Up @@ -52,11 +29,28 @@ async function getReleaseForTag(tag) {
return data;
}

async function getSignatureAssetContent(sig_url) {
const response = await fetch(sig_url);
let sig_content = await response.text();
async function downloadLatestJSON(release) {
let latestJsonURL = '';

for (let a of release.assets) {
if (a.name == 'latest.json') {
latestJsonURL = a.browser_download_url;
}
}

if (!latestJsonURL) {
throw new Error('latest.json is not present');
}

const response = await fetch(latestJsonURL);
let json = await response.json();

if (!json) {
console.log(response);
throw new Error('Error in response json');
}

return sig_content;
return json;
}

async function getReleaseFromEventOrTag() {
Expand Down Expand Up @@ -107,52 +101,10 @@ async function getReleaseFromEventOrTag() {
};
}

let version = release.tag;
if (version.charAt(0) === 'v') {
version = version.substring(1); // remove first letter
}

let asset_url_map = release.assets.reduce((map, a) => {
map[a.name] = a.browser_download_url;
return map;
}, {});

let extensions = {
linux: 'amd64.AppImage.tar.gz',
darwin: '.app.tar.gz',
windows: 'x64-setup.nsis.zip'
};

let platform_sig_template = {};

for (let [platform, ext] of Object.entries(extensions)) {
for (let [name, url] of Object.entries(asset_url_map)) {
if (name.endsWith(ext)) {
let sig_url = asset_url_map[`${name}.sig`];
let sig_content = await getSignatureAssetContent(sig_url);

platform_sig_template[`${platform}-x86_64`] = {
signature: sig_content,
url: url
};

if (platform == 'darwin') {
// apple silicon chips
platform_sig_template[`${platform}-aarch64`] = {
signature: sig_content,
url: url
};
}
}
}
}

template_json.version = version;
template_json.notes = release.body;
template_json.pub_date = release.published_at;
template_json.platforms = platform_sig_template;
let content = await downloadLatestJSON(release);
content.notes = release.body;

fs.writeFile('sad_updater.json', JSON.stringify(template_json), 'utf8', function (err) {
fs.writeFile('sad_updater.json', JSON.stringify(content), 'utf8', function (err) {
if (err) throw err;
console.log('Dumped sad_updater.json');
});
Expand Down
138 changes: 85 additions & 53 deletions src-tauri/src/adb_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,33 @@ use std::os::windows::process::CommandExt;

use log::info;

pub trait ADBCommand {
pub trait ADBCommand: Sized {
fn execute(&self) -> Result<String, ADBError>;
fn arg<S: AsRef<str>>(self, arg: S) -> Self;
fn args<I, S>(self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let mut s1 = self;
for arg in args {
s1 = s1.arg(arg);
}
s1
}

fn arg_prepend<S: AsRef<str>>(self, arg: S) -> Self;
fn args_prepend<I, S>(self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let mut s1 = self;
for arg in args {
s1 = s1.arg_prepend(arg);
}
s1
}
}

#[derive(Debug, thiserror::Error)]
Expand All @@ -15,65 +40,50 @@ pub enum ADBError {
Unknown(String),
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ADBRaw {
adb_path: String,
sub_commands: Vec<String>,
cmd_str: String,
argsv: Vec<String>,
}

impl ADBRaw {
pub fn new(adb_path: String, value: Vec<String>) -> Self {
pub fn new(adb_path: String) -> Self {
let mut cmd_str = "adb";
if !adb_path.is_empty() {
cmd_str = adb_path.as_str();
}
Self {
adb_path: adb_path,
sub_commands: value,
cmd_str: cmd_str.to_string(),
argsv: vec![],
}
}
}

#[derive(Debug, Clone)]
pub struct ADBShell {
adb_path: String,
sub_commands: Vec<String>,
device_id: String,
}

impl ADBShell {
pub fn new(adb_path: String) -> Self {
Self {
adb_path: adb_path,
sub_commands: vec![],
device_id: String::from(""),
}
}
impl ADBCommand for ADBRaw {
fn arg<S: AsRef<str>>(self, arg: S) -> Self {
// https://users.rust-lang.org/t/best-way-to-clone-and-append-a-single-element/68675/2

pub fn for_device(mut self, device_id: String) -> Self {
self.device_id = device_id;
return self;
let mut s1 = self;
s1.argsv.push(arg.as_ref().to_owned());
return s1;
}

pub fn with_commands(mut self, sub_commands: &[&str]) -> Self {
self.sub_commands = sub_commands.iter().map(|s| String::from(*s)).collect();
return self;
fn arg_prepend<S: AsRef<str>>(self, arg: S) -> Self {
let mut s1 = self;
s1.argsv.insert(0, arg.as_ref().to_owned());
return s1;
}
}

impl ADBCommand for ADBRaw {
fn execute(&self) -> Result<String, ADBError> {
let mut command = Command::new(self.cmd_str.to_owned());
command.args(self.argsv.to_vec());

let mut cmd_str = "adb";
if !self.adb_path.is_empty() {
cmd_str = self.adb_path.as_str();
}

let mut command = Command::new(cmd_str);

// https://stackoverflow.com/a/38186733/6323666
let args = self
.sub_commands
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>();
command.args(args);
// let args = self
// .sub_commands
// .iter()
// .map(|s| s.as_str())
// .collect::<Vec<&str>>();
// command.args(args);

info!("command {:?}", command);

Expand Down Expand Up @@ -107,17 +117,39 @@ impl ADBCommand for ADBRaw {
}
}

#[derive(Debug, Clone)]
pub struct ADBShell {
adb_raw: ADBRaw,
}

impl ADBShell {
pub fn new(adb_path: String) -> Self {
let adbr = ADBRaw::new(adb_path).arg("shell");
Self { adb_raw: adbr }
}
}

impl ADBCommand for ADBShell {
fn execute(&self) -> Result<String, ADBError> {
let mut sub_commands_with_shell: Vec<String> = vec![String::from("shell")];
fn arg<S: AsRef<str>>(self, arg: S) -> Self {
let mut s1 = self;
s1.adb_raw = s1.adb_raw.arg(arg.as_ref());
return s1;
}

if !String::is_empty(&self.device_id.to_owned()) {
sub_commands_with_shell.insert(0, String::from("-s"));
sub_commands_with_shell.insert(1, self.device_id.to_owned());
}
fn arg_prepend<S: AsRef<str>>(self, arg: S) -> Self {
let mut s1 = self;
s1.adb_raw = s1.adb_raw.arg_prepend(arg.as_ref());
return s1;
}

sub_commands_with_shell.extend(self.sub_commands.to_owned());
let adb_raw = ADBRaw::new(self.adb_path.to_owned(), sub_commands_with_shell);
return adb_raw.execute();
fn execute(&self) -> Result<String, ADBError> {
return self.adb_raw.execute();
}
}

pub fn for_device<'a, T: ADBCommand + Clone>(abdc: &'a T, device_id: String) -> T {
// ideally its -s <device_id> but we send in reverse so prepend works properly
return abdc
.clone()
.args_prepend(vec!["-s", &device_id].into_iter().rev());
}
11 changes: 7 additions & 4 deletions src-tauri/src/devices.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::adb_cmd::{ADBCommand, ADBRaw, ADBShell};
use crate::adb_cmd::{self, ADBCommand, ADBRaw, ADBShell};
use anyhow::{anyhow, Error, Result};
use core::result::Result::Ok;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -61,7 +61,9 @@ pub struct ADBTerminalImpl {

impl ADBTerminalImpl {
pub fn list_devices(&self) -> Result<Vec<Device>> {
let res = ADBRaw::new(self.adb_path.to_owned(), vec![String::from("devices")]).execute();
let res = ADBRaw::new(self.adb_path.to_owned())
.arg("devices")
.execute();
match res {
Err(e) => {
return Err(e.into());
Expand Down Expand Up @@ -101,8 +103,9 @@ impl ADBTerminalImpl {
return Err(e);
}
Ok(d) => {
let shell_cmd: ADBShell = ADBShell::new(self.adb_path.to_owned()).for_device(d.id.to_owned());
let res = shell_cmd.with_commands(&["getprop"]).execute();
let shell_cmd: ADBShell =
adb_cmd::for_device(&ADBShell::new(self.adb_path.to_owned()), d.id.to_owned());
let res = shell_cmd.arg("getprop").execute();
match res {
Err(e) => {
return Err(e.into());
Expand Down
Loading

0 comments on commit 0f1f007

Please sign in to comment.