Add 'notifications' command

This commit is contained in:
KaKi87 2024-01-27 22:25:29 +01:00
parent 7c50f6ef8d
commit a16fe23020
3 changed files with 39 additions and 0 deletions

33
main.js
View file

@ -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('<url>', '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),

View file

@ -6,6 +6,7 @@
"author": "KaKi87 <KaKi87@pm.me>",
"license": "MIT",
"dependencies": {
"ascii-table": "^0.0.9",
"commander": "^11.1.0",
"eris": "^0.17.1",
"keyevent.json": "^0.1.0",

View file

@ -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"