asticode / go-astilectron-bundler

Bundle your Astilectron app with ease

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

macOS app only starts on second double click

ricoberger opened this issue ยท comments

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: kubenav/kubenav#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.

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 ?

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.

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.

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

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.

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

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.

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 ?

Hi, yes the same is happening for unsigned apps (kubenav/kubenav#108 (comment)):

  • First double click results in the following warning:
    "kubenav.app" cannot be opened because the developer cannot be verified.
    macOS cannot verify that this app is free from malware.
    
    MOVE TO BIN OR CANCEL
    
  • Right click and open, prints the next warning:
    macOS cannot verify the developer of "kubenav.app". Are you sure you want to open it?
    By opening this app, you will be overriding system security which can expose your computer and personal information to malware that may harm your Mac or compromise your privacy.
    
    MOVE TO BIN, OPEN OR CANCEL
    
  • When I click on open, nothing happens
  • Double click again on the app, opens the app

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

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

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.

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 ๐Ÿ™‚

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.

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

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.

Works perfect. Thank you ๐Ÿ™‚