Skip to content

Commit

Permalink
use different lock files for various users
Browse files Browse the repository at this point in the history
  • Loading branch information
nwg-piotr committed Sep 28, 2023
1 parent ff219c5 commit 47f41c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ func main() {
// Unless we are in autohide/resident mode, we probably want the same key/mouse binding to turn the dock off.
// Since v0.2 we can't just send SIGKILL if running instance found. We'll send SIGUSR1 instead.
// If it's running with `-r` or `-d` flag, it'll show the window. If not - it will die.
lockFilePath := fmt.Sprintf("%s/nwg-dock.lock", tempDir())

// Use md5-hashed $USER name to create unique lock files for multiple users
lockFilePath := fmt.Sprintf("%s/nwg-dock-%s.lock", tempDir(), md5Hash(os.Getenv("USER")))
lockFile, err := singleinstance.CreateLockFile(lockFilePath)
if err != nil {
pid, err := readTextFile(lockFilePath)
Expand Down
7 changes: 7 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"crypto/md5"
"encoding/hex"
"errors"
"fmt"
"github.com/gotk3/gotk3/gdk"
Expand Down Expand Up @@ -841,3 +843,8 @@ func isCommand(command string) bool {
cmd := strings.Fields(command)[0]
return getCommandOutput(fmt.Sprintf("command -v %s ", cmd)) != ""
}

func md5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}

0 comments on commit 47f41c9

Please sign in to comment.