Skip to content

Commit 40e6f87

Browse files
brackets-ioabose
authored andcommitted
fix: windows drop window render issues
1 parent c87089e commit 40e6f87

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/drop-files.html

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Project Name</title>
77
<script>
8-
let windowLabelOfListener, dropMessage, dropProjectMessage, dropMessageOneFile;
8+
let windowLabelOfListener, dropMessage, dropProjectMessage, dropMessageOneFile, platform;
99
window.__TAURI__.event.listen('tauri://file-drop', (event) => {
1010
__TAURI__.window.appWindow.hide();
1111
if(!event || !event.payload || !event.payload.length || !windowLabelOfListener){
@@ -16,8 +16,22 @@
1616
pathList: event.payload
1717
});
1818
});
19-
window.__TAURI__.event.listen('tauri://file-drop-cancelled', (event) => {
20-
//__TAURI__.window.appWindow.hide();
19+
window.addEventListener('mouseout', function(_event) {
20+
__TAURI__.window.appWindow.hide();
21+
});
22+
window.__TAURI__.event.listen('tauri://file-drop-cancelled', (_event) => {
23+
// usually in mac, when the drag leaves the window, we would get a mouseout event. this doesnt
24+
// happen in windows as tauri has a custom hwnd window overlay over this dop window and appear
25+
// to be swallowing the mouse out events. So we listen to tauri's drop cancelled event instead
26+
// on windows only.
27+
if(platform === "win") {
28+
// in windows, tauri drop work differently, we have to do this to prevent the drop window not
29+
// disappearing on mouse out.
30+
__TAURI__.window.appWindow.hide();
31+
}
32+
});
33+
window.addEventListener('click', ()=>{
34+
__TAURI__.window.appWindow.hide();
2135
});
2236
window.__TAURI__.event.listen('tauri://file-drop-hover', (event) => {
2337
if(!event || !event.payload || !dropProjectMessage || !dropMessage){
@@ -43,25 +57,22 @@
4357
dropProjectMessage = payload.dropProjectMessage;
4458
dropMessageOneFile = payload.dropMessageOneFile;
4559
windowLabelOfListener = payload.windowLabelOfListener;
60+
platform = payload.platform;
4661
});
47-
window.addEventListener('mouseout', function(event) {
48-
// Check if the mouse is leaving the window (relatedTarget is null)
49-
__TAURI__.window.appWindow.hide();
50-
});
51-
window.addEventListener('dragleave', ()=>{
52-
//__TAURI__.window.appWindow.hide();
53-
});
54-
window.addEventListener('dragend', ()=>{
55-
//__TAURI__.window.appWindow.hide();
56-
});
57-
window.addEventListener('click', ()=>{
58-
__TAURI__.window.appWindow.hide();
59-
});
60-
document.addEventListener('visibilitychange', () => {
61-
if (document.hidden) {
62-
//__TAURI__.window.appWindow.hide();
63-
}
64-
});
62+
63+
// The below code is commented as it was causing flicker issues in some platforms. IF adding these below
64+
// event handlers, tread carefully.
65+
// window.addEventListener('dragleave', ()=>{
66+
// //__TAURI__.window.appWindow.hide();
67+
// });
68+
// window.addEventListener('dragend', ()=>{
69+
// //__TAURI__.window.appWindow.hide();
70+
// });
71+
// document.addEventListener('visibilitychange', () => {
72+
// if (document.hidden) {
73+
// //__TAURI__.window.appWindow.hide();
74+
// }
75+
// });
6576
setInterval(async ()=>{
6677
// close window if the metrics hidden window and file drop window is the only one around.
6778
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');

src/utils/DragAndDrop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ define(function (require, exports, module) {
256256
dropMessage: Strings.DROP_TO_OPEN_FILES,
257257
dropMessageOneFile: Strings.DROP_TO_OPEN_FILE,
258258
dropProjectMessage: Strings.DROP_TO_OPEN_PROJECT,
259-
windowLabelOfListener: window.__TAURI__.window.appWindow.label
259+
windowLabelOfListener: window.__TAURI__.window.appWindow.label,
260+
platform: Phoenix.platform
260261
});
261262
if (isSameSize && isSamePosition && (await fileDropWindow.isVisible())) {
262263
return; // Do nothing if the window is already at the correct size and position and visible

0 commit comments

Comments
 (0)