From d7671942a60b2bc711794db32c7ef8826972a548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 2 Sep 2021 21:37:24 +0200 Subject: [PATCH] code fmt change. --- internal/api/members/handler.go | 4 +--- internal/api/room/upload.go | 10 ++++----- internal/capture/screencast.go | 1 + internal/config/webrtc.go | 17 +++++++++------ internal/desktop/drop.go | 13 +++++------ internal/desktop/filechooserdialog.go | 31 +++++++++++++++------------ internal/desktop/xorg.go | 8 +++---- internal/desktop/xorg/xorg.go | 12 +++++------ internal/http/auth/auth.go | 4 +--- internal/websocket/manager.go | 6 +++--- 10 files changed, 54 insertions(+), 52 deletions(-) diff --git a/internal/api/members/handler.go b/internal/api/members/handler.go index 558991d0..b5d52718 100644 --- a/internal/api/members/handler.go +++ b/internal/api/members/handler.go @@ -14,9 +14,7 @@ import ( type key int -const ( - keyMemberCtx key = iota -) +const keyMemberCtx key = iota type MembersHandler struct { members types.MemberManager diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index 58161271..b4c51fb7 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -10,13 +10,11 @@ import ( "demodesk/neko/internal/utils" ) -const ( - // Maximum upload of 32 MB files. - MAX_UPLOAD_SIZE = 32 << 20 -) +// maximum upload size of 32 MB +const maxUploadSize = 32 << 20 func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { - err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) + err := r.ParseMultipartForm(maxUploadSize) if err != nil { utils.HttpBadRequest(w, "failed to parse multipart form") return @@ -87,7 +85,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) { } func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) { - err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) + err := r.ParseMultipartForm(maxUploadSize) if err != nil { utils.HttpBadRequest(w, "failed to parse multipart form") return diff --git a/internal/capture/screencast.go b/internal/capture/screencast.go index 179e8b32..36222b17 100644 --- a/internal/capture/screencast.go +++ b/internal/capture/screencast.go @@ -28,6 +28,7 @@ type ScreencastManagerCtx struct { image types.Sample } +// timeout between intervals, when screencast pipeline is checked const screencastTimeout = 5 * time.Second func screencastNew(enabled bool, pipelineStr string) *ScreencastManagerCtx { diff --git a/internal/config/webrtc.go b/internal/config/webrtc.go index 55bdea31..ab6d84ed 100644 --- a/internal/config/webrtc.go +++ b/internal/config/webrtc.go @@ -13,6 +13,15 @@ import ( "demodesk/neko/internal/utils" ) +// default port range - min +const defEprMin = 59000 + +// default port range - max +const defEprMax = 59100 + +// default stun server +const defStunSrv = "stun:stun.l.google.com:19302" + type WebRTC struct { ICELite bool ICETrickle bool @@ -24,12 +33,6 @@ type WebRTC struct { IpRetrievalUrl string } -const ( - defEprMin = 59000 - defEprMax = 59100 - defStun = "stun:stun.l.google.com:19302" -) - func (WebRTC) Init(cmd *cobra.Command) error { cmd.PersistentFlags().Bool("webrtc.icelite", false, "configures whether or not the ICE agent should be a lite agent") if err := viper.BindPFlag("webrtc.icelite", cmd.PersistentFlags().Lookup("webrtc.icelite")); err != nil { @@ -76,7 +79,7 @@ func (s *WebRTC) Set() { if len(s.ICEServers) == 0 { s.ICEServers = append(s.ICEServers, types.ICEServer{ - URLs: []string{defStun}, + URLs: []string{defStunSrv}, }) } diff --git a/internal/desktop/drop.go b/internal/desktop/drop.go index 6dbf186b..ff9166d8 100644 --- a/internal/desktop/drop.go +++ b/internal/desktop/drop.go @@ -6,10 +6,11 @@ import ( "demodesk/neko/internal/desktop/drop" ) -const ( - DROP_MOVE_REPEAT = 4 - DROP_DELAY = 100 * time.Millisecond -) +// repeat move event multiple times +const dropMoveRepeat = 4 + +// wait after each repeated move event +const dropMoveDelay = 100 * time.Millisecond func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool { mu.Lock() @@ -31,9 +32,9 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool { }) drop.Emmiter.Once("begin", func(payload ...interface{}) { - for i := 0; i < DROP_MOVE_REPEAT; i++ { + for i := 0; i < dropMoveRepeat; i++ { manager.Move(x, y) - time.Sleep(DROP_DELAY) + time.Sleep(dropMoveDelay) } //nolint diff --git a/internal/desktop/filechooserdialog.go b/internal/desktop/filechooserdialog.go index 5091e001..b10f76a8 100644 --- a/internal/desktop/filechooserdialog.go +++ b/internal/desktop/filechooserdialog.go @@ -6,11 +6,14 @@ import ( "time" ) -const ( - FILE_CHOOSER_DIALOG_NAME = "Open File" - FILE_CHOOSER_DIALOG_SHORT_SLEEP = "0.2" - FILE_CHOOSER_DIALOG_LONG_SLEEP = "0.4" -) +// name of the window that is being controlled +const fileChooserDialogName = "Open File" + +// short sleep value between fake user interactions +const fileChooserDialogShortSleep = "0.2" + +// long sleep value between fake user interactions +const fileChooserDialogLongSleep = "0.4" func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error { mu.Lock() @@ -19,19 +22,19 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error { // TODO: Use native API. err1 := exec.Command( "xdotool", - "search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus", - "sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP, + "search", "--name", fileChooserDialogName, "windowfocus", + "sleep", fileChooserDialogShortSleep, "key", "--clearmodifiers", "ctrl+l", "type", "--args", "1", uri+"//", - "sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP, + "sleep", fileChooserDialogShortSleep, "key", "Delete", // remove autocomplete results - "sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP, + "sleep", fileChooserDialogShortSleep, "key", "Return", - "sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP, + "sleep", fileChooserDialogLongSleep, "key", "Down", "key", "--clearmodifiers", "ctrl+a", "key", "Return", - "sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP, + "sleep", fileChooserDialogLongSleep, ).Run() if err1 != nil { @@ -41,7 +44,7 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error { // TODO: Use native API. err2 := exec.Command( "xdotool", - "search", "--name", FILE_CHOOSER_DIALOG_NAME, + "search", "--name", fileChooserDialogName, ).Run() // if last command didn't return error, consider dialog as still open @@ -61,7 +64,7 @@ func (manager *DesktopManagerCtx) CloseFileChooserDialog() { // TODO: Use native API. err := exec.Command( "xdotool", - "search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus", + "search", "--name", fileChooserDialogName, "windowfocus", ).Run() if err != nil { @@ -92,7 +95,7 @@ func (manager *DesktopManagerCtx) IsFileChooserDialogOpened() bool { // TODO: Use native API. err := exec.Command( "xdotool", - "search", "--name", FILE_CHOOSER_DIALOG_NAME, + "search", "--name", fileChooserDialogName, ).Run() return err == nil diff --git a/internal/desktop/xorg.go b/internal/desktop/xorg.go index 35a43d5c..047068d1 100644 --- a/internal/desktop/xorg.go +++ b/internal/desktop/xorg.go @@ -95,19 +95,19 @@ func (manager *DesktopManagerCtx) GetKeyboardMap() (*types.KeyboardMap, error) { func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) { if mod.NumLock != nil { - xorg.SetKeyboardModifier(xorg.KBD_NUM_LOCK, *mod.NumLock) + xorg.SetKeyboardModifier(xorg.KbdModNumLock, *mod.NumLock) } if mod.CapsLock != nil { - xorg.SetKeyboardModifier(xorg.KBD_CAPS_LOCK, *mod.CapsLock) + xorg.SetKeyboardModifier(xorg.KbdModCapsLock, *mod.CapsLock) } } func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers { modifiers := xorg.GetKeyboardModifiers() - NumLock := (modifiers & xorg.KBD_NUM_LOCK) != 0 - CapsLock := (modifiers & xorg.KBD_CAPS_LOCK) != 0 + NumLock := (modifiers & xorg.KbdModNumLock) != 0 + CapsLock := (modifiers & xorg.KbdModCapsLock) != 0 return types.KeyboardModifiers{ NumLock: &NumLock, diff --git a/internal/desktop/xorg/xorg.go b/internal/desktop/xorg/xorg.go index 4598f6cf..827b9149 100644 --- a/internal/desktop/xorg/xorg.go +++ b/internal/desktop/xorg/xorg.go @@ -19,11 +19,11 @@ import ( "demodesk/neko/internal/types" ) -type KbdModifiers uint8 +type KbdMod uint8 const ( - KBD_CAPS_LOCK KbdModifiers = 2 - KBD_NUM_LOCK KbdModifiers = 16 + KbdModCapsLock KbdMod = 2 + KbdModNumLock KbdMod = 16 ) var ScreenConfigurations = make(map[int]types.ScreenConfiguration) @@ -213,7 +213,7 @@ func GetScreenSize() *types.ScreenSize { return nil } -func SetKeyboardModifier(mod KbdModifiers, active bool) { +func SetKeyboardModifier(mod KbdMod, active bool) { mu.Lock() defer mu.Unlock() @@ -225,11 +225,11 @@ func SetKeyboardModifier(mod KbdModifiers, active bool) { C.XSetKeyboardModifier(C.int(mod), num) } -func GetKeyboardModifiers() KbdModifiers { +func GetKeyboardModifiers() KbdMod { mu.Lock() defer mu.Unlock() - return KbdModifiers(C.XGetKeyboardModifiers()) + return KbdMod(C.XGetKeyboardModifiers()) } func GetCursorImage() *types.CursorImage { diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index eed1d303..856a6913 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -10,9 +10,7 @@ import ( type key int -const ( - keySessionCtx key = iota -) +const keySessionCtx key = iota func SetSession(r *http.Request, session types.Session) *http.Request { ctx := context.WithValue(r.Context(), keySessionCtx, session) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 6e9c6476..b44e37e5 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -15,6 +15,9 @@ import ( "demodesk/neko/internal/websocket/handler" ) +// send pings to peer with this period - must be less than pongWait +const pingPeriod = 10 * time.Second + func New( sessions types.SessionManager, desktop types.DesktopManager, @@ -32,9 +35,6 @@ func New( } } -// Send pings to peer with this period. Must be less than pongWait. -const pingPeriod = 10 * time.Second - type WebSocketManagerCtx struct { logger zerolog.Logger sessions types.SessionManager