From a16fe23020689dac5cfe5ca0eadb78edca4a01e4 Mon Sep 17 00:00:00 2001 From: KaKi87 Date: Sat, 27 Jan 2024 22:25:29 +0100 Subject: [PATCH] :sparkles: Add 'notifications' command --- main.js | 33 +++++++++++++++++++++++++++++++++ package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/main.js b/main.js index e276301..c53f0bf 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,7 @@ import { overrideConsole } from 'nodejs-better-console'; import Eris from 'eris'; import { Command, Argument } from 'commander'; import KeyEvent from 'keyevent.json' assert { type: 'json' }; +import AsciiTable from 'ascii-table'; import { parse } from 'shell-quote'; import { @@ -111,6 +112,38 @@ const .description('Launch Kiwi browser') .argument('', 'Website URL') .action(url => adb(`am start -a android.intent.action.VIEW -d ${url} -t text/plain com.kiwibrowser.browser`)); + program + .command('notifications') + .description('Show notification history') + .action(async () => { + const items = []; + let item; + for(let line of (await adb('dumpsys notification --noredact')).split('\n')){ + line = line.trim(); + if(line.startsWith('NotificationRecord(')) + items.push(item = { app: line.slice(35).split(' ')[0] }); + if(line.startsWith('android.title=')) + item.title = line.slice(line.indexOf('(') + 1, -1); + if(line.startsWith('android.text=')) + item.text = line.slice(line.indexOf('(') + 1, -1); + if(line.startsWith('mCreationTimeMs=')) + item.date = parseInt(line.slice(16)); + } + items.sort((a, b) => b.date - a.date); + response = { + output: new AsciiTable() + .setHeading('App', 'Time', 'Content') + .addRowMatrix(items + .sort((a, b) => b.date - a.date) + .map(item => [ + item.app, + new Date(item.date).toLocaleTimeString(), + `${item.title}${item.title.length + item.text.length < 50 ? ` ยท ${item.text}` : ''}` + ]) + ).toString(), + isRaw: true + }; + }); try { await program.parseAsync( parse(command), diff --git a/package.json b/package.json index 8e11563..caaab3d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "author": "KaKi87 ", "license": "MIT", "dependencies": { + "ascii-table": "^0.0.9", "commander": "^11.1.0", "eris": "^0.17.1", "keyevent.json": "^0.1.0", diff --git a/yarn.lock b/yarn.lock index 15beccf..7b1633c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +ascii-table@^0.0.9: + version "0.0.9" + resolved "https://registry.yarnpkg.com/ascii-table/-/ascii-table-0.0.9.tgz#06a6604d6a55d4bf41a9a47d9872d7a78da31e73" + integrity sha512-xpkr6sCDIYTPqzvjG8M3ncw1YOTaloWZOyrUmicoEifBEKzQzt+ooUpRpQ/AbOoJfO/p2ZKiyp79qHThzJDulQ== + commander@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/commander/-/commander-11.1.0.tgz#62fdce76006a68e5c1ab3314dc92e800eb83d906"