asticode / go-astilectron-bundler

Bundle your Astilectron app with ease
MIT License
127 stars 67 forks source link

macOS app only starts on second double click #75

Closed ricoberger closed 4 years ago

ricoberger commented 4 years ago

Hi, first of all thanks for this awesome project. I'm not 100% sure if this is really an issue with astilectron or with my app.

When I want to run an app builded for macOS, it only starts when I double click it the second time. On the first double click nothing happens. I only can find the following errors in the Console.app:

Jun 19 18:14:48 ricos-mbp com.apple.xpc.launchd[1] (com.apple.xpc.launchd.oneshot.0x100000bc.kubenav[58474]): Service exited with abnormal code: 2
Jun 19 18:15:16 ricos-mbp VTDecoderXPCService[58495]: DEPRECATED USE in libdispatch client: Changing the target of a source after it has been activated; set a breakpoint on _dispatch_bug_deprecated to debug
Jun 19 18:15:16 ricos-mbp VTDecoderXPCService[58495]: DEPRECATED USE in libdispatch client: Changing target queue hierarchy after xpc connection was activated; set a breakpoint on _dispatch_bug_deprecated to debug
Jun 19 18:15:18 ricos-mbp Electron[58487]: assertion failed: 19F101: libxpc.dylib + 92807 [68D433B6-DCFF-385D-8620-F847FB7D4A5A]: 0x87
Jun 19 18:15:21 ricos-mbp com.apple.xpc.launchd[1] (com.apple.mdworker.shared.10000000-0000-0000-0000-000000000000[58498]): Service exited due to SIGKILL | sent by mds[130]

A build where this happens can be found here: https://github.com/kubenav/kubenav/actions/runs/140437555 and the project related issue here: https://github.com/kubenav/kubenav/issues/108

If the app was built locally it works the first time. Also if I run the binary kubenav.app/Contents/MacOS/kubenav from the app directly.

Any ideas why this happens? Thanks in advance for any help.

asticode commented 4 years ago

Mmm unfortunately, your generated app is incompatible with my OS version (my OS version is 10.14.6 and the minimum required OS version is 10.15) therefore I can't reproduce the problem locally 😞

But what happens if, instead of double clicking the first time, you run open <path to kubenav.app> ? Does it show anything interesting ?

ricoberger commented 4 years ago

Hi thanks for the fast reply. If I run the app with open kubenav.app nothing is shown. When I run the command the first time nothing happens, the second time the app is opened.

ricoberger commented 4 years ago

I tried to build the demo app from https://github.com/asticode/go-astilectron-demo. I replaced all my code with the code from the demo. I only use my bundler.json file: https://github.com/ricoberger/kubenav/tree/2.5.0/cmd/electron.

When I want to run the builded app, it also starts only when I double click it the second time.

asticode commented 4 years ago

Could you try removing the info_plist attribute from your bundler.json ? I suspect one its options to cause this... 🤔

ricoberger commented 4 years ago

I removed the info_plist attribute from the bundler.json and also the entitlements.plist which was used during the singing of the app, but the behavior stays the same for my app and the demo app.

asticode commented 4 years ago

When you test with the demo app, are you signing the app ?

ricoberger commented 4 years ago

Yes I use the same workflow as for my app. I just replaced my files with the files from the demo app: https://github.com/ricoberger/kubenav/tree/master/cmd/electron to make sure that it isn't related to my code.

asticode commented 4 years ago

OK then I think this is related to the signing of the app. To be sure, could you omit signing the app and see whether you're experiencing the issue ?

ricoberger commented 4 years ago

Hi, yes the same is happening for unsigned apps (https://github.com/kubenav/kubenav/issues/108#issue-640680353):

asticode commented 4 years ago

Did you enroll in Apple's developer program to get the certificate you use to sign your App ?

ricoberger commented 4 years ago

Yes, I'm enrolled in the Apple developer program and get the certificate from the Apple developer portal.

asticode commented 4 years ago

OK so this has nothing to do with signing the app. Damn.

Can you try logging something to a file in your app, right at the very top of your main function ? to see whether the go code is executed or if MacOSX kills it before.

ricoberger commented 4 years ago

Hi, I think I found the problem with the help of your hint. When I remove the flag.Parse() command from the main function the app starts with the first double click.

Currently I only tested it for the demo app. I will try it also with my app tomorrow. Do you already have an idea why this can be a problem?

Thanks again for your support 🙂

asticode commented 4 years ago

Nice catch! The first scenario that comes to mind is that an additional flag is added by MacOSX on the first double click and it makes GO panic. You can easily validate that by adding that code at the top of your main function :

f, _ := os.Create("/tmp/bundler-issue-75")
defer f.Close()
b, _ := json.Marshal(os.Args)
f.Write(b)

This will log args provided to the binary in a file located at /tmp/bundler-issue-75. That way you can see whether there's an additional flag.

If that's the case, there's an easy solution for that.

ricoberger commented 4 years ago

That's it. For the first start an additional flag -psn_0_6501939 is added.

asticode commented 4 years ago

Ok perfect, take a look at the fix I've just pushed for the demo, it should fix your issue as well. Let me know if you need some explanation.

ricoberger commented 4 years ago

Works perfect. Thank you 🙂