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 {
|
||||
ImplicitHosting bool
|
||||
InactiveCursors bool
|
||||
MercifulReconnect bool
|
||||
APIToken string
|
||||
|
||||
@ -24,6 +25,11 @@ func (Session) Init(cmd *cobra.Command) error {
|
||||
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")
|
||||
if err := viper.BindPFlag("session.merciful_reconnect", cmd.PersistentFlags().Lookup("session.merciful_reconnect")); err != nil {
|
||||
return err
|
||||
@ -60,6 +66,7 @@ func (Session) Init(cmd *cobra.Command) error {
|
||||
|
||||
func (s *Session) Set() {
|
||||
s.ImplicitHosting = viper.GetBool("session.implicit_hosting")
|
||||
s.InactiveCursors = viper.GetBool("session.inactive_cursors")
|
||||
s.MercifulReconnect = viper.GetBool("session.merciful_reconnect")
|
||||
s.APIToken = viper.GetString("session.api_token")
|
||||
|
||||
|
@ -312,6 +312,10 @@ func (manager *SessionManagerCtx) ImplicitHosting() bool {
|
||||
return manager.config.ImplicitHosting
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) InactiveCursors() bool {
|
||||
return manager.config.InactiveCursors
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) CookieEnabled() bool {
|
||||
return manager.config.CookieEnabled
|
||||
}
|
||||
|
@ -54,8 +54,10 @@ func (session *SessionCtx) IsHost() bool {
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetCursor(cursor types.Cursor) {
|
||||
if session.manager.InactiveCursors() {
|
||||
session.manager.SetCursor(cursor, session)
|
||||
}
|
||||
}
|
||||
|
||||
// ---
|
||||
// websocket
|
||||
|
@ -70,6 +70,7 @@ type SessionManager interface {
|
||||
OnHostChanged(listener func(session Session))
|
||||
|
||||
ImplicitHosting() bool
|
||||
InactiveCursors() bool
|
||||
CookieEnabled() bool
|
||||
MercifulReconnect() bool
|
||||
|
||||
|
@ -20,6 +20,9 @@ import (
|
||||
// send pings to peer with this period - must be less than pongWait
|
||||
const pingPeriod = 10 * time.Second
|
||||
|
||||
// period for sending inactive cursor messages
|
||||
const inactiveCursorsPeriod = 500 * time.Millisecond
|
||||
|
||||
func New(
|
||||
sessions types.SessionManager,
|
||||
desktop types.DesktopManager,
|
||||
@ -132,11 +135,14 @@ func (manager *WebSocketManagerCtx) Start() {
|
||||
|
||||
manager.fileChooserDialogEvents()
|
||||
|
||||
if manager.sessions.InactiveCursors() {
|
||||
manager.logger.Info().Msg("starting inactive cursors handler")
|
||||
|
||||
manager.wg.Add(1)
|
||||
go func() {
|
||||
defer manager.wg.Done()
|
||||
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
ticker := time.NewTicker(inactiveCursorsPeriod)
|
||||
defer ticker.Stop()
|
||||
|
||||
lastEmpty := false
|
||||
@ -144,6 +150,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
||||
for {
|
||||
select {
|
||||
case <-manager.shutdown:
|
||||
manager.logger.Info().Msg("stopping inactive cursors handler")
|
||||
return
|
||||
case <-ticker.C:
|
||||
cursorsMap := manager.sessions.PopCursors()
|
||||
@ -171,6 +178,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
manager.logger.Info().Msg("websocket starting")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user