Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.dock.hide() crash on OS X Catalina when running as root #19896

Closed
3 tasks done
nicko2n opened this issue Aug 22, 2019 · 9 comments
Closed
3 tasks done

app.dock.hide() crash on OS X Catalina when running as root #19896

nicko2n opened this issue Aug 22, 2019 · 9 comments

Comments

@nicko2n
Copy link

nicko2n commented Aug 22, 2019

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    6.0.3. Also observed on 4.2.9
  • Operating System:
    OSX Catalina 10.15 Beta (19A536g)
  • Last Known Working Electron version:
    Can't reproduce on non-Catalina variants of OSX - at least Yosemite and High Sierra

Expected Behavior

App icon not shown in Dock

Actual Behavior

Error message followed by Electron app crash

2019-08-22 13:18:37.765 Electron[73668:2759878] -[__NSCFConstantString objectAtIndex:]:
unrecognized selector sent to instance 0x7fff9812d5c0

To Reproduce

App crashes when calling app.dock.hide() but only when running as root, e.g. started as a service by launchd.

package.json:
{
"name": "electron-dock",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^6.0.3"
}
}

main.js:
const {app, BrowserWindow} = require('electron')
app.dock.hide()
console.log('reached')
process.exit(0)

As non-privileged user:
$ npm start

electron-dock@1.0.0 start /path/to/app
electron .
reached

As root, via sudo
$ sudo npm start

electron-dock@1.0.0 start path/to/app
electron .
reached

As root, via su - (or via launchd)

$ sudo su -
root# npm start

electron-dock@1.0.0 start /path/to/app
electron .

2019-08-22 13:23:11.096 Electron[73780:2762770] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff9812d5c0

Additional Information

My app crashes with "Illegal instruction: 4" after printing the error message but the example above doesn't; not sure what the difference is.

Unsure why it runs ok via "sudo npm start", but not after "sudo su -" . It doesn't appear to be related to differenced in environment variables.

Reproduced on two OS X laptops, but on Catalina only (latest beta as of submission).

@nicko2n
Copy link
Author

nicko2n commented Aug 29, 2019

Issue still present after upgrading to the new beta (beta 7) of Catalina.

The instance in the error message changed:
2019-08-29 09:18:12.058 Electron[2596:29096] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff92fed090

@nicko2n
Copy link
Author

nicko2n commented Sep 17, 2019

Reproduced in MacOS build 19A558d.

2019-09-17 10:50:09.630 Electron[1498:12005] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff91c2f340

@nicko2n
Copy link
Author

nicko2n commented Sep 25, 2019

Reproduced with beta 9 (build 19A573a)

2019-09-25 09:49:15.316 Electron[1812:21458] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff90409c60

@nicko2n
Copy link
Author

nicko2n commented Oct 9, 2019

Reproduced in the launch release of Catalina
2019-10-08 20:57:34.071 Electron[1855:17634] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff96e26040

@codebytere
Copy link
Member

Unfortunately this is a wontFix on our end - not because we don't wish to but because for consumer apps, Apple as a company allows very little control over the Dock, and the way that an app exists on it. Apps can only set, by normal means, one of a few activation policies:

// The application is an ordinary app that appears in the Dock and may
// have a user interface.
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];

// The application does not appear in the Dock and does not have a menu
// bar, but it may be activated programmatically or by clicking on one
// of its windows.
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];

// The application does not appear in the Dock and may not create
// windows or be activated.
[NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];

but we in Electron want to provide you more granular access, so we hook into slightly lower level components. Unfortunately, the above is a side effect of us allowing you to have more control at all. As such, i'm going to label this a wont-fix and close it out.

@ghost
Copy link

ghost commented Jan 29, 2020

@codebytere
Thanks a lot for this info, just came across this issue on our tests in Catalina.
My code in main.js just has this:

app.dock.hide()

The app I'm working on does not have a menu and it should not show it the Dock, it is very basic and must be called from root.

How could apply the this bit in the app code, please?
// The application does not appear in the Dock and does not have a menu
// bar, but it may be activated programmatically or by clicking on one
// of its windows.
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];

Sorry for the newbie question, just learning about this great way to create macOS apps.

Thank you for any input.
Regards,
Mauricio

@codebytere
Copy link
Member

@MauricioFauth that's a great question - it's definitely possible and i'm open to considering it! Could you please open a new issue as a feature request? Specifically, a request for the ability to control app activation policy on macOS?

@ghost
Copy link

ghost commented Jan 30, 2020

@codebytere Thank you very much for considering this. Let me know if you need further information and, as a newbie, if I did something wrong.
Kind regards
Mauricio

@threatstop
Copy link

Thank you for the update.

With the info you provided, I was able to workaround the issue by adding
"mac": {
"extendInfo": {
"LSUIElement": 1
}
}
to my electron-builder config. Now the electron-based app launched via launchd doesn't pop-up in the dock when it's run.

I second the request to be able to do this using the electron API instead of enforcing it via the app's plist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants