Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set browserWindow Always on top, even other app is in fullscreen [Electron, MAC OS]

it's possible to use custom window level in Electron Framework, for make window always on top, even other apps is in fullscreen ?

For native MacOS apps i found this: https://stackoverflow.com/a/27397096/5838242

Where he saying:

window.level = Int(CGWindowLevelForKey(kCGMaximumWindowLevelKey))

On electron, i have a browser window:

mainWindow = new BrowserWindow({width: 1400, height: 50, resizable: false, alwaysOnTop: true, y: 0, x: 0, minimizable: false, title: 'CD App', frame: false, titleBarStyle: 'hidden', type: 'desktop' });

I know the 'type' parameter is the POINT, but this parameter have just two options:

On macOS, possible types are desktop, textured. The textured type adds metal gradient appearance (NSTexturedBackgroundWindowMask). The desktop type places the window at the desktop background window level (kCGDesktopWindowLevel - 1). Note that desktop window will not receive focus, keyboard or mouse events, but you can use globalShortcut to receive input sparingly.

So, any possibilities to do this thing ?

like image 406
Paulo Rodrigues Avatar asked Oct 03 '16 15:10

Paulo Rodrigues


1 Answers

As of Electron 1.4.2 the setAlwaysOnTop() API takes an optional level parameter to adjust the window level, you'd use it like so:

mainWindow = new BrowserWindow({ ... });
mainWindow.setAlwaysOnTop(true, 'screen');

See the docs for all the possible values of the optional parameter, I'm not sure screen is the one you want in this case, you'll need to experiment.

like image 137
Vadim Macagon Avatar answered Sep 28 '22 16:09

Vadim Macagon