Skip to content

Commit

Permalink
remove progress bar
Browse files Browse the repository at this point in the history
todo: remove plist parsers in js
use wasm
  • Loading branch information
ChiChou committed Jun 12, 2023
1 parent 36d044a commit 0b90a56
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 138 deletions.
45 changes: 7 additions & 38 deletions bin/bagbak.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

import chalk from 'chalk';
import progress, { SingleBar } from 'cli-progress';

import { Command } from 'commander';
import { DeviceManager, getDevice, getRemoteDevice, getUsbDevice } from 'frida';
Expand Down Expand Up @@ -100,57 +99,27 @@ async function main() {
return `${val} ${unit}`;
}

/**
* @type {SingleBar | null}
*/
let bar = null;

/**
* @type {string}
*/
let current;

if (!debugEnabled()) {
job
.on('mkdir', (remote) => {
process.stdout.write('\r' + remote);
process.stdout.write(`${chalk.cyanBright('mkdir')} ${chalk.gray(remote)}\r`);
})
.on('download', (remote, size) => {
current = remote;
process.stdout.write('\r' + remote);

if (bar) bar.stop();

if (size > 2 * 1024 * 1024) {
const format = `${chalk.cyan('{bar}')} ${chalk.grey(' | {percentage}% | {downloaded}/{size}')} ${remote}`
bar = new progress.SingleBar({
format,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
});
bar.start(size, 0);
}
process.stderr.write(`${chalk.gray(remote)}\r`);
})
.on('progress', (remote, downloaded, size) => {
if (remote !== current) throw new Error('Protocol Error');
if (!bar) return;
bar.update(downloaded, {
downloaded: humanFileSize(downloaded), size: humanFileSize(size)
});
process.stdout.write(`${humanFileSize(downloaded)}/${humanFileSize(size)} ${chalk.gray(remote)}\r`);
})
.on('done', (remote) => {
if (remote !== current) throw new Error('Protocol Error');
if (!bar) return;
bar.update(bar.getTotal());
bar.stop();
bar = null;
process.stdout.write(`${chalk.green('ok')} ${chalk.gray(remote)}\r`);
})
.on('patch', (remote) => {
console.log('decrypt', remote);
console.log(chalk.redBright('decrypt'), remote);
})
}

await job.packTo(program.output);
const saved = await job.packTo(program.output);
console.log(`Saved to ${chalk.yellow(saved)}`);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class Main extends EventEmitter {
/**
*
* @param {import("fs").PathLike?} suggested path of ipa
* @return {Promise<string>} final path of ipa
*/
async packTo(suggested) {
const cwd = join(tmpdir(), 'bagbak');
Expand All @@ -156,6 +157,6 @@ export class Main extends EventEmitter {
await rename(join(cwd, ipa), ipa);
await rm(payload, { recursive: true, force: true });

console.log(`ipa saved to ${ipa}`);
return ipa;
}
}
98 changes: 0 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"bplist-creator": "^0.1.1",
"bplist-parser": "^0.3.2",
"chalk": "^4.0.0",
"cli-progress": "^3.8.2",
"commander": "^5.1.0",
"frida": "^16.0.11",
"plist": "^3.0.6",
Expand Down

0 comments on commit 0b90a56

Please sign in to comment.