Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
file chooser dialog diabled by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Nov 24, 2023
1 parent d9bcde3 commit b40c077
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
8 changes: 8 additions & 0 deletions internal/api/room/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down
9 changes: 8 additions & 1 deletion internal/config/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type Desktop struct {
UseInputDriver bool
InputSocket string

Unminimize bool
Unminimize bool
FileChooserDialog bool
}

func (Desktop) Init(cmd *cobra.Command) error {
Expand All @@ -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
}

Expand Down Expand Up @@ -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")
}
4 changes: 4 additions & 0 deletions internal/desktop/filechooserdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions internal/desktop/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
4 changes: 3 additions & 1 deletion internal/websocket/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (manager *WebSocketManagerCtx) Start() {
})
})

manager.fileChooserDialogEvents()
if manager.desktop.IsFileChooserDialogEnabled() {
manager.fileChooserDialogEvents()
}

if manager.sessions.Settings().InactiveCursors {
manager.startInactiveCursors()
Expand Down
1 change: 1 addition & 0 deletions pkg/types/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ type DesktopManager interface {
// filechooser
HandleFileChooserDialog(uri string) error
CloseFileChooserDialog()
IsFileChooserDialogEnabled() bool
IsFileChooserDialogOpened() bool
}
13 changes: 7 additions & 6 deletions pkg/xevent/xevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

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

Expand Down

0 comments on commit b40c077

Please sign in to comment.