Skip to content

Commit

Permalink
refactor rich presence handling; initial StudioRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Mar 9, 2024
1 parent 4955b8a commit 790ac47
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 291 deletions.
180 changes: 0 additions & 180 deletions bloxstraprpc/bloxstraprpc.go

This file was deleted.

88 changes: 0 additions & 88 deletions bloxstraprpc/discordrpc.go

This file was deleted.

26 changes: 19 additions & 7 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io"
"log/slog"
"os"
"os/signal"
Expand All @@ -13,18 +14,20 @@ import (

"github.com/apprehensions/rbxbin"
"github.com/apprehensions/rbxweb/clientsettings"
"github.com/apprehensions/wine"
"github.com/fsnotify/fsnotify"
"github.com/godbus/dbus/v5"
"github.com/lmittmann/tint"
"github.com/nxadm/tail"
slogmulti "github.com/samber/slog-multi"
bsrpc "github.com/vinegarhq/vinegar/bloxstraprpc"
"github.com/vinegarhq/vinegar/config"
"github.com/vinegarhq/vinegar/internal/dirs"
"github.com/vinegarhq/vinegar/internal/state"
"github.com/vinegarhq/vinegar/richpresence"
"github.com/vinegarhq/vinegar/richpresence/bloxstraprpc"
"github.com/vinegarhq/vinegar/richpresence/studiorpc"
"github.com/vinegarhq/vinegar/splash"
"github.com/vinegarhq/vinegar/sysinfo"
"github.com/apprehensions/wine"
"golang.org/x/term"
)

Expand All @@ -33,6 +36,11 @@ const (
DieTimeout = 3 * time.Second
)

const (
// TODO: find better entries
PlayerShutdownEntry = "[FLog::SingleSurfaceApp] shutDown:"
)

const (
DialogUseBrowser = "WebView/InternalBrowser is broken, please use the browser for the action that you were doing."
DialogQuickLogin = "WebView/InternalBrowser is broken, use Quick Log In to authenticate ('Log In With Another Device' button)"
Expand All @@ -57,7 +65,7 @@ type Binary struct {

// Logging
Auth bool
Activity bsrpc.Activity
Presence richpresence.BinaryRichPresence
}

func BinaryPrefixDir(bt clientsettings.BinaryType) string {
Expand All @@ -67,6 +75,7 @@ func BinaryPrefixDir(bt clientsettings.BinaryType) string {
func NewBinary(bt clientsettings.BinaryType, cfg *config.Config) (*Binary, error) {
var bcfg *config.Binary
var bstate *state.Binary
var rp richpresence.BinaryRichPresence

s, err := state.Load()
if err != nil {
Expand All @@ -77,16 +86,18 @@ func NewBinary(bt clientsettings.BinaryType, cfg *config.Config) (*Binary, error
case clientsettings.WindowsPlayer:
bcfg = &cfg.Player
bstate = &s.Player
rp = bloxstraprpc.New()
case clientsettings.WindowsStudio64:
bcfg = &cfg.Studio
bstate = &s.Studio
rp = studiorpc.New()
}

pfx := wine.New(BinaryPrefixDir(bt), bcfg.WineRoot)
os.Setenv("GAMEID", "ulwgl-roblox")

return &Binary{
Activity: bsrpc.New(),
Presence: rp,

GlobalState: &s,
State: bstate,
Expand All @@ -113,6 +124,7 @@ func (b *Binary) Main(args ...string) int {
)))

b.Splash = splash.New(&b.GlobalConfig.Splash)
b.Prefix.Stderr = io.MultiWriter(os.Stderr, logFile)
b.Config.Env.Setenv()

go func() {
Expand Down Expand Up @@ -368,16 +380,16 @@ func (b *Binary) Tail(name string) {
// 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:") {
if strings.Contains(line.Text, PlayerShutdownEntry) {
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)
if err := b.Presence.Handle(line.Text); err != nil {
slog.Error("Presence handling failed", "error", err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vinegar/binary_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/apprehensions/rbxbin"
"github.com/apprehensions/rbxweb/clientsettings"
cp "github.com/otiai10/copy"
"github.com/vinegarhq/vinegar/dxvk"
"github.com/vinegarhq/vinegar/internal/dirs"
"github.com/vinegarhq/vinegar/internal/netutil"
"github.com/vinegarhq/vinegar/dxvk"
"golang.org/x/sync/errgroup"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/vinegar/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"runtime/debug"

"github.com/apprehensions/rbxweb/clientsettings"
"github.com/apprehensions/wine"
"github.com/vinegarhq/vinegar/config"
"github.com/vinegarhq/vinegar/sysinfo"
"github.com/apprehensions/wine"
)

func PrintSysinfo(cfg *config.Config) {
Expand Down
Loading

0 comments on commit 790ac47

Please sign in to comment.