Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

electron

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?

like image 349
callum Avatar asked Jan 09 '20 16:01

callum


People also ask

How do I hide app icons on Mac Dock?

On your Mac, choose Apple menu > System Preferences, then click Dock & Menu Bar . In the Dock & Menu Bar section in the sidebar, change the options you want. For example, you can change how items appear in the Dock, adjust its size, locate it along the left or right edge of the screen, or even hide it.

Is there a way to keep an icon of each window separately on Mac Dock?

Right click on the Dock, select "Dock Preferences", and from there, uncheck the box that says "Minimize windows over the icon of the application". That will make that every instance of an app have its dedicated icon on the right side of the Dock (to the left of the Trash App icon).

Why does my Mac keep apps on the Dock?

In macOS Mojave, a new “recent apps” section keeps icons in your dock even after the app is closed. This feature does more than simply moving open, non-pinned application icons to a new place. It also keeps the icons in your Dock after you've closed the application.

What is bounce icon on Dock?

This means that particular application needs you—click on the jumping icon and that application will “come forward.” Then you will probably see a message on the screen that needs to be taken care of, such as “Do you want to save this document” or “This application couldn't do what you wanted.” Just do what it wants you ...


1 Answers

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
}
like image 57
Chan Jing Hong Avatar answered Jan 04 '23 14:01

Chan Jing Hong