wails
wails copied to clipboard
Open a file from Finder/Explorer
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
From the native OS Finder/Explorer the user can open a file in the a wails app. On mac this might mean using the right-click menu and selecting "Open with..." and then a wails app.
If the wails app is registered as the default handler for a specific file type, simply double-clicking on a file from Finder/Explorer should open it in the wails app.
Electron has some prior art here, although an ideal solution for wails/go might look different: https://www.electronjs.org/docs/latest/api/app#event-open-file-macos
Describe alternatives you've considered
No alternatives known other than using something besides Wails.
Additional context
There's also a related discussion: https://github.com/wailsapp/wails/discussions/1829
Wails is currently great for putting a UI on top of a web app or some Go functionality, however, its capabilities would be significantly expanded (IMO) if Wails apps could handle files the same way native apps do. Certain use-cases likely will not be possible otherwise.
Thanks for opening this! I was certain there was a ticket for it already but this is great! I've got code for this on Mac but will need to look into what's available on Windows and Linux. If you have any information on that, please feel free to add it to the ticket. I've scheduled it in for v2.1 👍
Thanks! Sorry, I don't have any info regarding win/lin. I primarily use mac for GUI-related stuff.
On linux I think there is two ways to do this, one of which needs root permission. (I'm no expert, this is how I use it.)
By "hand"
This registers the app for the current user only!
- You need a *.desktop file for the application.
- Copy the *.desktop file to
~/.local/share/applications
- Add a new line to
~/.local/share/applications/defaults.list
like{your mime type}=myapp.desktop
By xdg-mime
- You need a *.desktop file for the application.
- Create a file type xml for you'r filetype if needed:
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/wails">
<comment>MyApp</comment>
<glob pattern="*.wails"/>
</mime-type>
</mime-info>
- Register the new mime type:
sudo xdg-mime install --mode system MyApp-wails.xml
- Make your app default:
sudo xdg-mime default myapp.desktop text/wails
- Add your icon for it with:
xdg-icon-resource
(never really figured it out)
Edit: But probably this should be a post install script for a *.deb file or something, not really an integral part of wails.
@Lyimmi This thread looks a bit inactive. Is someone working on this? If not, I would like to pick this up.
@sriramr98 hi, feel free to pick this up.
macOS specific: I was able to edit the Info.plist
file just fine to associate a Wails app with .deb
files:
<key>NSHumanReadableCopyright</key><string>{{.Info.Copyright}}</string>
+ <key>CFBundleDocumentTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>deb</string>
+ </array>
+ </dict>
+ </array>
</dict></plist>
And this works - I can double-click on a .deb
file, or right-click, Open With, and it shows up. BUT macOS doesn't simply send through the filename as a command-line argument and I get an error/warning message: The document “whatever.deb” could not be opened. deb-view cannot open files of this type.
See https://apple.stackexchange.com/questions/370427/what-does-macos-actually-do-when-open-a-file
To allow a macOS Wails app to handle opening a file from Finder it would need to handle these messages.
I'm leaving below some links I found under a brief search that might shed a light for when developing for Windows:
- https://stackoverflow.com/questions/20449316/how-add-context-menu-item-to-windows-explorer-for-folders
- https://stackoverflow.com/questions/212906/script-to-associate-an-extension-to-a-program
- https://stackoverflow.com/questions/10686411/create-windows-right-click-context-menu-for-specific-folders
- https://stackoverflow.com/a/3788554 (it's a C# question, but the guy talks about registry keys)