Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launching apps using a separate client running as active user #44

Open
joshgoebel opened this issue Jun 19, 2022 · 0 comments
Open

Launching apps using a separate client running as active user #44

joshgoebel opened this issue Jun 19, 2022 · 0 comments
Labels
discussion Discussion topic documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@joshgoebel
Copy link
Owner

joshgoebel commented Jun 19, 2022

This is trivial to add to existing configs by using a named pipe for one-way communication from server to client. The named pipe just needs to be located somewhere that your active user has access to.

First, make a FIFO that we can use for comms and set it's permissions properly:

sudo mkfifo -m644 /var/run/keyszer-launcher-sub
chown keymapper:keymapper /var/run/keyszer-launcher-sub

Then our config file might look something like this:

import os
LAUNCH_PIPE = "/var/run/keyszer-launcher-sub"

fd = os.open(LAUNCH_PIPE, os.O_RDWR)
launch_fifo = os.fdopen(fd, "w")

def launch(command):
    def launcher():
        launch_fifo.write(f"LAUNCH {command}")
        launch_fifo.flush()
    return launcher

# keymaps

keymap("default", {
  K("Cmd-Plus"): launch("raise-volume"),
  K("Cmd-Minus"): launch("lower-volume"),
})

And a simple Bash launch client:

#!usr/bin/env bash
file="/var/run/keyszer-launcher-sub"

while read -r line; do
    words=( $line )
    case ${words[0]} in
    LAUNCH)
      unset 'words[0]'
      cmd=${words[@]}
      case $cmd in
        raise-volume)
          pulsemixer --change-volume +5
          ;;
        lower-volume)
          pulsemixer --change-volume -5
          ;;
      esac
      ;;
    *)
      echo "Dunno what to do with: ${words[@]}"
      ;;
    esac

    #echo -e "$line\n"
done <$file 
@joshgoebel joshgoebel added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 19, 2022
@joshgoebel joshgoebel changed the title Launching using a client running as active user Launching apps using a separate client running as active user Jun 19, 2022
@joshgoebel joshgoebel added this to the 1.0.0 milestone Jun 19, 2022
@joshgoebel joshgoebel added the discussion Discussion topic label Jun 19, 2022
joshgoebel added a commit that referenced this issue Jun 20, 2022
See #44 for how to implement launching safely and securely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion topic documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant