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

adding screenshots and ability to change based on OS theme #65

Merged
merged 10 commits into from
Nov 10, 2019

Conversation

silvererudite
Copy link
Contributor

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.

@rugk
Copy link
Owner

rugk commented Oct 21, 2019

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

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.

I am having some wierd issues after I change theme in OS and reload

Could you describe what issue you actually have? AFAIK you need to restart Firefox to properly apply the theme, possibly.

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.

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.

@@ -3,3 +3,11 @@
.float-image {
margin: 10px;
}

@media (prefers-color-scheme: dark) {

Copy link
Owner

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.

@@ -20,3 +20,12 @@ RandomTips.init(tips).then(() => {
RandomTips.setContext("options");
RandomTips.showRandomTipIfWanted();
});

let dark= window.matchMedia('@media (prefers-color-scheme: dark)');
Copy link
Owner

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. 😄

if(dark){
document.getElementById('searchBarDemo').src="./img/emojiSearchDog_dark.png";
}
else if(light){
Copy link
Owner

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).

@rugk
Copy link
Owner

rugk commented Oct 28, 2019

@silvererudite If you need any pointers/help or have questions, feel free to ask.

@rugk
Copy link
Owner

rugk commented Nov 7, 2019

@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.

@silvererudite
Copy link
Contributor Author

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?
p.s I will push a clean commit at the end with your other suggested changes once I can make this work. thanks alot for being patient

* 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
@rugk
Copy link
Owner

rugk commented Nov 8, 2019

Okay, pulled your change and fixed some things. Specifically:

  • is is addListener, not addEventListener
  • only register for dark version, not retrigger for light version
  • the .matchMedia() query string was wrong (not include @media)

While testing please also note:

  • in Linux/GNOME at least, you need to restart Firefox, so the change cannot be live-reloaded (tell me if you experience something else)
    This is not bad, but we have implemented it, at least, already. As I guess this is a bug in Firefox, I've reported it here: https://bugzilla.mozilla.org/show_bug.cgi?id=1595037

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.

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

@silvererudite
Copy link
Contributor Author

@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

@silvererudite
Copy link
Contributor Author

silvererudite commented Nov 8, 2019

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
As you suggested I used eslint for this commit now. I have also tested it using Firefox Dev edition 71.0 and it works fine. Please take a look and get back if I missed something.

@rugk
Copy link
Owner

rugk commented Nov 8, 2019

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
Copy link
Owner

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.
Copy link
Owner

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)

src/options/modules/ColorSchemeModeHelper.js Outdated Show resolved Hide resolved
@silvererudite
Copy link
Contributor Author

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
Copy link
Owner

Choose a reason for hiding this comment

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

no comment in comments 😜

Suggested change
* // 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
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

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

type missing:

Suggested change
* @param {} darkQuery
* @param {object} darkQuery

Copy link
Owner

@rugk rugk Nov 8, 2019

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 😆 )

@@ -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>
Copy link
Owner

Choose a reason for hiding this comment

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

can be removed now?

// init modules
CustomOptionTriggers.registerTrigger();
AutomaticSettings.setDefaultOptionProvider(AddonSettings.getDefaultValue);
AutomaticSettings.init();
ColorSchemeModeHelper.changeScreenshotTheme();
Copy link
Owner

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.

@silvererudite
Copy link
Contributor Author

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);
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 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.

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 tested it on Firefox dev edition by changing my OS theme and yes it worked fine. Are we talking about some other tests?

Copy link
Owner

Choose a reason for hiding this comment

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

Well, no other tests, just usual dev testing.

Because it may work, but not without side-effects. Here is an exception thrown if you look into the debugger:
exception

return ColorSchemeModeHelper.changeScreenshotTheme(darkQuery);
}

dark.addListener(changeScreenshotTheme);
Copy link
Owner

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.

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 really have no idea how to do that. I tried to mimic how the existing modules were written. would you pls provide an example?

@@ -10,6 +10,8 @@

<script defer src="../common/common.js" type="module"></script>
<script defer src="./options.js" type="module"></script>

Copy link
Owner

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

@silvererudite
Copy link
Contributor Author

@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 init method as I've not done sth like it in the past and not getting a clear idea form the existing modules. However I tried too mimic them as much as I could.
Would you pls provide an example for how to do so or maybe point me to some related reading so that i can learn?

@rugk
Copy link
Owner

rugk commented Nov 9, 2019

Some tip:

@silvererudite
Copy link
Contributor Author

@rugk was I supposed to do sth like this?

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.

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)");
Copy link
Owner

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);
Copy link
Owner

@rugk rugk Nov 10, 2019

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.

@silvererudite
Copy link
Contributor Author

@rugk done

@rugk
Copy link
Owner

rugk commented Nov 10, 2019

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.

@silvererudite
Copy link
Contributor Author

Thanks a lot for your patience @rugk . I'm glad I learnt a lot from bugging you :D
I look forward to contributing more to the project

@rugk
Copy link
Owner

rugk commented Nov 10, 2019

So just did some small changes by myself now. However please take a look at them to learn what you've missed to do:

eslint requires @returns:
grafik

see the commit message for other details

* empty line
* grammar in description
* also space after brackets
@rugk
Copy link
Owner

rugk commented Nov 10, 2019

Next time:
You can (automatically) let issues close when a PR is merged by adding some "magic" text to your PR body.

@rugk rugk merged commit 7fea7e8 into rugk:master Nov 10, 2019
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.

2 participants