-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
adding screenshots and ability to change based on OS theme #65
Conversation
Hi @silvererudite, Next time maybe try to install/use an editorconfig plugin or so for your editor in case it is not built-in. We use that in our repo, so it should notice and use that. You can (automatically) let issues close when a PR is merged by adding some "magic" text to your PR body. It would be kind, if you could edit your PR to change this. 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.
Could you describe what issue you actually have? |
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.
Nice screenshots BTW. 😃
Also, what maybe is an issue for your bugs is that you also need to register a listener for change events, i.e. when the preferred color changes at runtime. Fortunately, you can subscribe to these events. See: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Methods
And better move this functionality into a separate module (JS file). Just as any other included module. Maybe name it ColorSchemeModeHelper
or so.
src/options/options.css
Outdated
@@ -3,3 +3,11 @@ | |||
.float-image { | |||
margin: 10px; | |||
} | |||
|
|||
@media (prefers-color-scheme: dark) { | |||
|
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.
An empty CSS ruleset? I guess this is not really useful. So let's remove it.
src/options/options.js
Outdated
@@ -20,3 +20,12 @@ RandomTips.init(tips).then(() => { | |||
RandomTips.setContext("options"); | |||
RandomTips.showRandomTipIfWanted(); | |||
}); | |||
|
|||
let dark= window.matchMedia('@media (prefers-color-scheme: dark)'); |
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.
Use editorconfig -> that =
style is a non-standard here. A space is missing. 😄
src/options/options.js
Outdated
if(dark){ | ||
document.getElementById('searchBarDemo').src="./img/emojiSearchDog_dark.png"; | ||
} | ||
else if(light){ |
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.
Again, please adhere to the code style and use editorconfig (in one line).
@silvererudite If you need any pointers/help or have questions, feel free to ask. |
@silvererudite Are you still interested in completing this? If not, that's no problem, just add a notice, so I know what the current status of this PR is. |
hi @rugk sorry it's taking me this long. Can u pls help me debug why adding the eventlistener for detecting theme change at runtime is not working? |
* is is addListener, not addEventListener * only register for dark version, not retrigger for light version * the .matchMedia() query string was wrong (not include `@media`) * some code style fixes
Okay, pulled your change and fixed some things. Specifically:
While testing please also note:
|
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.
So please:
- fix the remaining issues (maybe use eslint for that, if you can)
- i.e. e.g. add a jsdoc to the new function.
- maybe please move it into a new module (in
./modules
) there
@rugk how do I synchronize the remote fork with my local clone after your commits? To explain a bit, I want to make my local copy of the repo updated with your changes in the fork what is the Git command to do that? Or is there any other way to do so |
…developer edition
Hi @rugk, was able to synchronize (turns out it's easier than I thought in vscode😀)I have pushed hopefully the final commit for the issue. Now this PR closes #59 |
The answer was "just pull", but apparently you figured that out by yourself. |
@@ -0,0 +1,16 @@ | |||
/* this function changes screenshot in the options menu as per user's OS theme.By defualt |
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 see on how we structure all other modules, i.e.:
- make an
init
method - import the module as a dependency instead of adding a custom include line in the HTML
/* this function changes screenshot in the options menu as per user's OS theme.By defualt | ||
a user will see light themed screenshot but if the user has enabled dark theme | ||
in their OS the they would see dark-themed screenshot. It makes use of the following CSS media query | ||
and detects its change of state by attaching a js listener to 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.
This comment is not JSDoc. Please document the function (too), it has a specific format. (just look it up, there are likely also plugins)
hi @rugk ...I fixed as per your latest review. not really sure about the module thing really. I tried to mimic the code in other module. Luckily browser testing passed. Please see if this is what you wanted. |
@@ -0,0 +1,15 @@ | |||
/** | |||
* // does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 |
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.
no comment in comments 😜
* // does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 | |
* does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 |
@@ -0,0 +1,15 @@ | |||
/** | |||
* // does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 |
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 please explain the function's objective etc, as it is best practise for JSDoc.
@@ -0,0 +1,15 @@ | |||
/** | |||
* // does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 | |||
* @param {} darkQuery |
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.
type missing:
* @param {} darkQuery | |
* @param {object} darkQuery |
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.
(or maybe Object
– pls check eslint, don't know it out of my head 😆 )
src/options/options.html
Outdated
@@ -10,6 +10,8 @@ | |||
|
|||
<script defer src="../common/common.js" type="module"></script> | |||
<script defer src="./options.js" type="module"></script> | |||
<script defer src="./modules/ColorSchemeModeHelper.js" type="module"></script> |
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.
can be removed now?
src/options/options.js
Outdated
// init modules | ||
CustomOptionTriggers.registerTrigger(); | ||
AutomaticSettings.setDefaultOptionProvider(AddonSettings.getDefaultValue); | ||
AutomaticSettings.init(); | ||
ColorSchemeModeHelper.changeScreenshotTheme(); |
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.
nah… rather call it simply init
here and structure the ColorSchemeModeHelper
better to have a private function that does this internal stuff. Again, look at the other modules.
Hi @rugk pls check if this is what you wanted. All tests pass. |
@@ -9,6 +14,7 @@ export function changeScreenshotTheme(darkQuery){ | |||
} else { | |||
document.getElementById("searchBarDemo").src = "./img/emojiSearchDog_light.png"; | |||
} | |||
return ColorSchemeModeHelper.changeScreenshotTheme(darkQuery); |
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 this change? (pls always do so)
Because AFAIK this should not work.
Please read https://hacks.mozilla.org/2015/08/es6-in-depth-modules/ or similar in order to understand how these modules work.
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 tested it on Firefox dev edition by changing my OS theme and yes it worked fine. Are we talking about some other tests?
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.
return ColorSchemeModeHelper.changeScreenshotTheme(darkQuery); | ||
} | ||
|
||
dark.addListener(changeScreenshotTheme); |
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 mentioned, put this into an init
method.
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 really have no idea how to do that. I tried to mimic how the existing modules were written. would you pls provide an example?
src/options/options.html
Outdated
@@ -10,6 +10,8 @@ | |||
|
|||
<script defer src="../common/common.js" type="module"></script> | |||
<script defer src="./options.js" type="module"></script> | |||
|
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.
see the diff and remove these new empty lines, you've added pls
@rugk I tested these changes on FF dev edition and they worked as expected. However I'm not really getting what you mean when you say put the function in |
Some tip:
|
…ving some whitespaces
@rugk was I supposed to do sth like this? |
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.
Yeah…
That looks almost good to go, just one minor change.
* does not work in Firefox currently due to https://bugzilla.mozilla.org/show_bug.cgi?id=1595037 | ||
* @param {Object} darkQuery | ||
*/ | ||
const dark = window.matchMedia("(prefers-color-scheme: dark)"); |
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.
Let's please move this line into the init
method, so all code is in some function.
} | ||
} | ||
|
||
dark.addListener(changeScreenshotTheme); |
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.
Ah and this also into the ìnit
function pls.
@rugk done |
LGTM now, and you can BTW request a review at the top right on GitHub PRs. (for the next time 😃 ) I'll do some final tests and will merge it. |
Thanks a lot for your patience @rugk . I'm glad I learnt a lot from bugging you :D |
* empty line * grammar in description * also space after brackets
Next time: |
as per issue #59 @rugk would you please check if it works. I am having some wierd issues after I change theme in OS and reload. Please get back if you can figure out the problem.