-
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
Changes from all commits
7157190
028b807
1fa9de5
3e2c790
e19a003
6b63a5f
889fa74
d69f14c
618e549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,12 +11,22 @@ | |||||
* @const | ||||||
* @type {Object} | ||||||
*/ | ||||||
|
||||||
// checks for OS dark theme and returns the appropriate background color | ||||||
const setQrBackgroundColor = () => { | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Did you actually test it(?), because…
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
} | ||||||
}; | ||||||
|
||||||
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 commentThe 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 commentThe 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 |
||||||
qrBackgroundColor: "#ffffff", | ||||||
qrBackgroundColor: setQrBackgroundColor(), | ||||||
qrErrorCorrection: "Q", | ||||||
autoGetSelectedText: false, | ||||||
monospaceFont: false, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,6 +532,12 @@ export function init() { | |
const applyingQrColor = AddonSettings.get("qrBackgroundColor").then((qrBackgroundColor) => { | ||
if (qrBackgroundColor) { | ||
document.body.style.backgroundColor = qrBackgroundColor; | ||
|
||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Why did you move that from CSS to JS now? Everything which you can define statically, put into CSS. (as it was before) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving back to CSS |
||
qrCodeText.style.color = "#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.
As per our guide:
(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 aconst
so the line doesn't go on forever)