-
Notifications
You must be signed in to change notification settings - Fork 127
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
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.
Hi @davidfloyd91,
thanks for your first contribution to this project! 🎉 👍 🏅
I hope you'll like this project and enjoy hacking on it… 😃
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) |
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.
Please sort it alphabetical, thanks.
src/popup/qrcode.css
Outdated
background-color: var(--grey-30); | ||
} | ||
#qrcode-container { | ||
background-color: var(--grey-60); |
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.
Oh another big problem. This change overrides the user's choice of the background color in the settings:
leads to:
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.
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 |
Okay, so. So marking this as blocked by TinyWebEx/AddonSettings#6 |
You're right, my mistake. Fixed: TinyWebEx/common@90ca64d Again regarding this color thing:
|
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 |
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) |
Cross-posting this comment, since it's relevant to this issue: TinyWebEx/AddonSettings#6 (comment) |
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.) |
Sorry about that. What's the best way to proceed? I |
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"; |
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.
Did you actually test it(?), because…
return "ffffff"; | |
return "#ffffff"; |
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.
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 |
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.
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…
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.
Moving back to CSS
return "ffffff"; | ||
} | ||
}; | ||
|
||
const defaultSettings = Object.freeze({ | ||
debugMode: false, | ||
popupIconColored: false, | ||
qrCodeType: "svg", | ||
qrColor: "#0c0c0d", |
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.
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.)
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 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 = () => { |
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.
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.
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.
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
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.
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)
Ouch, no, merged the wrong PR… |
Oh I was wondering. I'll submit one with the changes you mentioned now |
Or wait? Let me know what you want to do, here's the commit davidfloyd91@1639cef |
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… |
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.