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

Dark theme #239

Merged
merged 1 commit into from
May 14, 2018
Merged

Dark theme #239

merged 1 commit into from
May 14, 2018

Conversation

htwyford
Copy link
Contributor

@htwyford htwyford commented May 9, 2018

Addresses #185. The onboarding in the sidebar and doorhanger now take on the dark theme if it's applied in Firefox.

One outstanding issue is that Firefox broadcasts a switch from the default to the dark theme, but not from the the dark theme to the default. This means the sidebar changes when the dark theme is applied but doesn't return to default without a browser restart. I figured this is a smallish edge case: a user would have to switch from default to dark while the onboarding window is open. This issue doesn't cause any breaking changes. Doesn't seem like it can be resolved until https://bugzilla.mozilla.org/show_bug.cgi?id=1435216 is addressed.

Alternatively, we could disable the listener. This would allow us to remove the management permission. The user would have to close and reopen the sidebar after switching to dark theme to see the changes.

Copy link

@ericawright ericawright left a comment

Choose a reason for hiding this comment

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

Some cursory comments:

  • The side bar seems to stay in dark theme mode until you close and open it again.
    (edit) both the sidebar and popup stay in dark mode until opened again - though will switch dynamically from light to dark

nit:

  • there is a white flash on the sidebar when it is in dark mode.

run npm run lint to find some code style fixes

addon/theming.js Outdated
@@ -0,0 +1,111 @@
var updateBackground = function(el, color) {

Choose a reason for hiding this comment

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

use let and const instead of var

addon/popup.js Outdated
handleThemes(isPopup = true);

// // watch for switch to dark theme.
// // BUG: No event transmitted when switching back to default

Choose a reason for hiding this comment

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

remove this comment, since we aren't using themes other than dark/light

@ericawright
Copy link

Instead of using isPopup, can't we just have one listener and update both the popup and the sidebar when triggered?

@htwyford
Copy link
Contributor Author

htwyford commented May 9, 2018

Regarding isPopup, the sidebar and popup are blind to each other, and the popup is only updated when it's opened. If you attempt to update the sidebar variables when the popup needs to be drawn, there's an error and both fail, and vice versa.

addon/theming.js Outdated
(theme.colors.popup_highlight || "#ededf0") + "!important }";
let style = document.createElement("style");

if (style.styleSheet) {

Choose a reason for hiding this comment

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

does this ever evaluate to true?

addon/theming.js Outdated
if (theme.colors) {
let panel = document.getElementById("panel");
let tabs = document.getElementsByClassName("tab");
let feedback = document.getElementsByClassName("feedback-button")[0];
Copy link

@ericawright ericawright May 9, 2018

Choose a reason for hiding this comment

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

document.querySelector('.feedback-button') will get you only the first element it finds with that selector

addon/theming.js Outdated
};

function updateSidebarStyle() {
if (theme.colors) {
Copy link

@ericawright ericawright May 9, 2018

Choose a reason for hiding this comment

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

can these styles be applied with css instead? select a parent element el.classList.add('dark-theme') then style all the children within it dark?
We talked about how the border and carat of the panel can only be changed with JS, but in all other cases css is better

@htwyford
Copy link
Contributor Author

htwyford commented May 9, 2018

The selection of what elements to dark theme is more specific than "all children of root" to avoid writing too many exceptions in the CSS.

Copy link

@ericawright ericawright left a comment

Choose a reason for hiding this comment

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

Can the "Recent Tabs" and "Current Tabs" labels be a lighter color in dark mode?

Can you use variables in css, it doesn't look like they've been used yet, but might as well start them.
ex:
root {
--dark-theme-background-color: #6d6d6f;
}

addon/sidebar.js Outdated
@@ -2,6 +2,25 @@ function element(selector) {
return document.querySelector(selector);
}

function applyDarkTheme() {
document.body.style.background = "#4a4a4f";
document.body.style.color = "#fff";

Choose a reason for hiding this comment

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

Do you know why this needs to be applied when the sidebar is triggered? I tried removing it and the popup styling was affected

}

async function checkForDark() {
browser.management.getAll().then((extensions) => {

Choose a reason for hiding this comment

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

I wish there was a better way to listen for this event that didn't require us to request more permissions...

addon/popup.css Outdated

#panel.dark-theme,
#panel.dark-theme .tab {
background: #4a4a4f !important;

Choose a reason for hiding this comment

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

I think you can remove most, if not all, of the !important

.page.dark-theme button:hover,
.page.dark-theme button:focus,
.page.dark-theme .graphic__shadow {
background: #6d6d6f;

Choose a reason for hiding this comment

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

I like the effect on the shadow, but it creates a strange highlighter effect on the links.

addon/sidebar.js Outdated
function applyDarkTheme() {
document.body.style.background = "#4a4a4f";
document.body.style.color = "#fff";
document.querySelector(".page").classList.add("dark-theme");

Choose a reason for hiding this comment

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

looks like there's already a utility function written above on this page for this, we should use it.

@ianb
Copy link
Contributor

ianb commented May 10, 2018

Is there anything with browser_style that would help us here? (A property mentioned on this page)

There's a possibility we could detect the theme using browser_style and getComputedStyle(). (Note that I don't know if browser_style even respects the dark theme, and I haven't tested any of this, it's just a hunch.)

There's also a possibility that if we don't specify things browser_style already gives us, then the dark theme would magically be applied? (That seems unlikely to me.)

@htwyford
Copy link
Contributor Author

browser_style doesn't seem to respect dark theme. Searching through chrome://browser/content/extension.css doesn't turn up any references to any of the dark theme colours (or the works "dark", "night", "firefox-compact-dark", etc., for that matter).
I also tried removing specific references to browser_style as well, and it just defaults to the usual white look. I think something custom is needed, as least until browser_style starts broadcasting dark-theme changes.

@ericawright
Copy link

@htwyford this is ready right? @fzzzy or @ianb want to review again?

@htwyford
Copy link
Contributor Author

It's ready!

@fzzzy
Copy link
Contributor

fzzzy commented May 14, 2018

@htwyford This looks good, but it has some conflicts now. Can you resolve them? Thanks!

although JS theming is required for the base of the popup. A
listener is installed to update the sidebar on default -> dark changes.
@fzzzy
Copy link
Contributor

fzzzy commented May 14, 2018

Nice!

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.

4 participants