Skip to content

Commit

Permalink
fix(DragEvent): Fix drag event on Linux (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgmarchi authored Nov 22, 2023
1 parent 18fa0f1 commit 190d4af
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ui/src/components/files/upload_progress_bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use dioxus_desktop::wry::webview::FileDropEvent;
use dioxus_desktop::{use_window, DesktopContext};
use kit::elements::{button::Button, Appearance};

use crate::utils::get_drag_event::BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX;
use crate::utils::{
get_drag_event,
verify_valid_paths::{decoded_pathbufs, verify_paths},
Expand Down Expand Up @@ -256,6 +257,9 @@ async fn drag_and_drop_function(
if verify_paths(&paths) {
let new_files_to_upload = decoded_pathbufs(paths);
*files_ready_to_upload.write_silent() = new_files_to_upload;
if cfg!(target_os = "linux") {
*BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX.write() = false;
}
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/utils/get_drag_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub fn get_drag_event() -> FileDropEvent {

pub static DRAG_EVENT: Lazy<RwLock<FileDropEvent>> =
Lazy::new(|| RwLock::new(FileDropEvent::Cancelled));

pub static BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
24 changes: 21 additions & 3 deletions ui/src/webview_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::get_drag_event::DRAG_EVENT;
use crate::utils::get_drag_event::{BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX, DRAG_EVENT};
use common::STATIC_ARGS;
use dioxus_desktop::Config;
use dioxus_desktop::{wry::webview::FileDropEvent, Config};
use warp::logging::tracing::log;

pub(crate) fn webview_config() -> Config {
Expand All @@ -25,7 +25,25 @@ pub(crate) fn webview_config() -> Config {
)
.with_file_drop_handler(|_w, drag_event| {
log::info!("Drag Event: {:?}", drag_event);
*DRAG_EVENT.write() = drag_event;
if cfg!(target_os = "linux") {
match drag_event {
FileDropEvent::Hovered { .. } => {
*BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX.write() = false;
*DRAG_EVENT.write() = drag_event;
}
FileDropEvent::Dropped { .. } => {
*BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX.write() = true;
*DRAG_EVENT.write() = drag_event;
}
_ => {
if !*BLOCK_CANCEL_DRAG_EVENT_FOR_LINUX.read() {
*DRAG_EVENT.write() = FileDropEvent::Cancelled;
}
}
};
} else {
*DRAG_EVENT.write() = drag_event;
}
true
})
.with_disable_context_menu(false);
Expand Down

0 comments on commit 190d4af

Please sign in to comment.