From b40c0778c882a2c7cd2c7858ebfa3bba51ae9813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 24 Nov 2023 10:39:09 +0100 Subject: [PATCH] file chooser dialog diabled by default. --- internal/api/room/upload.go | 8 ++++++++ internal/config/desktop.go | 9 ++++++++- internal/desktop/filechooserdialog.go | 4 ++++ internal/desktop/manager.go | 8 ++++++-- internal/websocket/manager.go | 4 +++- pkg/types/desktop.go | 1 + pkg/xevent/xevent.go | 13 +++++++------ 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index 046c6d94..bc25ef3d 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -87,6 +87,10 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) error { } func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) error { + if !h.desktop.IsFileChooserDialogEnabled() { + return utils.HttpBadRequest("file chooser dialog is disabled") + } + err := r.ParseMultipartForm(maxUploadSize) if err != nil { return utils.HttpBadRequest("failed to parse multipart form").WithInternalErr(err) @@ -150,6 +154,10 @@ func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) e } func (h *RoomHandler) uploadDialogClose(w http.ResponseWriter, r *http.Request) error { + if !h.desktop.IsFileChooserDialogEnabled() { + return utils.HttpBadRequest("file chooser dialog is disabled") + } + if !h.desktop.IsFileChooserDialogOpened() { return utils.HttpUnprocessableEntity("file chooser dialog is not open") } diff --git a/internal/config/desktop.go b/internal/config/desktop.go index a18d2c12..10bcec95 100644 --- a/internal/config/desktop.go +++ b/internal/config/desktop.go @@ -19,7 +19,8 @@ type Desktop struct { UseInputDriver bool InputSocket string - Unminimize bool + Unminimize bool + FileChooserDialog bool } func (Desktop) Init(cmd *cobra.Command) error { @@ -43,6 +44,11 @@ func (Desktop) Init(cmd *cobra.Command) error { return err } + cmd.PersistentFlags().Bool("desktop.file_chooser_dialog", false, "whether to handle file chooser dialog externally") + if err := viper.BindPFlag("desktop.file_chooser_dialog", cmd.PersistentFlags().Lookup("desktop.file_chooser_dialog")); err != nil { + return err + } + return nil } @@ -74,4 +80,5 @@ func (s *Desktop) Set() { s.UseInputDriver = viper.GetBool("desktop.input.enabled") s.InputSocket = viper.GetString("desktop.input.socket") s.Unminimize = viper.GetBool("desktop.unminimize") + s.FileChooserDialog = viper.GetBool("desktop.file_chooser_dialog") } diff --git a/internal/desktop/filechooserdialog.go b/internal/desktop/filechooserdialog.go index e5db4af6..32e9f7d5 100644 --- a/internal/desktop/filechooserdialog.go +++ b/internal/desktop/filechooserdialog.go @@ -84,6 +84,10 @@ func (manager *DesktopManagerCtx) CloseFileChooserDialog() { } } +func (manager *DesktopManagerCtx) IsFileChooserDialogEnabled() bool { + return manager.config.FileChooserDialog +} + func (manager *DesktopManagerCtx) IsFileChooserDialogOpened() bool { mu.Lock() defer mu.Unlock() diff --git a/internal/desktop/manager.go b/internal/desktop/manager.go index 2f981618..dad4dd2d 100644 --- a/internal/desktop/manager.go +++ b/internal/desktop/manager.go @@ -71,11 +71,15 @@ func (manager *DesktopManagerCtx) Start() { manager.logger.Panic().Err(err).Msg("unable to connect to input driver") } + // set up event listeners xevent.Unminimize = manager.config.Unminimize + xevent.FileChooserDialog = manager.config.FileChooserDialog go xevent.EventLoop(manager.config.Display) - // In case it was opened - go manager.CloseFileChooserDialog() + // in case it was opened + if manager.config.FileChooserDialog { + go manager.CloseFileChooserDialog() + } manager.OnEventError(func(error_code uint8, message string, request_code uint8, minor_code uint8) { manager.logger.Warn(). diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 03da86b2..9443aa6a 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -167,7 +167,9 @@ func (manager *WebSocketManagerCtx) Start() { }) }) - manager.fileChooserDialogEvents() + if manager.desktop.IsFileChooserDialogEnabled() { + manager.fileChooserDialogEvents() + } if manager.sessions.Settings().InactiveCursors { manager.startInactiveCursors() diff --git a/pkg/types/desktop.go b/pkg/types/desktop.go index 73f37d39..bd38da0e 100644 --- a/pkg/types/desktop.go +++ b/pkg/types/desktop.go @@ -98,5 +98,6 @@ type DesktopManager interface { // filechooser HandleFileChooserDialog(uri string) error CloseFileChooserDialog() + IsFileChooserDialogEnabled() bool IsFileChooserDialogOpened() bool } diff --git a/pkg/xevent/xevent.go b/pkg/xevent/xevent.go index 91e449e4..53b820e9 100644 --- a/pkg/xevent/xevent.go +++ b/pkg/xevent/xevent.go @@ -16,7 +16,8 @@ import ( var Emmiter events.EventEmmiter var Unminimize bool = false -var file_chooser_dialog_window uint32 = 0 +var FileChooserDialog bool = false +var fileChooserDialogWindow uint32 = 0 func init() { Emmiter = events.New() @@ -41,7 +42,7 @@ func goXEventClipboardUpdated() { //export goXEventConfigureNotify func goXEventConfigureNotify(display *C.Display, window C.Window, name *C.char, role *C.char) { - if C.GoString(role) != "GtkFileChooserDialog" { + if C.GoString(role) != "GtkFileChooserDialog" || !FileChooserDialog { return } @@ -53,19 +54,19 @@ func goXEventConfigureNotify(display *C.Display, window C.Window, name *C.char, C.XFileChooserHide(display, window) - if file_chooser_dialog_window == 0 { - file_chooser_dialog_window = uint32(window) + if fileChooserDialogWindow == 0 { + fileChooserDialogWindow = uint32(window) Emmiter.Emit("file-chooser-dialog-opened") } } //export goXEventUnmapNotify func goXEventUnmapNotify(window C.Window) { - if uint32(window) != file_chooser_dialog_window { + if uint32(window) != fileChooserDialogWindow || !FileChooserDialog { return } - file_chooser_dialog_window = 0 + fileChooserDialogWindow = 0 Emmiter.Emit("file-chooser-dialog-closed") }