Recently I upgraded to Mac OS High Sierra and after the upgrade Geany will open a new instance when opening some xml's. The behaviour seems random, out of 10 XML files, 3 of them opens a new instance while the other 7 opens inside the already open instance.
I can't explain it and tried to search for the issue with no luck. Can I provide a log or any other information?
Tried to find a pattern for which files opens in a new instance. My OP implies all vector drawables, but it turns out not all vector drawables opens in a new instance. For exempel, I have four nearly identical files, in the same folder, and two opens in new separate instances and the other two in the already opened main instance.
@PerLycke How do you open the XMLs? By double-clicking in Finder, dragging them to Geany icon in the launcher, or using File->Open?
Anyway, from your description it sounds strange - Geany itself should treat all the XMLs equally so it must be something specific to High Sierra.
@techee I'm opening them by double-clicking the file in finder. I made a screen-recording to show when it happens:
https://www.dropbox.com/s/i3c58o32yrjdmoj/xml_open.mov?dl=0
File -> open, and dragging them into the already open Geany window, don't make it open a new instance. It's just that the double click in finder started behaving like this. I've used Geany for many years and always opened files from finder, this never happened before
I've just tried this also on Android xml drawable resources and can't reproduce it here.
You might try to reset the file association by control-clicking the file in Finder, selecting Get Info and making sure Geany is selected in "Open with". Also you can press the "change all" button. I don't know if macOS tries to be "intelligent" and can distinguish various types of XML files - maybe for some of the XMLs it thinks it's another type of XML and launches Geany in some "special" way.
But again, it's more like a macOS thing than a Geany thing - Geany doesn't care what file you open and it shouldn't affect how it's launched.
I tried that but didn't help. Just for testing purpose, I set another application as default for XML. And it works fine with that application, all files opens in the same instance. Changing back to Geany, and the problem is there again.
As you say, should be the Mac OS, but still I'm surprised this happens only with Geany
Hmm, no more ideas, sorry. The most puzzling thing is that one xml opens in the same instance of Geany while other from the same directory in a new one and there seems to be no difference between them...
I don't know if it's possible or would be relevant, but maybe there's 2 concurrent installations of Geany and not all files open with the same one, creating strange behavior?
Or different users or different config files.
@techee @b4n @elextr
I think I figured this out, but can't find a way to fix it. All XML files downloaded from the internet will open in a new instance. For exempel, I use this online converter to convert svg to Android xml drawable: http://inloop.github.io/svg2android/
Every xml I converted and downloaded from there will open in a new instance when double clicked in finder, or dragged to the Geany icon in the dock. Same issue with xml's downloaded elsewhere from the internet. A locally created and saved xml will open in the main instance like it should.
I understand this is a Mac OS side thing, but strange thing is that if I set the default application to Textwrangler, or any other text editor, they open in the same instance.
Are the files that open differently detected as the same mime type?
XML is used for lots of things, and the mime type detector can tell them apart from the contents, there is not one "XML" type, see [here](https://en.wikipedia.org/wiki/XML_and_MIME). And each mime type can have a different opening command configured.
If they are different mime types they may have different geany commands configured?
@PerLycke Thanks, that was it - I can reproduce it now. The very first time the file is edited and saved, it starts opening in the same instance. I suspect macOS does something similar to e.g. downloaded binaries where it warns users that they are about to run a file downloaded from the Internet and in the case of xml probably launches the associated application in a different way. I'll try to investigate what's going on.
OK, I know what's going on now but don't have a good solution for the problem. For non-downloaded XMLs the files to be opened are passed as Geany command line arguments and everything works as on linux - they are passed to the existing Geany instance through the socket. However, with the downloaded XMLs the files to be opened aren't for some reason passed as arguments but later through the callback here:
https://github.com/geany/geany/blob/master/src/osx.c#L111
This means that argc==0 and no sending through sockets is performed here
https://github.com/geany/geany/blob/master/src/libmain.c#L1096
and new instance of Geany is started. The problem is that at the time when main() is run we don't know if Geany is going to receive the files to be opened through the callback or not. It's only later when we start receiving the callback but at this point Geany UI is already displayed.
Thanks for the explanation. Crossing fingers there'll be a solution in the future
@techee can you configure the command OSX uses to start the application in weird mode? If so you could add a command line option to say "don't open the UI, just lurk waiting for the callback".
Or if the socket exists and no files are provided, don't start the UI, but only on OSX. On Linux it makes no sense to start Geany with no files when a socket is open, so it acts as if `-i` was given. Maybe that should be different on OSX.
One issue would be are all files given in one callback so Geany can safely close after it, or is each file a separate callback in which case you can't tell if you have them all to exit.
@elextr The problem with your suggestions is that I can't distinguish the "weird mode" from an ordinary creation of new Geany instance which is also possible and useful. You can create a new instance by right-clicking Geany icon in the launcher and selecting "new window" and this one is also started without any parameters.
So to summarise:
Option | Action | Command ----------|----------|-------------- 1 | Click on launcher | `geany` 2 | Click on local file | `geany filename` 3 | Click on remote file | `geany` and filename via callback
Option three sort of makes sense, that way the application can start in parallel with the download so its faster, think of opening something like office. But surely it doesn't open a new instance of office each remote file the user clicks? Surely it is supposed to call the callback on the existing instance?
If option 3 cannot have its command configured and uses the same configuration as option one then you are screwed. Whilst you could check the socket in the callback and pass the filename on, you are still gonna get the UI opening. And if the user selects several files, will you get several callbacks? If so how do you know when you have them all?
I would just correct the table - option 3 isn't for a remote file. It's for local file which has been downloaded by a browser and hasn't been edited yet. And I think this is related to security - I believe Apple fears that users could associate files with some interpreter and then just by double-clicking the downloaded file it would get executed.
There's also: Option 4 - file dragged to Geany launcher icon - if not running, geany is launched and callback is called Option 5 - file dragged to Geany window - the callback is called
The problem with Geany is that it isn't a native macOS application. Instead of launching the binary directly, macOS launches a shell script which sets various environment variables and then launches the Geany process with normal shell exec command. On the other hand when you double-click an application bundle of a native macOS application, it won't create a new process if some instance is already running (no socket like Geany uses is needed) so native applications don't have this problem.
Your last paragraph pretty much summarises what I think is the situation Geany is facing and I don't see a solution.
Ok, so "all" you need is a "proper" OSX program which follows the OSX rules and gets the callbacks using proper OSX calls and which then starts Geany(s) via script and communicates via the socket. Easy :grin:
What about having Geany not open a new instance when it's called with no files under OSX, but just do as if files were passed (but none are), so activating the main window and stuff? The "open new instance" would use `-i` anyway, so no problem there. The Geany behavior with no arguments is not very common I think, many programs just activate their window, trying to raise it -- or like GEdit open a new untitled file in the existing window.
Would that solve the issue and the running Geany instance would get the callback, or would it just be lost?
The "open new instance" would use -i anyway, so no problem there.
If I understand @techee comments above, OSX does not allow configuring a different command for making a new instance from the command for "open and I am gonna send you filenames via callback" so you can't have one with `-i` and one without.
What about having Geany not open a new instance when it's called with no files under OSX, but just do as if files were passed (but none are), so activating the main window and stuff?
I'm not sure I understand - do you mean somehow forwarding the stuff to the main instance from the script? I don't know how to do that - from OS X perspective a new process was successfully started - and it's the script - so when the script terminates the process is dead from the OS X perspective and it won't receive the callback.
The problem is that OS X seems to do two different things when launching applications - when it's a native application, it won't launch a new instance of it from the bundle and there must be something within the application which makes new instances. But when it starts a script and probably also some command-line application too, it launches it every time. And we need the script because all the simulated GTK environment has to be set up there.
The problem is that OS X seems to do two different things when launching applications - when it's a native application, it won't launch a new instance of it from the bundle and there must be something within the application which makes new instances. But when it starts a script and probably also some command-line application too, it launches it every time. And we need the script because all the simulated GTK environment has to be set up there.
Yeah, thats why I suggested above that there needs to be a native app that actually starts and communicates with real Geany.
I have defined an alias on my shell to start Geany via terminal:
`alias geany="open -a geany"`
but pretty much the same behavior.
What happens when, instead, you create a symlink to
/Applications/Geany.app/Contents/MacOS/geany
and put it somewhere on your path? This should make sure the script is launched normally (at least for the non-downloaded files).
No difference. I tried to set —socket-file but this didn't help neither.
Have you removed the alias and restarted the terminal to make sure it's not the alias but the command in the path which is used?
Yes, I did.
``` flanitz@Franks-MacBook-Pro ~> alias | grep geany flanitz@Franks-MacBook-Pro ~> alias | grep open 1 flanitz@Franks-MacBook-Pro ~> geany --verbose 1 2017-12-01 16:17:18.666 geany-bin[21088:5818844] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. Geany-INFO: Geany 1.32, en_US.UTF-8 Geany-INFO: GTK 2.24.31, GLib 2.52.2 …. ```
Funny thing: When opening Geany with an file it's working. Only if i choose no file a new instance is used.
No idea - can't reproduce it here :-(
Funny thing: When opening Geany with an file it's working. Only if i choose no file a new instance is used.
isn't that the default Geany behavior in any OS?
Funny thing: When opening Geany with an file it's working. Only if i choose no file a new instance is used.
isn't that the default Geany behavior in any OS?
It doesn't happen on my machine - when Geany is already running, invoking it again from the terminal doesn't create a new instance. In general, macOS tries to keep one instance of every application so other applications work the same way too.
@techee I don't know if it's related at all, or if it could help in any way, but Chrome had a similar issue where it would open a new instance: "LaunchServices tries to open a second instance of Chromium". They committed a change with an attempt to fix this:
https://chromium.googlesource.com/chromium/src.git/+/fe15df9c055bb0c48e94aa9...
@PerLycke Thanks for the link. Most of the patch seems to be specific to Chromium but the call of `activateIgnoringOtherApps:`
https://developer.apple.com/documentation/appkit/nsapplication/1428468-activ...
might be worth experimenting with (at least it seems related to what we do but I'm not sure if it helps in this case). I'll try it when I have time.
@techee no new ideas about this?
I believe this issue is fixed in the latest release based on GTK 3. Feel free to reopen this issue if you still experience the issue.
Closed #1619.
github-comments@lists.geany.org