Biont / sway-launcher-desktop

TUI Application launcher with Desktop Entry support. Made for SwayWM, but runs anywhere
GNU General Public License v3.0
613 stars 29 forks source link

Force only single launcher instance #9

Closed asahaf closed 3 years ago

asahaf commented 4 years ago

We can force only single launcher instance by using lock file like so at line 143:

LOCK_FILE=/tmp/sway_launcher_desktop.lock
[ -f "$LOCK_FILE" ] && exit 1
touch "$LOCK_FILE"
FZFPIPE=$(mktemp)
PIDFILE=$(mktemp)
trap 'rm "$FZFPIPE" "$PIDFILE" "$LOCK_FILE"' EXIT INT

To make is easy to switch between single/multiple instances, we can have a flag at the top of the script

Biont commented 4 years ago

I totally get where you're coming from and I've been thinking about this myself, since I use a couple of shortcuts that spawn basic TUI programs and I could use a solution to make sure only one instance of each can be on screen. But this is also why I don't think this should be solved within the script when it would be easy enough to craft a wrapper script that takes arbitrary commands as parameters and makes sure the command can only run once.

However, such a wrapper script would be a nice addition to the readme.

asahaf commented 4 years ago

You're right, it would be cleaner with a wrapper as this script might be used in different in setups where forced single instance is not desired.

asahaf commented 4 years ago

I force single instance this way on sway config:

set $MENU_LOCK_DIR /tmp/sway.launcher.desktop.lock
set $menu mkdir "$MENU_LOCK_DIR" && trap 'rmdir "$MENU_LOCK_DIR"' EXIT INT && TERMINAL_COMMAND="$term -e " $term --class $term-sway-launcher -e <path-to>/sway-launcher-desktop.sh