mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-29 01:53:00 +08:00
Fix the leak of xdg processes
This commit is contained in:
@@ -179,4 +179,8 @@ func runPanel(
|
||||
if err != nil {
|
||||
logger.Panic(ctx, err)
|
||||
}
|
||||
err = panel.Close()
|
||||
if err != nil {
|
||||
logger.Error(ctx, err)
|
||||
}
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -11,7 +11,7 @@ replace github.com/andreykaipov/goobs v1.4.1 => github.com/xaionaro-go/goobs v0.
|
||||
|
||||
replace github.com/adrg/libvlc-go/v3 v3.1.5 => github.com/xaionaro-go/libvlc-go/v3 v3.0.0-20241011194409-0fe4e2a9d901
|
||||
|
||||
replace fyne.io/fyne/v2 v2.5.0 => github.com/xaionaro-go/fyne/v2 v2.0.0-20241012203222-61bfd3b898c0
|
||||
replace fyne.io/fyne/v2 v2.5.0 => github.com/xaionaro-go/fyne/v2 v2.0.0-20241020235352-fd61e4920f24
|
||||
|
||||
replace code.cloudfoundry.org/bytefmt => github.com/cloudfoundry/bytefmt v0.0.0-20211005130812-5bb3c17173e5
|
||||
|
||||
|
||||
10
go.sum
10
go.sum
@@ -657,20 +657,14 @@ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ
|
||||
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
|
||||
github.com/xaionaro-go/datacounter v1.0.4 h1:+QMZLmu73R5WGkQfUPwlXF/JFN+Weo4iuDZkiL2wVm8=
|
||||
github.com/xaionaro-go/datacounter v1.0.4/go.mod h1:Sf9vBevuV6w5iE6K3qJ9pWVKcyS60clWBUSQLjt5++c=
|
||||
github.com/xaionaro-go/fyne/v2 v2.0.0-20241012203222-61bfd3b898c0 h1:lo0cD3peJmJvQhz7SFSO/acqwTxVVcAk0qCDvuRmiEo=
|
||||
github.com/xaionaro-go/fyne/v2 v2.0.0-20241012203222-61bfd3b898c0/go.mod h1:NdxEG8L7EVWo06/cYbXW11uA0X7UG8Q8j5CLebvTZi8=
|
||||
github.com/xaionaro-go/fyne/v2 v2.0.0-20241020235352-fd61e4920f24 h1:eewdCRMkJmK2ipI9653XL2dE3EFS2I3GTFRadIyyEo4=
|
||||
github.com/xaionaro-go/fyne/v2 v2.0.0-20241020235352-fd61e4920f24/go.mod h1:NdxEG8L7EVWo06/cYbXW11uA0X7UG8Q8j5CLebvTZi8=
|
||||
github.com/xaionaro-go/go-rtmp v0.0.0-20241009130244-1e3160f27f42 h1:izCjREd+62HDF9FRYqUI7dgJNdUxAIysEuqed8lBcDY=
|
||||
github.com/xaionaro-go/go-rtmp v0.0.0-20241009130244-1e3160f27f42/go.mod h1:IuQWd+hy/tLuvuqFX0N9SMZrzOprM8Jvvdu+42RJwk4=
|
||||
github.com/xaionaro-go/goobs v0.0.0-20241018191659-49be16b2ceb5 h1:mGbap4wNdYQjnY5LAHcU0kEcQHFuzvcB2hReE1IDLDU=
|
||||
github.com/xaionaro-go/goobs v0.0.0-20241018191659-49be16b2ceb5/go.mod h1:yuYqusq3i5Jp69QYaSYU5mY3xE1cKZGixm2B49k7uks=
|
||||
github.com/xaionaro-go/gorex v0.0.0-20241010205749-bcd59d639c4d h1:9DyH0lboWWzKUwiqGmp9sTZ3bSPhgJHiiWgV+hqY9Uo=
|
||||
github.com/xaionaro-go/gorex v0.0.0-20241010205749-bcd59d639c4d/go.mod h1:yI0EvHC6Ir5WIZp3tEk7o42/QqeTb9pkII+T8p4FlPo=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020181755-c5f35f3595f5 h1:hZ2Vn1+nOS4HGZMBzJgxfvHTM+FqtOAomNLC8RPi5BQ=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020181755-c5f35f3595f5/go.mod h1:gzKL0qgtR13PXl4woI3nvxVhQ9Z6lHtGL5tk9HmITxA=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020183454-2f0792240237 h1:RErwOvIJwqj3o1gXsB1FFVErn36FNH/61S3jHiipzBI=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020183454-2f0792240237/go.mod h1:gzKL0qgtR13PXl4woI3nvxVhQ9Z6lHtGL5tk9HmITxA=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020185357-4b25f7aff380 h1:6TizYY8DVhtUEifPncz/RiuW00Pewhr4u5/KJ3CHxnQ=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020185357-4b25f7aff380/go.mod h1:gzKL0qgtR13PXl4woI3nvxVhQ9Z6lHtGL5tk9HmITxA=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020191155-4a9e942e8e35 h1:aVCVi4OMOC09ogSaNjEwW4et2EYcpQHHASNbfW5yATw=
|
||||
github.com/xaionaro-go/kickcom v0.0.0-20241020191155-4a9e942e8e35/go.mod h1:gzKL0qgtR13PXl4woI3nvxVhQ9Z6lHtGL5tk9HmITxA=
|
||||
github.com/xaionaro-go/libvlc-go/v3 v3.0.0-20241011194409-0fe4e2a9d901 h1:HX0CO6h5oDQfp9NquzQT0xWH4Gn9Z5BZ0IFJrYFl88k=
|
||||
|
||||
@@ -28,6 +28,8 @@ func (p *Panel) initEventSensor(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
p.eventSensor = es
|
||||
|
||||
observability.Go(ctx, func() {
|
||||
logger.Debugf(ctx, "eventSensor")
|
||||
defer logger.Debugf(ctx, "/eventSensor")
|
||||
@@ -37,6 +39,7 @@ func (p *Panel) initEventSensor(ctx context.Context) {
|
||||
|
||||
type eventSensor struct {
|
||||
WMH *windowmanagerhandler.WindowManagerHandler
|
||||
CancelFunc context.CancelFunc
|
||||
|
||||
PreviouslyFocusedWindow *windowmanagerhandler.WindowFocusChange
|
||||
}
|
||||
@@ -63,7 +66,12 @@ func (es *eventSensor) Loop(
|
||||
ctx context.Context,
|
||||
eventSubmitter submitEventer,
|
||||
) {
|
||||
ctx, cancelFn := context.WithCancel(ctx)
|
||||
windowFocusChangeChan := es.WMH.WindowFocusChangeChan(ctx)
|
||||
if es.CancelFunc != nil {
|
||||
panic("this sensor was already used")
|
||||
}
|
||||
es.CancelFunc = cancelFn
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -77,6 +85,13 @@ func (es *eventSensor) Loop(
|
||||
}
|
||||
}
|
||||
|
||||
func (es *eventSensor) Close() error {
|
||||
var err *multierror.Error
|
||||
err = multierror.Append(err, es.WMH.Close())
|
||||
es.CancelFunc()
|
||||
return err.ErrorOrNil()
|
||||
}
|
||||
|
||||
func (es *eventSensor) submitEventWindowFocusChange(
|
||||
ctx context.Context,
|
||||
ev windowmanagerhandler.WindowFocusChange,
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/facebookincubator/go-belt/tool/experimental/errmon"
|
||||
"github.com/facebookincubator/go-belt/tool/logger"
|
||||
"github.com/go-ng/xmath"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/xaionaro-go/obs-grpc-proxy/protobuf/go/obs_grpc"
|
||||
"github.com/xaionaro-go/streamctl/pkg/oauthhandler"
|
||||
"github.com/xaionaro-go/streamctl/pkg/observability"
|
||||
@@ -154,6 +155,8 @@ type Panel struct {
|
||||
|
||||
statusPanelLocker xsync.Mutex
|
||||
statusPanel *widget.Label
|
||||
|
||||
eventSensor *eventSensor
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -3411,3 +3414,12 @@ func (p *Panel) showWaitStreamDConnectWindow(ctx context.Context) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Panel) Close() error {
|
||||
var err *multierror.Error
|
||||
err = multierror.Append(err, p.eventSensor.Close())
|
||||
// TODO: remove observability.Go, Quit should be executed synchronously,
|
||||
// but there is a bug in fyne and it hangs
|
||||
observability.Go(context.TODO(), p.app.Quit)
|
||||
return err.ErrorOrNil()
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ func (wmh *WindowManagerHandler) WindowFocusChangeChan(ctx context.Context) <-ch
|
||||
return wmh.PlatformSpecificWindowManagerHandler.WindowFocusChangeChan(ctx)
|
||||
}
|
||||
|
||||
func (wmh *WindowManagerHandler) Close() error {
|
||||
return wmh.PlatformSpecificWindowManagerHandler.Close()
|
||||
}
|
||||
|
||||
type WindowFocusChange struct {
|
||||
WindowID *WindowID
|
||||
WindowTitle *string
|
||||
|
||||
@@ -13,6 +13,7 @@ type PID int // using the same underlying type as `os` does
|
||||
type UID int // using the same underlying type as `os` does
|
||||
|
||||
type XWMOrWaylandWM interface {
|
||||
Close() error
|
||||
WindowFocusChangeChan(ctx context.Context) <-chan WindowFocusChange
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,10 @@ type XWindowManagerHandler struct {
|
||||
}
|
||||
|
||||
func (wmh *WindowManagerHandler) initUsingXServer() error {
|
||||
x, err := xgbutil.NewConn()
|
||||
display := os.Getenv("DISPLAY")
|
||||
x, err := xgbutil.NewConnDisplay(display)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect to X-server using DISPLAY '%s': %w", os.Getenv("DISPLAY"), err)
|
||||
return fmt.Errorf("unable to connect to X-server using DISPLAY '%s': %w", display, err)
|
||||
}
|
||||
wmh.XWMOrWaylandWM = &XWindowManagerHandler{
|
||||
XUtil: x,
|
||||
@@ -110,3 +111,11 @@ func (wmh *XWindowManagerHandler) WindowFocusChangeChan(ctx context.Context) <-c
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
func (wmh *XWindowManagerHandler) Close() error {
|
||||
ctx := context.TODO()
|
||||
logger.Debugf(ctx, "Close")
|
||||
defer logger.Debugf(ctx, "/Close")
|
||||
wmh.XUtil.Conn().Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,3 +16,7 @@ type UID struct{}
|
||||
func (wmh *WindowManagerHandler) init(context.Context) error {
|
||||
return fmt.Errorf("the support of window manager handler for this platform is not implemented, yet")
|
||||
}
|
||||
|
||||
func (PlatformSpecificWindowManagerHandler) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user