fix: default parameter for exec cmd

- change: from bypass to block.

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-07-02 13:57:45 +07:00
parent 54a5813d06
commit fbbf0c12f4
4 changed files with 28 additions and 69 deletions

View file

@ -105,9 +105,7 @@
if (instance) { if (instance) {
try { try {
// bypass // bypass
await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass', { await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass');
bypass: true
});
} catch (e) {} } catch (e) {}
let result = await adb.executeCmd( let result = await adb.executeCmd(
@ -132,9 +130,7 @@
try { try {
// bypass // bypass
await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass', { await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass');
bypass: true
});
} catch (e) {} } catch (e) {}
setTimeout(async () => { setTimeout(async () => {

View file

@ -396,8 +396,8 @@ function sanitizeAdbCommand(command: string): string {
return command; return command;
} }
export async function executeCmd(command: string, { bypass = false }) { export async function executeCmd(command: string, block: boolean = false) {
command = !bypass ? sanitizeAdbCommand(command) : command; command = block ? sanitizeAdbCommand(command) : command;
let instance = getAdbInstance(); let instance = getAdbInstance();
if (!instance) { if (!instance) {
@ -448,7 +448,7 @@ export async function executeCmd(command: string, { bypass = false }) {
export async function goToMachineHome() { export async function goToMachineHome() {
if (!getAdbInstance()) return; if (!getAdbInstance()) return;
try { try {
await executeCmd('input keyevent KEYCODE_HOME', { bypass: true }); await executeCmd('input keyevent KEYCODE_HOME');
} catch (e) { } catch (e) {
console.error('[goToMachineHome] error', e); console.error('[goToMachineHome] error', e);
} }
@ -700,14 +700,7 @@ async function connectToAndroidServer(maxRetries = 5) {
handleAdbPayload(new TextDecoder().decode(raw)); handleAdbPayload(new TextDecoder().decode(raw));
} }
}; };
// logger.info("prep post ");
// worker.postMessage({ stream }, [stream]);
} }
// const reader = stream.readable.getReader();
// logger.info('checking on writer ', writer);
adbWriter.set(writer); adbWriter.set(writer);
if (writer) { if (writer) {
@ -723,45 +716,6 @@ async function connectToAndroidServer(maxRetries = 5) {
(worker as any).postMessage({ type: 'CHUNK', payload: value }, [value.buffer]); (worker as any).postMessage({ type: 'CHUNK', payload: value }, [value.buffer]);
} }
})(); })();
// const textDecoder = new TextDecoder();
// let buffer = '';
// (async () => {
// try {
// while (true) {
// const { value, done } = await reader.read();
// if (done) break;
// // decode chunk
// buffer += textDecoder.decode(value, { stream: true });
// let lines = buffer.split('\n');
// // save potential incomplete
// buffer = lines.pop() ?? '';
// for (const line of lines) {
// if (line.trim() === '') continue;
// GlobalEventBus.emit('adb:raw-payload', line);
// handleAdbPayload(line);
// }
// // GlobalEventBus.emit('adb:raw-payload', new TextDecoder().decode(value));
// // handleAdbPayload(new TextDecoder().decode(value));
// }
// } catch (e) {
// logger.error('read error', e);
// if (isRecoverableError(e)) {
// void connectToAndroidServer();
// }
// } finally {
// adbWriter.set(null);
// addNotification('WARN:Brewing Mode T Offline ...');
// reader.cancel().catch(() => {});
// }
// })();
return; return;
} else { } else {
addNotification('WARN:Brewing Mode T unavailable'); addNotification('WARN:Brewing Mode T unavailable');

View file

@ -5,9 +5,21 @@ import { addNotification } from './noti';
// Commands that modify device state — always require explicit user confirmation. // Commands that modify device state — always require explicit user confirmation.
const DANGEROUS_COMMAND_PREFIXES = [ const DANGEROUS_COMMAND_PREFIXES = [
'rm', 'reboot', 'reboot-bootloader', 'flash', 'format', 'rm',
'mount', 'unmount', 'dd', 'mkfs', 'wipe', 'reboot',
'install', 'uninstall', 'pm ', 'am ', 'svc ', 'reboot-bootloader',
'flash',
'format',
'mount',
'unmount',
'dd',
'mkfs',
'wipe',
'install',
'uninstall',
'pm ',
'am ',
'svc '
]; ];
function isDangerousCommand(command: string): boolean { function isDangerousCommand(command: string): boolean {
@ -151,13 +163,15 @@ async function executeAndRespond(req: RemoteShellRequest) {
* Uses the simpler executeCmd() which properly captures exitCode and stderr. * Uses the simpler executeCmd() which properly captures exitCode and stderr.
*/ */
async function executeDirect(req: RemoteShellRequest) { async function executeDirect(req: RemoteShellRequest) {
const result = await executeCmd(req.commandInput); const result = await executeCmd(req.commandInput, true);
const output = result.output ?? ''; const output = result.output ?? '';
const error = result.error ?? ''; const error = result.error ?? '';
const exitCode = result.exitCode ?? (error ? 1 : 0); const exitCode = result.exitCode ?? (error ? 1 : 0);
const success = exitCode === 0; const success = exitCode === 0;
addNotification(`${success ? 'INFO' : 'ERR'}:Remote shell command ${success ? 'completed' : 'failed'}`); addNotification(
`${success ? 'INFO' : 'ERR'}:Remote shell command ${success ? 'completed' : 'failed'}`
);
remoteShellRequest.set({ remoteShellRequest.set({
...req, ...req,

View file

@ -291,14 +291,11 @@
if (instance) { if (instance) {
try { try {
// bypass // bypass
await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass', { await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass');
bypass: true
});
} catch (e) {} } catch (e) {}
let result = await adb.executeCmd( let result = await adb.executeCmd(
'am start -n com.forthvending.coffeemain/com.forthvending.coffeemain.MainActivity', 'am start -n com.forthvending.coffeemain/com.forthvending.coffeemain.MainActivity'
{ bypass: true }
); );
// if (result?.output) { // if (result?.output) {
// toast.success('Open app success!'); // toast.success('Open app success!');
@ -319,15 +316,13 @@
try { try {
// bypass // bypass
await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass', { await adb.executeCmd('echo -n hurr > /sdcard/coffeevending/ignore_pass');
bypass: true
});
} catch (e) {} } catch (e) {}
setTimeout(async () => { setTimeout(async () => {
try { try {
// bypass // bypass
await adb.executeCmd('input tap 336 795', { bypass: true }); await adb.executeCmd('input tap 336 795');
} catch (e) {} } catch (e) {}
}, 3000); }, 3000);
} }