-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support vscode's titleBarStyle
#10044
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -72,6 +72,18 @@ export const corePreferenceSchema: PreferenceSchema = { | |||
A setting of 'compact' will move the menu into the sidebar.`, | |||
included: !isOSX | |||
}, | |||
'window.titleBarStyle': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In vscode, the preference also controls the display of context-menus, meaning we can have browser-like menus in electron instead of native. That's why when I first thought of the issue I was thinking we can control the binding we do to not bind native electron menus and instead use that of the browser:
theia/packages/core/package.json
Lines 123 to 124 in 068e78d
"frontend": "lib/browser/menu/browser-menu-module", | |
"frontendElectron": "lib/electron-browser/menu/electron-menu-module" |
With a bit more extra work, we can simply use the browser menus in electron (main menu, and context menus) by modifying the way we bind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we always want to have browser-like menus in Electron? If not, I'm not quite sure how we would be able to accomplish that during the binding phase, as we need the preference service to identify which title bar style is selected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msujew I believe dynamic binding might be possible, and is something we likely did in #9186.
As for the behavior, I would expect that:
native
displays the native menus (main-menu and context-menus) similarly to vscodecustom
displays the browser-like menus (main-menu and context-menus) similarly to vscode
You're right that there might be issues especially on startup, but perhaps it's something to try.
cc @paul-marechal any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You reminded me that the context menus where not displayed in the browser styling if custom
is used. I addressed that.
I believe dynamic binding might be possible, and is something we likely did in #9186.
I only saw conditional binding based on os
based constants. That works fairly well. However, during binding we have no access to preferences as they are 1. a service in themselves 2. we would have to wait for the async ready
state.
1212bf4
to
8f660b5
Compare
Should be fixed now 👍 |
f00a9b7
to
090c853
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msujew when updating the preference, we probably want to ask users to confirm a restart of the application similarly to vscode (confirmation dialog)?
I was able to get the following state:
- update preference from
native
tocustom
- execute the command
reload application
You reminded me that the context menus where not displayed in the browser styling if custom is used. I addressed that.
The custom context-menus (with custom
enabled) do not appear for me on Ubuntu.
Yes, I also thought about that. I tried implementing it, but got discouraged by the electron app restarting without starting the backend server. I'll take another look at it 👍
Weird, it works fine for me on Windows: Time to bring out my old Ubuntu vm... |
Hopefully the video helps :) reload-bug.mp4 |
I got that part, but do have a video of the native context menus (on |
Sure! context-menu-bug.mp4 |
@vince-fugnitto I managed to implement that without the whole application crashing. However, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a feature or a bug?
Both :-/. Ideally, the initial setting of preferences wouldn't fire an event, and they would just take on those values and then the preference service would resolve its .ready
promise and everyone would see the initial values and work from there. In practice, because there's a (reasonably) predictable flood of events (under most conditions), there are a number of places where code has been written in such a way to depend on those events, in the framework and almost certainly downstream. The bug earlier this week re: the browser menu bar was an example of the consequences of such code, but it would almost certainly be a pain in adopters' butts to remove that flood of events, however unsafe it is to rely on it in general.
Re: this particular case, you should be able to do something like setting a flag when you first create the menu bar and not showing the dialog before that. That way, you don't show it for the first flood of events (before you've even decided what to do), but any subsequent changes do trigger the dialog.
packages/core/src/electron-browser/menu/electron-menu-contribution.ts
Outdated
Show resolved
Hide resolved
packages/core/src/electron-browser/menu/electron-menu-contribution.ts
Outdated
Show resolved
Hide resolved
090c853
to
69d5c30
Compare
Thank you for the explanation, I implemented something similiar that ignores the first wave of preference changes 👍 I was also able to fix the issue Vince experienced (changing preference -> ignoring the dialog -> resetting the view). |
5766934
to
f4b778c
Compare
@vince-fugnitto I can't reproduce your context-menu issue using Ubuntu 20.04 (running emulated on Windows): Do you mind retesting it? I think I addressed every other issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behavior I was noticing was something in cache, since if I switch between two different electron instances (ex: master and this pr) I end up with odd behaviors.
One thing I did notice is the following:
- start the application, update the preference to
custom
- accept the restart prompt (the app restarts with the new menu)
- close the application
- modify the preference in the user's home (remove the
custom
titleBarStyle preference) - when restarting the application I get back the
custom
menu
It's only when I remove the electron cache do I see the proper menu again:
$ rm -rf ~/.config/Theia\ Electron\ Example/
I'm not sure if there is anything we can improve in this aspect, but I don't think it should block the pull-request, just a bug end-users might experience.
packages/core/src/electron-browser/window/electron-window-preferences.ts
Outdated
Show resolved
Hide resolved
05fe6a0
to
b076370
Compare
I don't think so either. We don't have access to the users preferences during startup, which would be needed in order to display the correct window title. Instead, everything is saved in the I also just noticed that the context menu uses the default electron menu if you set the preference from |
@msujew unfortunately, the The following for instance does not work for me: "theia": {
"target": "electron",
"frontend": {
"config": {
"applicationName": "Theia Electron Example",
"preferences": {
"window.titleBarStyle": "custom"
}
}
}
}, The app starts with |
323be3a
to
c5eef63
Compare
@vince-fugnitto Is this an approval? :) It would be great, if we were able to include it in this month's release. Although, I don't have an issue with delaying it. |
@msujew, Sorry, got distracted. I'll take a look later today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be working well for me. I was able to switch between modes without issue, and the behavior was correct.
Re: styling, the Theia icon certainly, and I think the other menu bar icons less obviously, are hovering a little higher than they should. It looks like about 10px below and only 6px above.
packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts
Outdated
Show resolved
Hide resolved
packages/core/src/electron-browser/menu/electron-menu-contribution.ts
Outdated
Show resolved
Hide resolved
packages/core/src/electron-browser/menu/electron-menu-contribution.ts
Outdated
Show resolved
Hide resolved
packages/core/src/electron-browser/menu/electron-menu-contribution.ts
Outdated
Show resolved
Hide resolved
packages/core/src/electron-browser/menu/electron-menu-style.css
Outdated
Show resolved
Hide resolved
6e0867a
to
c2a59d2
Compare
@colin-grant-work I agree (in regards to the Theia icon), but this also appears in the browser version ( I think this is unrelated to my changes and should be addressed in a separate PR. The other title bar icons are actually one pixel lower compared to vscode (vscode in the foreground, Theia in the background): But that is kind of related to Theia's top panel being 32px high, while vscode's is only 30px high. Should I change this to 30px in Theia as well? |
Sounds fair.
I don't have strong feelings here. I certainly have no objection in principle to |
c2a59d2
to
f04c05f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Good work finding a way to get electron to play nicely.
@msujew, @vince-fugnitto, this is working well for me, and the code looks good. Depending on your feelings about its complexity / likelihood of bugs, it might be worth putting off merging until after tomorrow's release? |
Sure, fine with me 👍 |
f04c05f
to
386fd0e
Compare
386fd0e
to
0bce21a
Compare
upstream PR: eclipse-theia/theia#10044 Signed-off-by: Marc Dumais <[email protected]>
upstream PR: eclipse-theia/theia#10044 Signed-off-by: Marc Dumais <[email protected]>
I get the same problem now, when I try upgrade theia to 1.23.0. from 1.18.0. After build the electron and start, I got it. No titlebar & top menu, only the content be display. And I try to set window: Title bar style custom -> native, it will be have a windows tile bar. (other: The restart window look like do not show always.) So, the window title bar style be default custom in new version, but it can't work in my PC, and then build electron installer running in other PC still so. And, I try to delete .theia/ in user folder, still so. I am using: |
@msujew, was there a technical obstacle to allowing the custom title bar on macOS?
VS Code supports it. Thank you! |
@kittaakos No real technical reason. I just don't have a macOS machine to test it. So we should still support it sometime on macOS. |
Excellent, thank you! We must implement it downstream, and if it works, we will contribute it back. |
What it does
Adds support for vscode's
window.titleBarStyle
setting that allows to use a browser-like menu in the electron environment:custom-title-bar-style.mp4
Note that this is only supported in Windows and Linux distributions. I actually have no idea how it works on MacOS.
How to test
custom
(browser-like) title bar. On Linux thenative
one.custom
andnative
state work correctly with the different configurations of thewindow.menuBarVisibility
setting.Review checklist
Reminder for reviewers