Skip to content

Commit

Permalink
cmd/vinegar: introduce homicide to roblox when its begging to live
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Feb 18, 2024
1 parent ae3623a commit ee9ef61
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import (
"github.com/vinegarhq/vinegar/wine"
)

const timeout = 6 * time.Second
const (
LogTimeout = 6 * time.Second
DieTimeout = 3 * time.Second
)

const (
DialogUseBrowser = "WebView/InternalBrowser is broken, please use the browser for the action that you were doing."
Expand Down Expand Up @@ -240,8 +243,10 @@ func (b *Binary) Run(args ...string) error {
}

// Roblox will keep running if it was sent SIGINT; requiring acting as the signal holder.
// SIGUSR1 is used in Tail() to force kill roblox, used to differenciate between
// a user-sent signal and a self sent signal.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1)
go func() {
s := <-c

Expand Down Expand Up @@ -320,12 +325,12 @@ func RobloxLogFile(pfx *wine.Prefix) (string, error) {
return "", fmt.Errorf("watch roblox log dir: %w", err)
}

t := time.NewTimer(timeout)
t := time.NewTimer(LogTimeout)

for {
select {
case <-t.C:
return "", fmt.Errorf("roblox log file not found after %s", timeout)
return "", fmt.Errorf("roblox log file not found after %s", LogTimeout)
case e := <-w.Events:
if e.Has(fsnotify.Create) {
return e.Name, nil
Expand All @@ -346,6 +351,16 @@ func (b *Binary) Tail(name string) {
for line := range t.Lines {
fmt.Fprintln(b.Prefix.Stderr, line.Text)

// Roblox shut down, give it atleast a few seconds, and then send an
// internal signal to kill it.
// This is due to Roblox occasionally refusing to die. We must kill it.
if strings.Contains(line.Text, "[FLog::SingleSurfaceApp] shutDown:") {
go func() {
time.Sleep(DieTimeout)
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
}()
}

if b.Config.DiscordRPC {
if err := b.Activity.HandleRobloxLog(line.Text); err != nil {
slog.Error("Activity Roblox log handle failed", "error", err)
Expand Down

0 comments on commit ee9ef61

Please sign in to comment.