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

setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }) api cause app dismiss in macOS dock #26350

Open
3 tasks done
fanlion opened this issue Nov 5, 2020 · 41 comments
Labels

Comments

@fanlion
Copy link

fanlion commented Nov 5, 2020

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:
    • 10.1.5
  • Operating System:
    • macOS 10.15.7 (19H2)
  • Last Known Working Electron version:
    • unknow

Expected Behavior

after setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }) , app should visible in macOS dock

Actual Behavior

after setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }) , app is invisible in macOS dock

To Reproduce

  1. git clone https://github.com/electron/electron-quick-start
  2. add mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); in main.js
  3. yarn start
  4. watch your macOS dock

Screenshots

Additional Information

maybe it cause by visibleOnFullScreen: true,when app‘s icon dismiss from dock, app.dock.show() is not work. electron@9.2.1 is work, but visibleOnFullScreen: true is removed.

@jkleinsc jkleinsc added the 10-x-y label Nov 5, 2020
@asc0910
Copy link

asc0910 commented Nov 6, 2020

Same with electron9.3.3

void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible,
                                                bool visibleOnFullScreen) {
  // In order for NSWindows to be visible on fullscreen we need to functionally
  // mimic app.dock.hide() since Apple changed the underlying functionality of
  // NSWindows starting with 10.14 to disallow NSWindows from floating on top of
  // fullscreen apps.
  ProcessSerialNumber psn = {0, kCurrentProcess};
  if (visibleOnFullScreen) {
    [window_ setCanHide:NO];
    TransformProcessType(&psn, kProcessTransformToUIElementApplication);
  } else {
    [window_ setCanHide:YES];
    TransformProcessType(&psn, kProcessTransformToForegroundApplication);
  }

  SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces);
  SetCollectionBehavior(visibleOnFullScreen,
                        NSWindowCollectionBehaviorFullScreenAuxiliary);
}

This makes the app dismiss from dock.

TransformProcessType(&psn, kProcessTransformToUIElementApplication);

No idea without setting this?

@oltreseba
Copy link

oltreseba commented Nov 25, 2020

It looks like it's happening in electron 11.0.3 as well.

It was working fine in electron 9.1.1

@yarinsa
Copy link

yarinsa commented Jan 19, 2021

try to use electron-panel-window to prevent this behavior

@oltreseba
Copy link

I don't think this is currently a doable way as:

@lacymorrow
Copy link

The visibleOnFullScreen option was removed from setVisibleOnAllWorkspaces in this PR: #21706

@jetlej
Copy link

jetlej commented Apr 29, 2021

@lacymorrow I still see it in the docs. What would that accomplish anyways?

@kylefoo
Copy link

kylefoo commented Oct 20, 2021

it is brought back again, see: #24956

@keyurchitroda
Copy link

I'm using screenWindow.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true}); for window visible on full screen. it's working fine. but app is invisible in macOS dock . If i remove {visibleOnFullScreen: true} then app is visible in macOS dock. but window invisible on full screen. please share me solution if anyone have idea about that. i'm using electron version 11.5.0.

@lacymorrow
Copy link

This is an OLD bug with Electron, I have this piece of code in my app:

	// Enables staying on fullscreen apps for macos https://github.com/electron/electron/pull/11599
	app.dock.hide()

	// VisibleOnFullscreen removed in https://github.com/electron/electron/pull/21706, still does things for old versions
	win.setVisibleOnAllWorkspaces( true, { visibleOnFullScreen: true } )

	// If we wanted a dock, we can use it now: https://github.com/electron/electron/pull/11599
	app.dock.show()

I believe hiding dock before setVisibleOnAllWorkspaces then showing dock is the workaround.

@keyurchitroda
Copy link

keyurchitroda commented Apr 8, 2022

I was trying this solution,
but if i implement app.dock.show() ,
this win.setVisibleOnAllWorkspaces( true, { visibleOnFullScreen: true } ) functionality is not working , means window is invisible on full screen.

@lacymorrow
Copy link

lacymorrow commented Apr 8, 2022

There is no way to make an electron window visible above all fullscreen window.

Believe me, I've tried. The best you'll get is

// Values include normal, floating, torn-off-menu, modal-panel, main-menu, status, pop-up-menu, screen-saver
targetWindow.setAlwaysOnTop( true, 'screen-saver' )

If you ever figure it out, please let me know.
lacymorrow/crossover#64

@kyle-go
Copy link

kyle-go commented May 17, 2022

@lacymorrow
Finally, I found a way to make an electron window visible above all fullscreen window.

const options = {
    width: 240,
    height: 80,
    show: false,  //  !!!!!!!!!!!!!!!!! IMPORTANT, MUST SET HIDE BEFORE call setVisibleOnAllWorkspaces
    webPreferences: {
      nodeIntegration: false,
      nodeIntegrationInWorker: false,
      contextIsolation: false,
      preload: path.join(__dirname, 'preload.js'),
      nativeWindowOpen: true,
      enableRemoteModule: true,
    },
    resizable: false,
    minimizable: false,
    maximizable: false,
    acceptFirstMouse: true,
    movable: true,
    alwaysOnTop: true,
    fullscreenable: false,
    frame: false,
  };
  floatingBarWindow = new BrowserWindow(options);
  floatingBarWindow.loadURL(
      prepareURL([__dirname, 'index.html'], { theme })
  );

  floatingBarWindow.setVisibleOnAllWorkspaces(true,{visibleOnFullScreen:true});

  floatingBarWindow.on('closed', () => {
    floatingBarWindow = null;
  });

  floatingBarWindow.on('ready-to-show', ()=>{
    floatingBarWindow.show();
    app.dock.show(); // SHOW IT!, because setVisibleOnAllWorkspaces will cause app icon dismiss
  })

Last update(2022-06-07):
Sorry, the code above is only work for special macOS version. And the 'app.dock.show()' will take some other problem.
Yes, I think lacymorrow is right. The api setVisibleOnAllWorkspaces not work properly.

@lacymorrow
Copy link

@kyle-go Do you have an example repo to test/reproduce with?

@shivam-bit
Copy link

@kyle-go any update on this?

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2022

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Oct 6, 2022
@kyle-go
Copy link

kyle-go commented Oct 6, 2022

bump

@github-actions github-actions bot removed the stale label Oct 7, 2022
@lacymorrow
Copy link

bump

2 similar comments
@killaragorn
Copy link

bump

@jordancde
Copy link

bump

@johnnyopao
Copy link

Ran into this and found a configuration that seems to work.

The key seems to be not setting fullscreenable when you init the window and instead do it after configuring setVisibleOnAllWorkspaces + visibleOnFullScreen

  window = new BrowserWindow({
    // DO NOT set fullscreenable here
    // fullscreenable: false,
  });

  window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

  // NOTE: Make sure this is called after setVisibleOnAllWorkspaces + visibleOnFullScreen
  // otherwise it will not actually show over fullscreen windows
  window.setFullScreenable(false);

not sure if everyone in this thread was using fullscreenable, but if you are and running into this issue try the above!

@extrastu
Copy link

Ran into this and found a configuration that seems to work.

The key seems to be not setting fullscreenable when you init the window and instead do it after configuring setVisibleOnAllWorkspaces + visibleOnFullScreen

  window = new BrowserWindow({
    // DO NOT set fullscreenable here
    // fullscreenable: false,
  });

  window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

  // NOTE: Make sure this is called after setVisibleOnAllWorkspaces + visibleOnFullScreen
  // otherwise it will not actually show over fullscreen windows
  window.setFullScreenable(false);

not sure if everyone in this thread was using fullscreenable, but if you are and running into this issue try the above!

This worked for me, thanks

@10n37
Copy link

10n37 commented May 19, 2023

Ran into this and found a configuration that seems to work.

The key seems to be not setting fullscreenable when you init the window and instead do it after configuring setVisibleOnAllWorkspaces + visibleOnFullScreen

  window = new BrowserWindow({
    // DO NOT set fullscreenable here
    // fullscreenable: false,
  });

  window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

  // NOTE: Make sure this is called after setVisibleOnAllWorkspaces + visibleOnFullScreen
  // otherwise it will not actually show over fullscreen windows
  window.setFullScreenable(false);

not sure if everyone in this thread was using fullscreenable, but if you are and running into this issue try the above!

Not working for me :(

@10n37
Copy link

10n37 commented May 31, 2023

Found the solution. Just set skipTransformProcessType: true in options:

window.setVisibleOnAllWorkspaces(true, {
    visibleOnFullScreen: true,
    skipTransformProcessType: true,
})

@lacymorrow
Copy link

lacymorrow commented Jun 2, 2023

doesn't work in windows, Electron 9-11

@10n37
Copy link

10n37 commented Jun 5, 2023

doesn't work in windows, Electron 9-11

but this issue about macOS dock problem.

@lacymorrow
Copy link

Does this not work for you?
#26350 (comment)

I'm running electron 11 I believe

@10n37
Copy link

10n37 commented Jun 6, 2023

Does this not work for you? #26350 (comment)

I'm running electron 11 I believe

Works, but it's not a 100% solution. I found some cases where dock can completely disappear.
The solution i found (i'm using electron 22) works fine now

@lacymorrow
Copy link

I have been sticking with Electron 11 because of this exact issue, looks like I have some testing to do,

@10n37
Copy link

10n37 commented Jun 7, 2023

Found the solution. Just set skipTransformProcessType: true in options:

window.setVisibleOnAllWorkspaces(true, {
    visibleOnFullScreen: true,
    skipTransformProcessType: true,
})

Nevermind. skipTransformProcessType disables visibleOnFullScreen option
but workspaces still works fine

@10n37
Copy link

10n37 commented Jun 12, 2023

Found the solution. Just set skipTransformProcessType: true in options:

window.setVisibleOnAllWorkspaces(true, {
    visibleOnFullScreen: true,
    skipTransformProcessType: true,
})

Nevermind. skipTransformProcessType disables visibleOnFullScreen option but workspaces still works fine

Found another trick. This problem solved by combining dock methods and BrowserWindow.setVisibleOnAllWorkspaces

app.dock.hide()

window.setVisibleOnAllWorkspaces(true, {
  visibleOnFullScreen: true,
  skipTransformProcessType: true,
})

await app.dock.show()

@10n37
Copy link

10n37 commented Jun 17, 2023

Finally able to figure it out.

BrowserWindow settings

const windowSettings = { type: 'panel' }

Method calls while creating window

window.setVisibleOnAllWorkspaces(true, {
  visibleOnFullScreen: true,
  skipTransformProcessType: true,
})

And now it's working perfectly on all workspaces and full-screen mode, without causing dock issue

electron: 22.0.0
macOS: 13.4

UPD: No need to call setVisibleOnAllWorkspaces, just set type: 'panel' in your window settings

const window = new BrowserWindow({type: 'panel'})

lacymorrow added a commit to lacymorrow/crossover that referenced this issue Jul 4, 2023
@electron-issue-triage
Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@ajay-pipaliya-simform
Copy link

Finally able to figure it out.

BrowserWindow settings

const windowSettings = { type: 'panel' }

Method calls while creating window

window.setVisibleOnAllWorkspaces(true, {
  visibleOnFullScreen: true,
  skipTransformProcessType: true,
})

And now it's working perfectly on all workspaces and full-screen mode, without causing dock issue

electron: 22.0.0 macOS: 13.4

I try this, but not working

@10n37
Copy link

10n37 commented Dec 19, 2023

I try this, but not working

Did you don't forget to set type: 'panel' in BrowserWindow settings?

I created a demo-project by using electron-react-boilerplate, you can try it:
https://github.com/RewriteH/electron-workspaces-visible

@ajay-pipaliya-simform
Copy link

ajay-pipaliya-simform commented Dec 19, 2023

I try this, but not working

Did you don't forget to set type: 'panel' in BrowserWindow settings?

I created a demo-project by using electron-react-boilerplate, you can try it: https://github.com/RewriteH/electron-workspaces-visible

I added type 'panel' but not working, Here I mentioned my code below. Please let me know if there's an error.

win = new BrowserWindow({
x: width - 384,
y: height - 696,
width: 900,
height: 696,
frame: false,
transparent: false,
resizable: false,
type: 'panel',
skipTaskbar: process.platform === 'win32' ? true : false,
visualEffectState: 'active',
tabbingIdentifier: 'OnTime',
icon: process.platform === 'win32' ?
nativeImage.createFromPath(path.join(__dirname, 'icons', 'winx256.ico')) :
nativeImage.createFromPath(path.join(__dirname, 'icons', 'winx128.png')),
webPreferences: {
devTools: true,
nodeIntegration: true,
allowRunningInsecureContent: (serve) ? true : false,
contextIsolation: false,
},
});

win.setAlwaysOnTop(true, 'pop-up-menu');
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

@10n37
Copy link

10n37 commented Dec 19, 2023

I try this, but not working
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

skipTransformProcessType must also be set to true:

window.setVisibleOnAllWorkspaces(true, {
 visibleOnFullScreen: true,
 skipTransformProcessType: true,
})

Checkout this demo if it's not working properly maybe it depends on OS or Electron version

@ajay-pipaliya-simform
Copy link

I try this, but not working
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

skipTransformProcessType must also be set to true:

window.setVisibleOnAllWorkspaces(true, {
 visibleOnFullScreen: true,
 skipTransformProcessType: true,
})

Checkout this demo if it's not working properly maybe it depends on OS or Electron version

your demo is working fine. but not working in my app

@10n37
Copy link

10n37 commented Feb 14, 2024

just set type: 'panel' in your window settings

Just set type: 'panel' in your window settings

const window = new BrowserWindow({type: 'panel'})

@lacymorrow
Copy link

Caution that type: panel is only for OSX.

From the docs:

The possible values and behaviors of the type option are platform dependent. Possible values are:

On Linux, possible types are desktop, dock, toolbar, splash, notification.
The desktop type places the window at the desktop background window level (kCGDesktopWindowLevel - 1). However, note that a desktop window will not receive focus, keyboard, or mouse events. You can still use globalShortcut to receive input sparingly.
The dock type creates a dock-like window behavior.
The toolbar type creates a window with a toolbar appearance.
The splash type behaves in a specific way. It is not draggable, even if the CSS styling of the window's body contains -webkit-app-region: drag. This type is commonly used for splash screens.
The notification type creates a window that behaves like a system notification.
On macOS, possible types are desktop, textured, panel.
The textured type adds metal gradient appearance (NSWindowStyleMaskTexturedBackground).
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.
The panel type enables the window to float on top of full-screened apps by adding the NSWindowStyleMaskNonactivatingPanel style mask,normally reserved for NSPanel, at runtime. Also, the window will appear on all spaces (desktops).
On Windows, possible type is toolbar.

@yuvalkarmi
Copy link

yuvalkarmi commented Mar 13, 2024

I try this, but not working
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });

skipTransformProcessType must also be set to true:

window.setVisibleOnAllWorkspaces(true, {
 visibleOnFullScreen: true,
 skipTransformProcessType: true,
})

Checkout this demo if it's not working properly maybe it depends on OS or Electron version

I can confirm this works as long as you set type to panel in the BrowserWindow settings (I'm running Electron 28.1.3). Thanks VERY much @10n37 - you just saved me lots of time and headache <3

@haisamMH
Copy link

This worked for me!

myWindow.setAlwaysOnTop(true, "floating");
myWindow.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true});
myWindow.setFullScreenable(false);

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

No branches or pull requests