Skip to content

Commit

Permalink
bring back CommFound from the dead for roblox autokill
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Oct 13, 2023
1 parent 9a08887 commit 5deb2e8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
27 changes: 24 additions & 3 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/vinegarhq/vinegar/internal/splash"
"github.com/vinegarhq/vinegar/roblox"
"github.com/vinegarhq/vinegar/roblox/bootstrapper"
"github.com/vinegarhq/vinegar/util"
"github.com/vinegarhq/vinegar/wine"
"github.com/vinegarhq/vinegar/wine/dxvk"
)
Expand Down Expand Up @@ -56,6 +57,7 @@ func NewBinary(bt roblox.BinaryType, cfg *config.Config, pfx *wine.Prefix) Binar
}

func (b *Binary) Run(args ...string) error {
exe := b.Type.Executable()
cmd, err := b.Command(args...)
if err != nil {
return err
Expand All @@ -64,15 +66,34 @@ func (b *Binary) Run(args ...string) error {
log.Printf("Launching %s", b.Name)
b.Splash.Message("Launching " + b.Alias)

kill := true

// If roblox is already running, don't kill wineprefix, even if
// auto kill prefix is enabled
if util.CommFound("Roblox") {
log.Println("Roblox is already running, not killing wineprefix after exit")
kill = false
}

// Launches into foreground
if err := cmd.Start(); err != nil {
return err
}

time.Sleep(1 * time.Second)
time.Sleep(2500 * time.Millisecond)
b.Splash.Close()
cmd.Wait()

if b.Config.AutoKillPrefix {
if kill && b.Config.AutoKillPrefix {
log.Println("Waiting for Roblox's process to die :)")

for {
time.Sleep(1 * time.Second)

if !util.CommFound(exe[:15]) {
break
}
}

b.Prefix.Kill()
}

Expand Down
1 change: 0 additions & 1 deletion cmd/vinegar/vinegar.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func PrefixInit(pfx *wine.Prefix) error {
return pfx.RegistryAdd("HKEY_CURRENT_USER\\Control Panel\\Desktop", "LogPixels", wine.REG_DWORD, "100")
}


func Uninstall() {
vers, err := state.Versions()
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions util/proc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build linux

package util

import (
"os"
"path/filepath"
"strings"
)

func CommFound(query string) bool {
comms, _ := filepath.Glob("/proc/*/comm")

for _, comm := range comms {
c, err := os.ReadFile(comm)
// The 'comm' file contains a new line, we remove it, as it will mess up
// the query. hence 'minus'ing the length by 1 removes the newline.
if err == nil && strings.Contains(string(c)[:len(c)-1], query) {
return true
}
}

return false
}

0 comments on commit 5deb2e8

Please sign in to comment.