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

close #186 (Automatic) dark mode #201

Merged
merged 9 commits into from
Jun 5, 2019
Merged

close #186 (Automatic) dark mode #201

merged 9 commits into from
Jun 5, 2019

Conversation

davidfloyd91
Copy link
Contributor

Implements a fix to #186: when a user's OS is set to a dark theme, the popup's colors are shifted to match Firefox's dark theme.

Note that the fix is implemented using prefers-color-scheme, which reads from the OS, not the browser. So a user who's chosen a dark macOS theme, but a light Firefox theme, for example, will still see a popup that's formatted to match FF's dark theme.

Also note that if the OS theme is changed, the browser needs to be restarted for offline-qr-code to reflect that change.

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

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

Hi @davidfloyd91,
thanks for your first contribution to this project! 🎉 👍 🏅
I hope you'll like this project and enjoy hacking on it… 😃

Screenshot for reference:
image

So, are these colors somewhat official you've taken for this? I.e. from Firefox Photon guide?

CONTRIBUTORS.md Outdated
@@ -13,6 +13,7 @@
- [@redagavin](https://github.com/redagavin)
- [@Thammarith](https://github.com/Thammarith)
- [@xlomonosvx](https://github.com/xlomonosvx)
- David Floyd [@davidfloyd91](https://github.com/davidfloyd91)
Copy link
Owner

Choose a reason for hiding this comment

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

Please sort it alphabetical, thanks.

background-color: var(--grey-30);
}
#qrcode-container {
background-color: var(--grey-60);
Copy link
Owner

Choose a reason for hiding this comment

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

Oh another big problem. This change overrides the user's choice of the background color in the settings:

image

leads to:

image


So I am sorry, but it seems you need to adjust some JS-things, too…
(best solution would IMHO be that it only colors the background of the QR code dark, if you want it.)

So, hmm, I guess we need another change in one module even, where we get the default values from: TinyWebEx/AddonSettings#6

(see also the Readme, it provides an extensive doc on how it's used.)

That color is set in JS.

@davidfloyd91
Copy link
Contributor Author

Sorry about the alphabetizing, I'd read somewhere to add yourself to the bottom. Fixed that.

The colors are from Photon, yes. The popup background ("Grey 60", #4a4a4f) matches other FF dark theme popups. The QR code background is Photon's "Grey 30" (#d7d7db), which just seemed a bit less blinding than the default white.

The overwriting is definitely an issue. Just removing the background-color from .qrcode doesn't appear to work, since there's not enough contrast (see screenshot below). So I'll look at the module you mentioned and fix it in JS.

Screen Shot 2019-06-03 at 2 29 14 PM

@rugk
Copy link
Owner

rugk commented Jun 3, 2019

Okay, so. So marking this as blocked by TinyWebEx/AddonSettings#6

@rugk rugk added the blocked This issue is blocked by something from the outside and cannot be done currently. label Jun 3, 2019
@rugk
Copy link
Owner

rugk commented Jun 3, 2019

I'd read somewhere to add yourself to the bottom

You're right, my mistake. Fixed: TinyWebEx/common@90ca64d


Again regarding this color thing:

  • In case I have not expressed it correctly – now in a better way: IMHO it would be best if the add-on could automatically "select" dark default colors (for the QR code) for the user in case of prefers-color-scheme = dark.
  • Regarding contrast: Yep, that needs to be assured, by default it should be quite optimal (use the settings page, it checks for that 😉). Also remember that not all QR code scanners can read inverted QR codes: Warning for inverted QR codes (when background color is dark and foreground light) #20
    So that choice of color needs to be a wise one, here… 😉

@davidfloyd91
Copy link
Contributor Author

Sounds good. I think I've just about wrapped my head around the AddonSettings module, it should be easy enough to add a couple of default settings. I'll keep you posted if I run into issues

@rugk
Copy link
Owner

rugk commented Jun 3, 2019

Yeah, thanks. That sounds great. Feel free to ask any questions then… (best in TinyWebEx/AddonSettings#6, if they are only about that feature there)

@davidfloyd91
Copy link
Contributor Author

Cross-posting this comment, since it's relevant to this issue: TinyWebEx/AddonSettings#6 (comment)

@rugk
Copy link
Owner

rugk commented Jun 4, 2019

BTW: Next time, try to avoid doing a pull request from the master branch, because you can run into problems when you have a "non-clean" master that does not follow this repo here (i.e. "upstream"). See this article for details.

And you can (automatically) let issues close when a PR is merged. (Just edit your PR description.)

@davidfloyd91
Copy link
Contributor Author

davidfloyd91 commented Jun 5, 2019

BTW: Next time, try to avoid doing a pull request from the master branch, because you can run into problems when you have a "non-clean" master that does not follow this repo here (i.e. "upstream"). See this article for details.

Sorry about that. What's the best way to proceed? I was going to merge went ahead and merged the latest commits into master so you can review them, but if that could cause problems I'm happy to close the PR and clean up my master (probably just by re-forking the repo? since we're only talking about 20-something lines of code...)

@davidfloyd91 davidfloyd91 changed the title (Automatic) dark mode close #186 (Automatic) dark mode Jun 5, 2019
@rugk
Copy link
Owner

rugk commented Jun 5, 2019

No problem, just keep it as it is now…

if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return "#d7d7db"; // Photon Grey 30
} else {
return "ffffff";
Copy link
Owner

Choose a reason for hiding this comment

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

Did you actually test it(?), because…

Suggested change
return "ffffff";
return "#ffffff";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Embarrassing. Looks like tests worked because white is the default, I tried it in a ternary with null and the result was the same. Fixing for readability


// checks for OS dark theme and sets sets colors in text field
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
qrCodeText.style.backgroundColor = "#4a4a4f"; // Photon Grey 60 -- FF dark theme popup color
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you move that from CSS to JS now?
IMHO a combination would be just fine…

Everything which you can define statically, put into CSS. (as it was before)
And everything which needs JS-handling, use JS…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving back to CSS

return "ffffff";
}
};

const defaultSettings = Object.freeze({
debugMode: false,
popupIconColored: false,
qrCodeType: "svg",
qrColor: "#0c0c0d",
Copy link
Owner

Choose a reason for hiding this comment

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

Also generally, I guess you could maybe also adjust the QR code color in case of "dark mode", so that it matches to the background color? Or is this really not needed? (did you check the contrast/tested with QR code scanners etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried out different combinations, always testing for contrast and QR scannability (if that's a word?). This combination seemed to reduce the white glare, stay in line with Photon and stay scannable better than others. But there might be a better solution

@@ -11,12 +11,22 @@
* @const
* @type {Object}
*/

// checks for OS dark theme and returns the appropriate background color
const setQrBackgroundColor = () => {
Copy link
Owner

Choose a reason for hiding this comment

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

As per our guide:

Avoid anonymous functions, which have no name (i.e. not really assigned) unless they do really do simple things.

(I've edited the md file now to clarify that a little…)

Generally, don't use arrow functions here. Either inline it into the actual object (I would choose so) or make it a real "usual" function and JSDOC-document it.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually in this case you may even be able to simplify that whole thing to one line: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, read that in the guide but forgot. Setting to ternary (but pulling window.matchMedia('(prefers-color-scheme: dark)').matches out into a const so the line doesn't go on forever)

@rugk rugk merged commit 618e549 into rugk:master Jun 5, 2019
@rugk
Copy link
Owner

rugk commented Jun 5, 2019

Ouch, no, merged the wrong PR…

@davidfloyd91
Copy link
Contributor Author

Oh I was wondering. I'll submit one with the changes you mentioned now

@davidfloyd91
Copy link
Contributor Author

Or wait? Let me know what you want to do, here's the commit davidfloyd91@1639cef

@rugk
Copy link
Owner

rugk commented Jun 5, 2019

So I reverted master… GitHub does not seem to reopen this PR… so…

Your chance to open a new PR (with a new branch, possibly now 😉)

Sorry for the inconvenience…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue is blocked by something from the outside and cannot be done currently.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants