@u4/adbkit
Version:
A Typescript client for the Android Debug Bridge.
54 lines • 1.65 kB
JavaScript
/**
* utils only used by third party
*/
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import Utils from '../../adb/utils.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default class ThirdUtils {
/**
* use to debug external apk output
* @param duplex process IO
* @param name for display only
* @returns resolve on stream closed
*/
static async dumpReadable(duplex, name) {
try {
const prefix = name + ':';
for (;;) {
await Utils.waitforReadable(duplex);
const data = await duplex.read();
if (data) {
const msg = data.toString();
console.log(prefix, msg.trim());
}
}
}
catch (e) {
// End
return;
}
}
static get resourceDir() {
return path.join(__dirname, '..', '..', '..', 'bin');
}
/**
* get fullpath from a ressource file.
* @param fileName filename
* @returns full path within the ressource folder
*/
static getResourcePath(fileName) {
const fullPath = path.join(ThirdUtils.resourceDir, fileName);
return fullPath;
}
static async getScreenSize(client) {
const str = await client.execOut('wm size', 'utf8');
const m = str.match(/(\d+)x(\d+)/);
if (!m)
throw Error('can not get device size info');
return { x: Number(m[1]), y: Number(m[2]) };
}
}
//# sourceMappingURL=ThirdUtils.js.map