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

dark-mode: Add a proposal for dark mode extension icons #585

Merged
merged 56 commits into from
May 9, 2024

Conversation

solomonkinard
Copy link
Contributor

@solomonkinard solomonkinard commented Apr 5, 2024

Proposal for #229

Copy link
Collaborator

@xeenon xeenon left a comment

Choose a reason for hiding this comment

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

Thanks for writing this up! This is looking good, but I have some overall concerns and questions that should be addressed.

proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
@xeenon xeenon requested review from zombie, dotproto and Rob--W April 6, 2024 00:33
@xeenon xeenon added supportive: chrome Supportive from Chrome supportive: safari Supportive from Safari needs-triage: firefox Firefox needs to assess this issue for the first time labels Apr 6, 2024
@solomonkinard
Copy link
Contributor Author

All comments addressed in the patch response. Thanks.

@xeenon xeenon added needs-triage: chrome Chrome needs to assess this issue for the first time and removed supportive: chrome Supportive from Chrome labels Apr 8, 2024
@xeenon xeenon requested review from rdcronin and oliverdunk April 8, 2024 23:34
Copy link
Member

@oliverdunk oliverdunk left a comment

Choose a reason for hiding this comment

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

Thanks for writing this up - we've been through so many iterations here that it's nice to have a single place to track what we're thinking. Left some initial thoughts.

proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Show resolved Hide resolved
@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Apr 10, 2024

@solomonkinard Thanks for putting this together!

The window.matchMedia('(prefers-color-scheme: dark)') trick would not work in serviceWorkers and more importantly, it would not work for dark browser themes.

Take for example the following theme:
https://chromewebstore.google.com/detail/mafbdhjdkjnoafhfelkjpchpaepjknad

This theme would want light-colored extension icons or they might be unreadable. Are browsers expected to use the "dark" variant of the extension icons in this situation?

A bit hesitant on the readability of yet another nesting object. A potential different approach would be to use a flat structure like this:

"icon_variants": [{
  "any": "16.svg",
  "type": "image/svg+xml"
}, {
  "16": "mono16.png",
  "32": "mono32.png",
  "type": "image/png",
  "purpose": "monochrome",
}, {
  "16": "[email protected]",
  "32": "[email protected]",
  "type": "image/png",
  "color_scheme": "dark",
  "density": "2dppx"
}, {
  "16": "light16.png",
  "32": "light32.png",
  "type": "image/png",
  "color_scheme": "light"
}, {
  "16": "default16.png",
  "32": "default32.png",
  "type": "image/png"
}]

This way we open ourselves up for future additions like the showcased monochrome (which would be helpful for Safari as they derive monochrome icons from normal extension icons currently). And a density property to handle details.

The browser would then pick the first object it understands and has matching conditions. This would allow extension developers to do several calls to setIcons with different syntaxes hoping the browser accept it.

This would also allow extension developers to specify both SVG and PNG icons and let the browser use SVG if supported, else fall back to PNG.

In the same fashion, dynamically setted icons could take imageData or dynamic svgs (as proposed by @xeenon here #462):

[{
  "16": imageDataSize16,
  "32": imageDataSize32,
  "type": ImageData
}, {
  "16": svgElement16,
  "32": svgElement32,
  "type": SVGElement
}]

Having the same syntax for dynamic and declarative icons seems ideal for developers.

Another benefit would be for a browser to pick the default icon in case the browser theme is neither dark nor light.

@xeenon
Copy link
Collaborator

xeenon commented Apr 29, 2024

There remains one aspect which we did not cover yet. How should browsers handle mixed types within the same icon group?

My initial thought on this would be ignore the full icon group and give a warning in the manifest when loading.

@carlosjeurissen How would you specify ImageData in the manifest? The manifest only supports paths. Maybe you mean JS APIs?

I think having the APIs only support one type per group (path or ImageData) seems best and is slightly easier to implement.

Supporting different image formats in one group is fine for Safari, we can support a mix of SVG and bitmap images.

@carlosjeurissen
Copy link
Contributor

@carlosjeurissen How would you specify ImageData in the manifest? The manifest only supports paths. Maybe you mean JS APIs?

The example was meant for both the manifest in setIcon. As for both we need to consider what to do with mixed types. ImageData is indeed not supported in the manifest.

I think having the APIs only support one type per group (path or ImageData) seems best and is slightly easier to implement.

One type per group is critical for simplifying the implementation of the fallback system.

Supporting different image formats in one group is fine for Safari, we can support a mix of SVG and bitmap images.

This might be true for Safari, but this can be problematic for Chrome as they currently do not support SVGs. However it is quite unlikely a developer would even mix SVGs with PNGs. @solomonkinard @oliverdunk Since this seems like a Chrome-only issue. What are your thoughts here?

@dotproto
Copy link
Member

This should be ["light", "dark"] and any other color_scheme we might want to add in the future. It specificially is not "light" as default.

Fixed.

@dotproto The path for any does not need to be an SVG, it can be a large bitmap that is scaled as needed for example. So this can drop SVGPath.

Ah, my mistake. Thanks for pointing that out. I've fixed this in my comment.

solomonkinard and others added 2 commits May 1, 2024 10:06
This incorporates the kernel of what Simeon discussed in WECG and
recommended in
w3c#585 (comment).
It's not meant to replace that comment, but only to introduce it here
for clarity, while allowing Simeon to update it as needed once this PR
is merged.

Added a fuzzy matching section again even though someone suggested it
be removed earlier. It was introduced in 6e6af62, but removed in a
subsequent "Commit suggestion" from somoene on GitHub. It's worth
calling out here at some point, so it might as well be in this PR,
which is already approved but still awaiting someone with the ability
to go ahead and merge it.

Some of these changes may foster discussion, which is completely
understandable.
Copy link
Member

@oliverdunk oliverdunk left a comment

Choose a reason for hiding this comment

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

In trying to move to TypeScript, I think we've introduced some new issues. Unfortunately those make the intention of the API design unclear enough that I think they need to be blockers. Left some initial feedback - while I very much appreciate the TypeScript types I also wouldn't be against just removing them so we can avoid leaving this PR open for too long.

proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
proposals/dark_mode_extension_icons.md Outdated Show resolved Hide resolved
@solomonkinard
Copy link
Contributor Author

The TypeScript schema section that Simeon recommended was removed. See #585 (review) for context. The PR was approved two weeks ago and awaiting merge; the TypeScript schema addition was added a week ago. Anyone, please share if there are any more comments blocking this PR from being merged. The latest PRs address all of the latest questions.

I think having the APIs only support one type per group (path or ImageData) seems best and is slightly easier to implement.

@solomonkinard @oliverdunk Since this seems like a Chrome-only issue. What are your thoughts here?

One type per group seems reasonable to make implementation easier. The PR has been updated in e1b23de.

@carlosjeurissen
Copy link
Contributor

One type per group seems reasonable to make implementation easier. The PR has been updated in e1b23de.

Sounds good. Yet we probably want to specify what would happen when mixed types are present. Should the whole icon group be marked as invalid? Should it throw an error in setIcon? Should it reject the whole manifest?

@solomonkinard
Copy link
Contributor Author

Yet we probably want to specify what would happen when mixed types are present. Should the whole icon group be marked as invalid? Should it throw an error in setIcon? Should it reject the whole manifest?

Added the following to the relevant section:

If more than one type is present in an icon group,
   the group can be ignored, marked as invalid and optionally show a warning
   during installation.

@solomonkinard
Copy link
Contributor Author

All merge-blocking comments should have been resolved at this point. If not, please advise. Otherwise, awaiting merge. Thanks.

@Rob--W Rob--W merged commit 61512ae into w3c:main May 9, 2024
3 checks passed
github-actions bot added a commit that referenced this pull request May 9, 2024
SHA: 61512ae
Reason: push, by Rob--W

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request May 9, 2024
SHA: 61512ae
Reason: push, by Rob--W

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@dotproto
Copy link
Member

dotproto commented May 9, 2024

… I also wouldn't be against just removing them so we can avoid leaving this PR open for too long.

No objections on my end. I'm a bit late on saying this, but I think it makes the most sense to land what we've all agreed on and introduce more explicit TypeScript types in a follow-on PR.

Thanks for all your work on this, @solomonkinard!

carlosjeurissen added a commit to carlosjeurissen/webextensions that referenced this pull request Jun 25, 2024
Co-authored-by: Rob Wu <[email protected]>
Co-authored-by: Oliver Dunk <[email protected]>
Co-authored-by: carlosjeurissen <[email protected]>
Co-authored-by: Timothy Hatcher <[email protected]>
Co-authored-by: Simeon Vincent <[email protected]>
@xeenon xeenon added implemented: safari Implemented in Safari and removed supportive: safari Supportive from Safari labels Sep 21, 2024
@carlosjeurissen
Copy link
Contributor

@solomonkinard Just tried the implementation in WebKit. Working great. An edge case came up tho. What if an extension which has only SVG icons defined in icon_variants gets loaded into Chrome once Chrome implemented icon_variants. What would it do? Will it fall back to the legacy icons?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implemented: safari Implemented in Safari supportive: chrome Supportive from Chrome supportive: firefox Supportive from Firefox
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants