callum
callum

Reputation: 37759

How to avoid showing a Dock icon while my Electron app is launching on macOS?

When creating a new BrowserWindow, you can set skipTaskbar: true to prevent it appearing in the Windows taskbar. But this doesn't work for the Dock on macOS.

For macOS we have app.dock.hide(), but it's not quite the same: it only hides the icon after your Electron app is launched. Even if you call app.dock.hide() as the very first thing in your main process, the Dock icon briefly appears and then disappears, which is something I want to avoid. (I want my app to only ever appear in the menu bar, similar to apps like Dropbox.)

After some more digging, I found this issue comment on the electron-builder project, which suggests the problem can be solved by setting "LSUIElement": 1 in an Info.plist file included in your bundled app distribution. Apple's docs for LSUIElement say this setting will indeed make the app run as an "agent app", which seems to be what I want.

Is there any way to provide this Info.plist setting in development, e.g. as a launch parameter for the electron CLI when running my app from source? Or is it really only possible to do it by bundling a full release and adding an Info.plist file?

Upvotes: 10

Views: 2934

Answers (1)

Chan Jing Hong
Chan Jing Hong

Reputation: 2461

You could use the property build.mac.extendInfo in package.json for additional settings to be added to Info.plist. https://www.electron.build/configuration/mac

Below is a sample of adding LSUIElement to the Mac's build settings in package.json.

"build": {
    "mac": {
        // ... other settings
        "extendInfo": {
            "LSUIElement": true
        }
    }
    // ... other settings
}

Upvotes: 1

Related Questions