godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.29k stars 21.05k forks source link

`filesystem/external_programs/*` doesn't really work on macOS #94173

Open mihe opened 3 months ago

mihe commented 3 months ago

Tested versions

Reproducible in: 4.3.beta [ec02d406ca0b9c822addff49cf58e9a72cf74eb0]

System information

macOS 13.6.7

Issue description

When trying to use the filesystem/external_programs/* editor settings on macOS, like for example filesystem/external_programs/raster_image_editor, there are several issues currently:

  1. When clicking the button next to the setting you're met with a dialog to pick a file, whereas applications on macOS are folders (*.app) (generally located in /Applications) making you have to dig through the *.app folder to look for the relevant binary, of which there may be several.
  2. Even if you point the setting to the appropriate *.app folder, for example /Applications/Adobe Photoshop 2024/Adobe Photoshop 2024.app, it'll open Photoshop when executing the "Open in External Program" action in the FileSystem dock, but it won't actually open the desired file within Photoshop. This is true even if you point the setting to the actual binary within the *.app folder as well.

Note that the second problem doesn't manifest with all applications. Things seem to work fine with Krita for example, but not with Photoshop. Either way, I believe the idiomatic way of opening applications like this on macOS is using /usr/bin/open (which seems to work fine) as opposed to the traditional Unix-style invocation.

It seems to me that the following changes need to be made:

  1. Change these settings to use PROPERTY_HINT_GLOBAL_DIR on macOS.
  2. Ideally have the dialog open in /Applications right away, if possible.
  3. Open the application using open /Applications/Some.app --args /Path/To/File rather than /Applications/Some.app /Path/To/File.

Also note that just using "Open in External Program" without having these settings assigned works fine, as that goes through OS_MacOS::shell_open rather than OS_Unix::create_process, but that requires having assigned the program as the default in macOS, which may not be desirable.

Steps to reproduce

  1. Open any project with a raster image file in it.
  2. Go to "Editor Settings" > "FileSystem" > "External Programs".
  3. Point "Raster Image Editor" to Photoshop (e.g. /Applications/Adobe Photoshop 2024/Adobe Photoshop 2024.app).
  4. Right-click a raster image file in the FileSystem dock.
  5. Click "Open in External Program".
  6. Note how Photoshop launches.
  7. Note how the file itself doesn't open in Photoshop.

Minimal reproduction project (MRP)

N/A

mihe commented 3 months ago

After checking with @bruvzg it seems that the more appropriate fix for this would be to:

  1. Change Godot's file picker to be able to pick bundles (e.g. *.app folders) as well, possibly through a new property.
  2. Have the application be launched using some new OS method, which on macOS would use the NSWorkspace method openURLs:withApplicationAtURL instead.

I'm assuming the change to the file picker should still allow for navigating into the bundle in some way, when necessary, similar to the "Show Package Contents" context action in Finder.

lostminds commented 3 months ago

I agree that NSWorkspace is definitely the way to go with all interactions like this where you want to open files in other applications.

  • Change Godot's file picker to be able to pick bundles (e.g. *.app folders) as well, possibly through a new property.

Regarding the picking of bundles this might be easier to implement via the native file pickers, for example on macOS where these will show and allow .app bundles to be selected as files rather than folders. Similarly other native file pickers might have appropriate modes where you can select applications in the formats they have on that platform.

mihe commented 3 months ago

Regarding the picking of bundles this might be easier to implement via the native file pickers

Using the native file pickers is already a thing through the interface/editor/use_native_file_dialogs editor setting (which is disabled by default) so support for this would likely need to be added to Godot's own file picker anyway.