Skip to content

Commit 8b17664

Browse files
committed
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.
1 parent 760d323 commit 8b17664

6 files changed

Lines changed: 72 additions & 156 deletions

File tree

.SRCINFO

Lines changed: 0 additions & 21 deletions
This file was deleted.

PKGBUILD

Lines changed: 0 additions & 81 deletions
This file was deleted.

install.sh

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set -e
66
# Variables for paths
77
INSTALL_DIR="/usr/local/lib/keyvis"
88
EXECUTABLE="/usr/local/bin/keyvis"
9-
KILL_EXECUTABLE="/usr/local/bin/keyvis-kill"
109
MAIN_JS="dist/main.js"
1110

1211
# Check if necessary commands are available
@@ -43,32 +42,15 @@ echo "Creating the executable script..."
4342
sudo tee "$EXECUTABLE" >/dev/null <<'EOF'
4443
#!/usr/bin/env bash
4544
46-
gjs -m /usr/local/lib/keyvis/main.js "$@"
47-
EOF
48-
49-
# Create the executable script for keyvis-kill
50-
echo "Creating the keyvis-kill executable script..."
51-
sudo tee "$KILL_EXECUTABLE" >/dev/null <<'EOF'
52-
#!/usr/bin/env bash
53-
54-
# Kill existing instances of keyvis
55-
pids=$(pgrep -f keyvis)
56-
57-
if [ -n "$pids" ]; then
58-
echo "Killing existing instances of keyvis with PIDs: $pids"
59-
for pid in $pids; do
60-
kill -9 "$pid"
61-
done
45+
if [ $# -eq 0 ]; then
46+
gjs -m /usr/local/lib/keyvis/main.js > /dev/null 2>&1 &
6247
else
63-
echo "No running instance of keyvis found."
48+
gjs -m /usr/local/lib/keyvis/main.js "$@"
6449
fi
65-
6650
EOF
6751

6852
# Make the scripts executable
6953
sudo chmod +x "$EXECUTABLE"
70-
sudo chmod +x "$KILL_EXECUTABLE"
7154

7255
echo "KeyVis has been installed successfully."
7356
echo "You can now run it using the 'keyvis' command."
74-
echo "You can also kill the running instance using 'keyvis-kill' command."

src/keyvis.ts

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,70 @@ interface Config {
2323
MAX_KEYS: number;
2424
}
2525

26-
let DEBUG: boolean = false;
27-
let ISKEYDLOG: boolean = false;
28-
29-
30-
if (ARGV.includes('--help') || ARGV.includes('-h')) {
31-
print(`Key Visualizer - A simple visualizer for key presses`);
32-
print(`Usage: keyvis [OPTION]`);
33-
print(``);
34-
print(`Options:`);
35-
print(` --debug, -d Enable debug mode`);
36-
print(` --keydlog, -k Enable keyd log`);
37-
print(` --help, -h Show this help message`);
38-
print(` --version, -v Show version information`);
39-
print(``);
40-
exit(0);
26+
type STATE = 'INFO' | 'DEBUG' | 'ERROR';
27+
28+
interface Option {
29+
alias: string;
30+
desc: string;
4131
}
4232

43-
if (ARGV.includes('--version') || ARGV.includes('-v')) {
44-
print(`Key Visualizer 0.1.0`);
33+
interface Options {
34+
[key: string]: Option;
35+
}
36+
37+
const OPTIONS: Options = {
38+
'--help': { alias: '-h', desc: 'Show this help message' },
39+
'--debug': { alias: '-d', desc: 'Enable debug mode' },
40+
'--keydlog': { alias: '-l', desc: 'Enable keyd log' },
41+
'--kill': { alias: '-k', desc: 'Kill all running keyvis instances' },
42+
'--version': { alias: '-v', desc: 'Show version information' }
43+
};
44+
45+
function showHelp(): void {
46+
print('');
47+
print('Key Visualizer - A simple visualizer for key presses');
48+
print('Usage: keyvis [OPTION]');
49+
print('');
50+
print('Options:');
51+
Object.entries(OPTIONS).forEach(([flag, { alias, desc }]) => {
52+
print(` ${flag.padEnd(10)} ${alias.padEnd(4)} ${desc}`);
53+
});
54+
print('');
4555
exit(0);
4656
}
4757

48-
if (ARGV.includes('--debug') || ARGV.includes('-d')) {
49-
DEBUG = true;
58+
function killInstances(): void {
59+
try {
60+
const proc = Gio.Subprocess.new(
61+
['pkill', '-o', '-f', 'gjs.*keyvis'],
62+
Gio.SubprocessFlags.STDOUT_PIPE,
63+
);
64+
proc.wait(null);
65+
const status = proc.get_status();
66+
status == 0 ? print('Keyvis killed successfully') : print('No keyvis instances found');
67+
exit(0);
68+
} catch (e) {
69+
logError(e instanceof Error ? e : new Error(String(e)));
70+
exit(1);
71+
}
72+
}
73+
74+
const hasArg = (flag: string): boolean =>
75+
ARGV.includes(flag) || ARGV.includes(OPTIONS[flag].alias);
76+
77+
if (hasArg('--help')) showHelp();
78+
79+
if (hasArg('--version')) {
80+
print('Key Visualizer 0.1.0');
81+
exit(0);
5082
}
51-
if (ARGV.includes('--keydlog') || ARGV.includes('-k')) {
52-
ISKEYDLOG = true;
83+
84+
const DEBUG = hasArg('--debug');
85+
const ISKEYDLOG = hasArg('--keydlog');
86+
87+
if (hasArg('--keydlog') && !hasArg('--debug')) {
88+
print('Error: --keydlog must be used with --debug');
89+
exit(1);
5390
}
5491

5592
function keydlog(msg: string): void {
@@ -58,8 +95,6 @@ function keydlog(msg: string): void {
5895
}
5996
}
6097

61-
type STATE = 'INFO' | 'DEBUG' | 'ERROR';
62-
6398
function debug(state: STATE, msg: string): void {
6499
if (!state) {
65100
state = 'INFO';
@@ -75,7 +110,7 @@ function debug(state: STATE, msg: string): void {
75110
}
76111

77112
const CONFIG: Config = {
78-
WINDOW_WIDTH: 500,
113+
WINDOW_WIDTH: 400,
79114
WINDOW_HEIGHT: 50,
80115
MARGIN: 20,
81116
CLEAR_TIMEOUT: 1500,
@@ -136,7 +171,6 @@ function setupHyprlandRules() {
136171
'windowrulev2 pin,class:(d7om.dev.keyvis)',
137172
'windowrulev2 noblur,class:(d7om.dev.keyvis)',
138173
'windowrulev2 noshadow,class:(d7om.dev.keyvis)',
139-
'windowrulev2 size 200 50,class:(d7om.dev.keyvis)',
140174
'windowrulev2 animation slide bottom,class:(d7om.dev.keyvis)',
141175
'windowrulev2 nofocus,class:(d7om.dev.keyvis)',
142176
'windowrule move 80% 92%,^(d7om.dev.keyvis)$',
@@ -276,10 +310,10 @@ const KeyVisualizer = GObject.registerClass(
276310
const css = new Gtk.CssProvider();
277311
css.load_from_data(`
278312
window {
279-
opacity: ${opacity};
280-
transition: opacity 0.5s;
281-
}
282-
`, -1);
313+
opacity: ${opacity};
314+
transition: opacity 0.5s;
315+
}
316+
`, -1);
283317

284318
const display = Gdk.Display.get_default();
285319
if (!display) {
@@ -439,7 +473,6 @@ const KeyVisualizer = GObject.registerClass(
439473

440474
this.fadeTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, CONFIG.FADE_TIMEOUT, () => {
441475
this._setWindowOpacity(0);
442-
this._window.hide();
443476
this.fadeTimeout = null;
444477
return GLib.SOURCE_REMOVE;
445478
});
@@ -471,6 +504,10 @@ const KeyVisualizer = GObject.registerClass(
471504
}
472505
);
473506

507+
474508
const app = new KeyVisualizer();
475-
app.run([]);
509+
510+
hasArg('--kill') ? killInstances() : app.run([])
511+
512+
476513

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"alwaysStrict": true,
1414
},
1515
"files": [
16-
"keyvis.ts",
16+
"./src/keyvis.ts",
1717
]
1818
}

uninstall.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Remove the executables
44
sudo rm -f /usr/local/bin/keyvis
5-
sudo rm -f /use/local/bin/keyvis-kill
65

76
# Remove the application files
87
sudo rm -rf /usr/local/lib/keyvis

0 commit comments

Comments
 (0)