file chooser dialog diabled by default.

This commit is contained in:
Miroslav Šedivý 2023-11-24 10:39:09 +01:00
parent d9bcde3331
commit b40c0778c8
7 changed files with 37 additions and 10 deletions

View File

@ -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")
}

View File

@ -20,6 +20,7 @@ type Desktop struct {
InputSocket string
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")
}

View File

@ -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()

View File

@ -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
// 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().

View File

@ -167,7 +167,9 @@ func (manager *WebSocketManagerCtx) Start() {
})
})
if manager.desktop.IsFileChooserDialogEnabled() {
manager.fileChooserDialogEvents()
}
if manager.sessions.Settings().InactiveCursors {
manager.startInactiveCursors()

View File

@ -98,5 +98,6 @@ type DesktopManager interface {
// filechooser
HandleFileChooserDialog(uri string) error
CloseFileChooserDialog()
IsFileChooserDialogEnabled() bool
IsFileChooserDialogOpened() bool
}

View File

@ -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")
}