Skip to content

Commit

Permalink
cmd/vinegar: handle ctrl-c to kill roblox
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Oct 20, 2023
1 parent baa1d6f commit fbc8718
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"path/filepath"
"strings"
"time"
_ "syscall"
"os/signal"
"syscall"

"github.com/nxadm/tail"
bsrpc "github.com/vinegarhq/vinegar/bloxstraprpc"
Expand Down Expand Up @@ -85,6 +86,20 @@ func (b *Binary) Run(args ...string) error {
return err
}

// act as the signal holder, as roblox/wine will not do anything
// with the INT signal.
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)

go func() {
<-c
// This way, cmd.Wait() will return and the wineprefix killer
// will be ran.
log.Println("Killing Roblox")
cmd.Process.Kill()
signal.Stop(c)
}()

if b.Config.DiscordRPC {
err := bsrpc.Login()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/vinegar/vinegar.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func main() {
b.Splash.Desc(b.Config.Channel)

errHandler := func(err error) {
if !cfg.Splash.Enabled {
if !cfg.Splash.Enabled || b.Splash.IsClosed() {
log.Fatal(err)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/splash/splash.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func (ui *Splash) Close() {
ui.Perform(system.ActionClose)
}

func (ui *Splash) IsClosed() bool {
return ui.closed
}

func window(width, height unit.Dp) *app.Window {
return app.NewWindow(
app.Decorated(false),
Expand Down Expand Up @@ -155,6 +159,7 @@ func (ui *Splash) Run() error {
var exitButton widget.Clickable

if !ui.Config.Enabled {
ui.closed = true
return nil
}

Expand Down Expand Up @@ -243,6 +248,7 @@ func (ui *Splash) Run() error {
}
}

ui.closed = true
return nil
}

Expand Down

0 comments on commit fbc8718

Please sign in to comment.