mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
54 lines
959 B
Go
54 lines
959 B
Go
package desktop
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"demodesk/neko/internal/desktop/xorg"
|
|
)
|
|
|
|
type DesktopManagerCtx struct {
|
|
logger zerolog.Logger
|
|
cleanup *time.Ticker
|
|
shutdown chan bool
|
|
display string
|
|
}
|
|
|
|
func New(display string) *DesktopManagerCtx {
|
|
return &DesktopManagerCtx{
|
|
logger: log.With().Str("module", "desktop").Logger(),
|
|
cleanup: time.NewTicker(1 * time.Second),
|
|
shutdown: make(chan bool),
|
|
display: display,
|
|
}
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) Start() {
|
|
xorg.Display(manager.display)
|
|
|
|
go func() {
|
|
defer func() {
|
|
manager.logger.Info().Msg("shutdown")
|
|
}()
|
|
|
|
for {
|
|
select {
|
|
case <-manager.shutdown:
|
|
return
|
|
case <-manager.cleanup.C:
|
|
xorg.CheckKeys(time.Second * 10)
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) Shutdown() error {
|
|
manager.logger.Info().Msgf("remote shutting down")
|
|
|
|
manager.cleanup.Stop()
|
|
manager.shutdown <- true
|
|
return nil
|
|
}
|