From 8b17664ca4ea87fe5d699b1ae2d3df0a824a7983 Mon Sep 17 00:00:00 2001 From: d7omdev Date: Tue, 22 Oct 2024 04:45:48 +0300 Subject: [PATCH] Release v0.2.0: Improved usability with new --kill flag and repo cleanup Changes include: - Deleted unnecessary files: .SRCINFO, PKGBUILD - Updated install.sh to remove kill script lines and check command-line args. - Enhanced src/keyvis.ts with type definitions, interface definitions, and improvements to key visualizer functionality. --- .SRCINFO | 21 ----------- PKGBUILD | 81 ----------------------------------------- install.sh | 24 ++----------- src/keyvis.ts | 99 +++++++++++++++++++++++++++++++++++---------------- tsconfig.json | 2 +- uninstall.sh | 1 - 6 files changed, 72 insertions(+), 156 deletions(-) delete mode 100644 .SRCINFO delete mode 100644 PKGBUILD diff --git a/.SRCINFO b/.SRCINFO deleted file mode 100644 index 094bffd..0000000 --- a/.SRCINFO +++ /dev/null @@ -1,21 +0,0 @@ -pkgbase = keyvis - pkgdesc = A simple and lightweight keystroke visualisation tool - pkgver = 0.1.0 - pkgrel = 1 - url = https://github.com/d7omdev/keyvis - arch = any - license = MIT - makedepends = git - makedepends = bun - makedepends = npm - makedepends = typescript - depends = gjs - depends = gtk4 - depends = keyd - depends = bun - provides = keyvis - conflicts = keyvis - source = git+https://github.com/d7omdev/keyvis.git - sha256sums = SKIP - -pkgname = keyvis diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index fa9731d..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,81 +0,0 @@ -# Maintainer: D7OM - -pkgname=keyvis -pkgver=0.1.0 -pkgrel=1 -pkgdesc="A simple and lightweight keystroke visualisation tool" -arch=('any') -url="https://github.com/d7omdev/keyvis" -license=('MIT') -depends=('gjs' 'gtk4' 'keyd' 'bun') -makedepends=('git' 'bun' 'npm' 'typescript') -provides=('keyvis') -conflicts=('keyvis') -source=("git+https://github.com/d7omdev/keyvis.git") -sha256sums=('SKIP') - -pkgver() { - cd "$srcdir/keyvis" - version=$(jq -r .version package.json) - echo "$version" -} - -build() { - cd "${srcdir}/keyvis" - bun install - bun run build:app -} - -package() { - cd "${srcdir}/keyvis" - - # Create necessary directories - install -dm755 "${pkgdir}/usr/lib/keyvis" - install -dm755 "${pkgdir}/usr/bin" - - # Check if the dist directory exists and contains main.js - if [[ -f "dist/main.js" ]]; then - # Install compiled JavaScript - install -Dm644 dist/main.js "${pkgdir}/usr/lib/keyvis/main.js" - else - echo "Error: dist/main.js not found. Please ensure the build step completed successfully." - exit 1 - fi - - # Install license - install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" - - # Create and install the executable script for keyvis - cat >"${pkgdir}/usr/bin/keyvis" <"${pkgdir}/usr/bin/keyvis-kill" <temp && mv temp "${pkgdir}/usr/lib/keyvis/main.js" - chmod +x "${pkgdir}/usr/lib/keyvis/main.js" -} diff --git a/install.sh b/install.sh index 82b12aa..263d72e 100644 --- a/install.sh +++ b/install.sh @@ -6,7 +6,6 @@ set -e # Variables for paths INSTALL_DIR="/usr/local/lib/keyvis" EXECUTABLE="/usr/local/bin/keyvis" -KILL_EXECUTABLE="/usr/local/bin/keyvis-kill" MAIN_JS="dist/main.js" # Check if necessary commands are available @@ -43,32 +42,15 @@ echo "Creating the executable script..." sudo tee "$EXECUTABLE" >/dev/null <<'EOF' #!/usr/bin/env bash -gjs -m /usr/local/lib/keyvis/main.js "$@" -EOF - -# Create the executable script for keyvis-kill -echo "Creating the keyvis-kill executable script..." -sudo tee "$KILL_EXECUTABLE" >/dev/null <<'EOF' -#!/usr/bin/env bash - -# Kill existing instances of keyvis -pids=$(pgrep -f keyvis) - -if [ -n "$pids" ]; then - echo "Killing existing instances of keyvis with PIDs: $pids" - for pid in $pids; do - kill -9 "$pid" - done +if [ $# -eq 0 ]; then + gjs -m /usr/local/lib/keyvis/main.js > /dev/null 2>&1 & else - echo "No running instance of keyvis found." + gjs -m /usr/local/lib/keyvis/main.js "$@" fi - EOF # Make the scripts executable sudo chmod +x "$EXECUTABLE" -sudo chmod +x "$KILL_EXECUTABLE" echo "KeyVis has been installed successfully." echo "You can now run it using the 'keyvis' command." -echo "You can also kill the running instance using 'keyvis-kill' command." diff --git a/src/keyvis.ts b/src/keyvis.ts index 84cecbc..6ad7589 100644 --- a/src/keyvis.ts +++ b/src/keyvis.ts @@ -23,33 +23,70 @@ interface Config { MAX_KEYS: number; } -let DEBUG: boolean = false; -let ISKEYDLOG: boolean = false; - - -if (ARGV.includes('--help') || ARGV.includes('-h')) { - print(`Key Visualizer - A simple visualizer for key presses`); - print(`Usage: keyvis [OPTION]`); - print(``); - print(`Options:`); - print(` --debug, -d Enable debug mode`); - print(` --keydlog, -k Enable keyd log`); - print(` --help, -h Show this help message`); - print(` --version, -v Show version information`); - print(``); - exit(0); +type STATE = 'INFO' | 'DEBUG' | 'ERROR'; + +interface Option { + alias: string; + desc: string; } -if (ARGV.includes('--version') || ARGV.includes('-v')) { - print(`Key Visualizer 0.1.0`); +interface Options { + [key: string]: Option; +} + +const OPTIONS: Options = { + '--help': { alias: '-h', desc: 'Show this help message' }, + '--debug': { alias: '-d', desc: 'Enable debug mode' }, + '--keydlog': { alias: '-l', desc: 'Enable keyd log' }, + '--kill': { alias: '-k', desc: 'Kill all running keyvis instances' }, + '--version': { alias: '-v', desc: 'Show version information' } +}; + +function showHelp(): void { + print(''); + print('Key Visualizer - A simple visualizer for key presses'); + print('Usage: keyvis [OPTION]'); + print(''); + print('Options:'); + Object.entries(OPTIONS).forEach(([flag, { alias, desc }]) => { + print(` ${flag.padEnd(10)} ${alias.padEnd(4)} ${desc}`); + }); + print(''); exit(0); } -if (ARGV.includes('--debug') || ARGV.includes('-d')) { - DEBUG = true; +function killInstances(): void { + try { + const proc = Gio.Subprocess.new( + ['pkill', '-o', '-f', 'gjs.*keyvis'], + Gio.SubprocessFlags.STDOUT_PIPE, + ); + proc.wait(null); + const status = proc.get_status(); + status == 0 ? print('Keyvis killed successfully') : print('No keyvis instances found'); + exit(0); + } catch (e) { + logError(e instanceof Error ? e : new Error(String(e))); + exit(1); + } +} + +const hasArg = (flag: string): boolean => + ARGV.includes(flag) || ARGV.includes(OPTIONS[flag].alias); + +if (hasArg('--help')) showHelp(); + +if (hasArg('--version')) { + print('Key Visualizer 0.1.0'); + exit(0); } -if (ARGV.includes('--keydlog') || ARGV.includes('-k')) { - ISKEYDLOG = true; + +const DEBUG = hasArg('--debug'); +const ISKEYDLOG = hasArg('--keydlog'); + +if (hasArg('--keydlog') && !hasArg('--debug')) { + print('Error: --keydlog must be used with --debug'); + exit(1); } function keydlog(msg: string): void { @@ -58,8 +95,6 @@ function keydlog(msg: string): void { } } -type STATE = 'INFO' | 'DEBUG' | 'ERROR'; - function debug(state: STATE, msg: string): void { if (!state) { state = 'INFO'; @@ -75,7 +110,7 @@ function debug(state: STATE, msg: string): void { } const CONFIG: Config = { - WINDOW_WIDTH: 500, + WINDOW_WIDTH: 400, WINDOW_HEIGHT: 50, MARGIN: 20, CLEAR_TIMEOUT: 1500, @@ -136,7 +171,6 @@ function setupHyprlandRules() { 'windowrulev2 pin,class:(d7om.dev.keyvis)', 'windowrulev2 noblur,class:(d7om.dev.keyvis)', 'windowrulev2 noshadow,class:(d7om.dev.keyvis)', - 'windowrulev2 size 200 50,class:(d7om.dev.keyvis)', 'windowrulev2 animation slide bottom,class:(d7om.dev.keyvis)', 'windowrulev2 nofocus,class:(d7om.dev.keyvis)', 'windowrule move 80% 92%,^(d7om.dev.keyvis)$', @@ -276,10 +310,10 @@ const KeyVisualizer = GObject.registerClass( const css = new Gtk.CssProvider(); css.load_from_data(` window { - opacity: ${opacity}; - transition: opacity 0.5s; -} -`, -1); + opacity: ${opacity}; + transition: opacity 0.5s; + } + `, -1); const display = Gdk.Display.get_default(); if (!display) { @@ -439,7 +473,6 @@ const KeyVisualizer = GObject.registerClass( this.fadeTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, CONFIG.FADE_TIMEOUT, () => { this._setWindowOpacity(0); - this._window.hide(); this.fadeTimeout = null; return GLib.SOURCE_REMOVE; }); @@ -471,6 +504,10 @@ const KeyVisualizer = GObject.registerClass( } ); + const app = new KeyVisualizer(); -app.run([]); + +hasArg('--kill') ? killInstances() : app.run([]) + + diff --git a/tsconfig.json b/tsconfig.json index 698a517..91be436 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,6 @@ "alwaysStrict": true, }, "files": [ - "keyvis.ts", + "./src/keyvis.ts", ] } diff --git a/uninstall.sh b/uninstall.sh index 6b3b7c6..968026a 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -2,7 +2,6 @@ # Remove the executables sudo rm -f /usr/local/bin/keyvis -sudo rm -f /use/local/bin/keyvis-kill # Remove the application files sudo rm -rf /usr/local/lib/keyvis