|
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
6 | 6 | <title>Project Name</title> |
7 | 7 | <script> |
8 | | - let windowLabelOfListener, dropMessage, dropProjectMessage, dropMessageOneFile; |
| 8 | + let windowLabelOfListener, dropMessage, dropProjectMessage, dropMessageOneFile, platform; |
9 | 9 | window.__TAURI__.event.listen('tauri://file-drop', (event) => { |
10 | 10 | __TAURI__.window.appWindow.hide(); |
11 | 11 | if(!event || !event.payload || !event.payload.length || !windowLabelOfListener){ |
|
16 | 16 | pathList: event.payload |
17 | 17 | }); |
18 | 18 | }); |
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(); |
21 | 35 | }); |
22 | 36 | window.__TAURI__.event.listen('tauri://file-drop-hover', (event) => { |
23 | 37 | if(!event || !event.payload || !dropProjectMessage || !dropMessage){ |
|
43 | 57 | dropProjectMessage = payload.dropProjectMessage; |
44 | 58 | dropMessageOneFile = payload.dropMessageOneFile; |
45 | 59 | windowLabelOfListener = payload.windowLabelOfListener; |
| 60 | + platform = payload.platform; |
46 | 61 | }); |
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 | + // }); |
65 | 76 | setInterval(async ()=>{ |
66 | 77 | // close window if the metrics hidden window and file drop window is the only one around. |
67 | 78 | const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels'); |
|
0 commit comments