ahkohd / tauri-macos-spotlight-example

An example macOS Spotlight app built with Tauri
MIT License
148 stars 9 forks source link

Spotlight w/ file picker upload #12

Closed ruoxiaomo closed 11 months ago

ruoxiaomo commented 11 months ago

I have identified a bug:

When using <input type="file"> to select a file, I am unable to choose a file from the popped-up Finder.

Could this issue be addressed? Thank you! ❤️

My macOS version is 12.3.1.

ahkohd commented 11 months ago

The file picker is not working correctly because the spotlight panel level is above that of the file picker level.

The solution is to reduce the spotlight panel level.

https://github.com/ahkohd/tauri-macos-spotlight-example/blob/4468b89f06d567ad74de678a98c1988b6d4a7fcf/src-tauri/src/spotlight.rs#L410

If you change that line to this:

 panel.set_level(NSMainMenuWindowLevel);

or go lower to normal window level:

const NSNormalWindowLevel: i32  = 2;
panel.set_level(NSNormalWindowLevel);

it will work.

ahkohd commented 11 months ago

To add support for file picker upload, here are the steps to carry out:

  1. When you click the file upload button.
  2. Set the spotlight panel to normal window level, panel.set_level(NSNormalWindowLevel), so that the file picker window can show on top of the spotlight window
  3. Set panel.set_auto_hide(false), this prevents the spotlight window from automatically hiding when it resigns as the key window (like blur).
  4. Show the file picker window.
  5. Pick your file.
  6. Reset the spotlight window level back to above the main menu window level, panel.set_level(NSMainMenuWindowLevel + 1).
  7. Reset the panel.set_auto_hide(true), so that the spotlight panel can auto-hide when it resigns as the key window.
ahkohd commented 11 months ago

Screen Recording 2023-11-25 at 9 05 46 PM

The full implementation can be found in the file-upload branch. See commit https://github.com/ahkohd/tauri-macos-spotlight-example/commit/536b35e382c2fc5f810963a2909f440260cc8630 (with explanations) which implements all the steps I mentioned above.

ahkohd commented 11 months ago

The file-upload example branch won't be merged to the main branch. It will be maintained parallel along side with the main branch, as uploading in a spotlight panel is not a very common use case.

ahkohd commented 11 months ago

Let me know if this solves your issue.

ruoxiaomo commented 11 months ago

yeah