Skip to content

Commit

Permalink
Release v0.2.0: Improved usability with new --kill flag and repo cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d7omdev committed Oct 22, 2024
1 parent 760d323 commit 8b17664
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 156 deletions.
21 changes: 0 additions & 21 deletions .SRCINFO

This file was deleted.

81 changes: 0 additions & 81 deletions PKGBUILD

This file was deleted.

24 changes: 3 additions & 21 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
99 changes: 68 additions & 31 deletions src/keyvis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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)$',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -471,6 +504,10 @@ const KeyVisualizer = GObject.registerClass(
}
);


const app = new KeyVisualizer();
app.run([]);

hasArg('--kill') ? killInstances() : app.run([])



2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"alwaysStrict": true,
},
"files": [
"keyvis.ts",
"./src/keyvis.ts",
]
}
1 change: 0 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b17664

Please sign in to comment.