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

[WS-31] windows integrated titlebar #102

Merged
merged 12 commits into from
Aug 23, 2023

Conversation

szymonkaliski
Copy link
Member

@szymonkaliski szymonkaliski commented Aug 15, 2023

Why

Integrated titlebar on Windows like on macOS:

Screenshot 2023-08-15 at 15 15 12 Screenshot 2023-08-15 at 15 15 31

Needs https://github.com/replit/repl-it-web/pull/35147 to be merged.

What changed

  • added custom platform styling for Windows
  • had to grab foreground color too
  • var(--background-root) in platform styling is not working on Windows, so changed to use getLastSeenBackgroundColor (and new getLastSeenForegroundColor)

Test plan

Check out the screenshots.

@linear
Copy link

linear bot commented Aug 15, 2023

WS-31 integrated titlebar/menubar UI for Windows, like on macOS

see what we can do, Windows looks ugly with the default title bar design (see screenshot)

notes from Faris: https://replit.slack.com/archives/C0509G0FJNL/p1683158097198949

Screenshot 2023-05-31 at 4.53.58 PM.png

@sergeichestakov
Copy link
Contributor

will check this in a bit with the web PR checked out - in the meantime looks like you have some conflicts here from the other PR

@szymonkaliski
Copy link
Member Author

thanks; conflicts fixed :)

titleBarOverlay: {
color: backgroundColor,
symbolColor: foregroundColor,
height: 44,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this the same height as the above for consistency? i.e. 48px esp since that's more consistent with RUI values and matches some of our other header heights

Copy link
Member Author

@szymonkaliski szymonkaliski Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we go with 48 then the hover state of the windows native button touches the top of the pane below it, which looks unintentional/wrong, considering we have 4px padding in most places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really? I feel like this looks better. what makes it look unintentional to you? feel like the later does for me:

44px

Screenshot 2023-08-16 at 10 59 34 AM
Screenshot 2023-08-16 at 10 55 37 AM

48px

Screenshot 2023-08-16 at 11 02 03 AM
Screenshot 2023-08-16 at 11 01 07 AM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea we have paddings everywhere so feels weird to me that it suddenly touches the pane... maybe worth circulating with #design for another opinion 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agree worth asking. feel like at the OS level it's ok to be flush with the pane

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asked here looks like 48px is the preferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will update together with the other changes!

Copy link
Contributor

@sergeichestakov sergeichestakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this largely looks good (except for the comment above) but can you make the background translucent? it looks like it's currently hardcoded to match the dark mode color so it looks off if you're using a light theme or anything other than our official dark theme:

Screenshot 2023-08-15 at 1 48 10 PM

@szymonkaliski
Copy link
Member Author

this largely looks good (except for the comment above) but can you make the background translucent? it looks like it's currently hardcoded to match the dark mode color so it looks off if you're using a light theme or anything other than our official dark theme

It's not hardcoded, it just defaults to the background/foreground from the dark theme, but then uses the colors recorded when we close the window:

desktop/src/createWindow.ts

Lines 171 to 184 in e6a0243

window.on("close", async () => {
// We're capturing the background and foreground colors to use as main
// browser window background color, and style the traffic lights/window
// buttons.
const backgroundColor = await window.webContents.executeJavaScript(
`getComputedStyle(document.body).getPropertyValue('--background-root');`,
);
const foregroundColor = await window.webContents.executeJavaScript(
`getComputedStyle(document.body).getPropertyValue('--foreground-default');`,
);
store.setLastSeenBackgroundColor(backgroundColor);
store.setLastSeenForegroundColor(foregroundColor);
store.setWindowBounds(window.getBounds());
});

This obviously will break if we have a mismatch between stored/current colors, like if we change the theme without restarting the app.

One possible way forward would be to expose some version of https://www.electronjs.org/docs/latest/api/browser-window#winsettitlebaroverlayoptions-windows through the electron API, and allow the client to change the color when we change the theme. What do you think @sergeichestakov?

@sergeichestakov
Copy link
Contributor

hmm it doesn't seem to restore for me in light mode (in other words, I still see the dark mode colors regardless). and yeah we're going to want to go with an approach that is resilient to switching themes

@szymonkaliski
Copy link
Member Author

ok cool, I'll switch it to draft and will update soon

@szymonkaliski szymonkaliski marked this pull request as draft August 16, 2023 15:03
@sergeichestakov
Copy link
Contributor

nvm looks like it does when I close and re-open a window (think I was just opening a window before without closing after switching themes)

@szymonkaliski
Copy link
Member Author

nvm looks like it does when I close and re-open a window (think I was just opening a window before without closing after switching themes)

Yea that's what I was trying to say -- we only update when we close the window, so it's easy to get into a stale state, I think we should expose this through the API so we can switch colors dynamically.

Comment on lines 94 to 95
color: backgroundColor,
symbolColor: foregroundColor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not affect Mac styling in the context of this PR? I think using CSS vars is the ideal solution if it works on MacOS. Looks like we'll have to find a different approach on Windows but don't see a reason to switch on Mac

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these actually don't do anything on macOS, I'll drop them completely

@szymonkaliski
Copy link
Member Author

@sergeichestakov I updated the code with comments, and added an event to notify on theme change, so we get this:

Screenshot.2023-08-21.at.11.01.17.mov

I tested on macOS and Windows, but would be good for you to test as well.

Since this depends on a new desktop app API event, you should test together with recent changes in https://github.com/replit/repl-it-web/pull/35147

@szymonkaliski szymonkaliski marked this pull request as ready for review August 21, 2023 09:16
titleBarStyle: "hidden",
titleBarOverlay: {
color: "var(--background-root)",
symbolColor: "var(--foreground-default)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color/symbolColor does nothing on macOS -- it's a Windows thing only

Copy link
Contributor

@sergeichestakov sergeichestakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exciting! let's just pass the theme values in directly as part of the IPC call? otherwise I see a flash in the transparent header when switching themes because the old values persist for a split second

src/createWindow.ts Show resolved Hide resolved
src/preload.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@sergeichestakov sergeichestakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. let's just make it an object arg rather than positional. also some merge conflicts to fix. I can take over

src/preload.ts Outdated
@@ -48,6 +48,8 @@ contextBridge.exposeInMainWorld('replitDesktop', {
ipcRenderer.invoke(events.SHOW_MESSAGE_BOX, params),
onEnterFullscreen: makeEventHandler(events.ON_ENTER_FULLSCREEN),
onLeaveFullscreen: makeEventHandler(events.ON_LEAVE_FULLSCREEN),
themeChanged: (backgroundColor: string, foregroundColor: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're going to want to an object param here rather than multiple positional params since we may add more values down the line (for instance, if we want to send the full theme over).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also: we should just be explicit here what theme values these correspond to. e.g. backgroundRoot and foregroundDefault rather than just backgroundColor, foregroundColor since, again, we may want to send more at some point and this will be easier to pass down directly from the theme values on the client

src/createWindow.ts Show resolved Hide resolved
@@ -76,13 +76,17 @@ function isInBounds(rect: Rectangle) {
});
}

async function getLastSeenBackgroundColor(
export async function getColorsFromWindow(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we need to export as this isn't used anywhere else

src/preload.ts Outdated
@@ -48,6 +48,8 @@ contextBridge.exposeInMainWorld('replitDesktop', {
ipcRenderer.invoke(events.SHOW_MESSAGE_BOX, params),
onEnterFullscreen: makeEventHandler(events.ON_ENTER_FULLSCREEN),
onLeaveFullscreen: makeEventHandler(events.ON_LEAVE_FULLSCREEN),
themeChanged: (backgroundColor: string, foregroundColor: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also: we should just be explicit here what theme values these correspond to. e.g. backgroundRoot and foregroundDefault rather than just backgroundColor, foregroundColor since, again, we may want to send more at some point and this will be easier to pass down directly from the theme values on the client

src/createWindow.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@sergeichestakov sergeichestakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the API a bit and did some minor refactoring. thanks for pushing this forward!

@sergeichestakov sergeichestakov merged commit fd35af9 into main Aug 23, 2023
3 checks passed
@sergeichestakov sergeichestakov deleted the sk/windows-integrated-titlebar branch August 23, 2023 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants