mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
inactive cursors to config.
This commit is contained in:
parent
28c22a254b
commit
3528766e7f
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
ImplicitHosting bool
|
ImplicitHosting bool
|
||||||
|
InactiveCursors bool
|
||||||
MercifulReconnect bool
|
MercifulReconnect bool
|
||||||
APIToken string
|
APIToken string
|
||||||
|
|
||||||
@ -24,6 +25,11 @@ func (Session) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.PersistentFlags().Bool("session.inactive_cursors", true, "show inactive cursors on the screen")
|
||||||
|
if err := viper.BindPFlag("session.inactive_cursors", cmd.PersistentFlags().Lookup("session.inactive_cursors")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().Bool("session.merciful_reconnect", true, "allow reconnecting to websocket even if previous connection was not closed")
|
cmd.PersistentFlags().Bool("session.merciful_reconnect", true, "allow reconnecting to websocket even if previous connection was not closed")
|
||||||
if err := viper.BindPFlag("session.merciful_reconnect", cmd.PersistentFlags().Lookup("session.merciful_reconnect")); err != nil {
|
if err := viper.BindPFlag("session.merciful_reconnect", cmd.PersistentFlags().Lookup("session.merciful_reconnect")); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -60,6 +66,7 @@ func (Session) Init(cmd *cobra.Command) error {
|
|||||||
|
|
||||||
func (s *Session) Set() {
|
func (s *Session) Set() {
|
||||||
s.ImplicitHosting = viper.GetBool("session.implicit_hosting")
|
s.ImplicitHosting = viper.GetBool("session.implicit_hosting")
|
||||||
|
s.InactiveCursors = viper.GetBool("session.inactive_cursors")
|
||||||
s.MercifulReconnect = viper.GetBool("session.merciful_reconnect")
|
s.MercifulReconnect = viper.GetBool("session.merciful_reconnect")
|
||||||
s.APIToken = viper.GetString("session.api_token")
|
s.APIToken = viper.GetString("session.api_token")
|
||||||
|
|
||||||
|
@ -312,6 +312,10 @@ func (manager *SessionManagerCtx) ImplicitHosting() bool {
|
|||||||
return manager.config.ImplicitHosting
|
return manager.config.ImplicitHosting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *SessionManagerCtx) InactiveCursors() bool {
|
||||||
|
return manager.config.InactiveCursors
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) CookieEnabled() bool {
|
func (manager *SessionManagerCtx) CookieEnabled() bool {
|
||||||
return manager.config.CookieEnabled
|
return manager.config.CookieEnabled
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,9 @@ func (session *SessionCtx) IsHost() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetCursor(cursor types.Cursor) {
|
func (session *SessionCtx) SetCursor(cursor types.Cursor) {
|
||||||
|
if session.manager.InactiveCursors() {
|
||||||
session.manager.SetCursor(cursor, session)
|
session.manager.SetCursor(cursor, session)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
@ -70,6 +70,7 @@ type SessionManager interface {
|
|||||||
OnHostChanged(listener func(session Session))
|
OnHostChanged(listener func(session Session))
|
||||||
|
|
||||||
ImplicitHosting() bool
|
ImplicitHosting() bool
|
||||||
|
InactiveCursors() bool
|
||||||
CookieEnabled() bool
|
CookieEnabled() bool
|
||||||
MercifulReconnect() bool
|
MercifulReconnect() bool
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ import (
|
|||||||
// send pings to peer with this period - must be less than pongWait
|
// send pings to peer with this period - must be less than pongWait
|
||||||
const pingPeriod = 10 * time.Second
|
const pingPeriod = 10 * time.Second
|
||||||
|
|
||||||
|
// period for sending inactive cursor messages
|
||||||
|
const inactiveCursorsPeriod = 500 * time.Millisecond
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
sessions types.SessionManager,
|
sessions types.SessionManager,
|
||||||
desktop types.DesktopManager,
|
desktop types.DesktopManager,
|
||||||
@ -132,11 +135,14 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
|
|
||||||
manager.fileChooserDialogEvents()
|
manager.fileChooserDialogEvents()
|
||||||
|
|
||||||
|
if manager.sessions.InactiveCursors() {
|
||||||
|
manager.logger.Info().Msg("starting inactive cursors handler")
|
||||||
|
|
||||||
manager.wg.Add(1)
|
manager.wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer manager.wg.Done()
|
defer manager.wg.Done()
|
||||||
|
|
||||||
ticker := time.NewTicker(500 * time.Millisecond)
|
ticker := time.NewTicker(inactiveCursorsPeriod)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
lastEmpty := false
|
lastEmpty := false
|
||||||
@ -144,6 +150,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-manager.shutdown:
|
case <-manager.shutdown:
|
||||||
|
manager.logger.Info().Msg("stopping inactive cursors handler")
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
cursorsMap := manager.sessions.PopCursors()
|
cursorsMap := manager.sessions.PopCursors()
|
||||||
@ -171,6 +178,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
manager.logger.Info().Msg("websocket starting")
|
manager.logger.Info().Msg("websocket starting")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user