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

#7622: Add support for MV3 to setToolbarIcon via chrome.offscreen #7634

Closed
wants to merge 3 commits into from

Conversation

fregante
Copy link
Contributor

What does this PR do?

Demo

wip

Checklist

  • Add tests
  • New files added to src/tsconfig.strictNullChecks.json (if possible)
  • Designate a primary reviewer

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 72.77%. Comparing base (963c1fd) to head (b766a62).
Report is 114 commits behind head on main.

Files Patch % Lines
src/background/activateBrowserActionIcon.ts 84.61% 2 Missing ⚠️
src/background/partnerTheme.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7634   +/-   ##
=======================================
  Coverage   72.77%   72.77%           
=======================================
  Files        1225     1226    +1     
  Lines       38212    38213    +1     
  Branches     7185     7184    -1     
=======================================
+ Hits        27808    27809    +1     
  Misses      10404    10404           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fregante
Copy link
Contributor Author

I'll close this until #7632 is done and other related work is finished. I thought it was

@fregante fregante closed this Feb 16, 2024
@grahamlangford
Copy link
Collaborator

@fregante you should be good to re-open this now.

@fregante fregante reopened this Mar 5, 2024
@@ -30,12 +29,12 @@ async function setToolbarIcon(): Promise<void> {
const activeTheme = await getActiveTheme();

if (activeTheme === DEFAULT_THEME) {
await activateBrowserActionIcon();
// Not necessary. If the theme is ever unset, just reload the extension to reset the icon.
Copy link
Collaborator

@mnholtz mnholtz Mar 5, 2024

Choose a reason for hiding this comment

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

Why not reset to the default logo though? Can it hurt? It seems more convenient to just have it set here rather then having to go out of your way to reset the extension. e.g. I'm thinking about the use-case of the sales team doing demos with custom branding and switching themes often

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep in mind that this PR is old and based on old theme code. I need to rebase it and rework it. I just reopened it to keep track of my tasks this week.

assertNotNullish(context, "Failed to get 2D context for canvas"); // Impossible

// Note: Images that are not square will be stretched to fit the canvas, unless
// they're SVGs and the preserveAspectRatio attribute is set.
Copy link
Collaborator

Choose a reason for hiding this comment

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

unless they're SVGs and the preserveAspectRatio attribute is set.

In which case, what happens? Does it get truncated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raster images are just stretched. SVG images are mostly fine I think as long as there's a viewBox attribute. The preserveAspectRatio thing might only be required in some browsers. I didn't investigate all the scenarios, but in short SVGs can be authored with a specific scaling behavior.

const imageBitmap = await createImageBitmap(blob);

const context = new OffscreenCanvas(width, height).getContext("2d");
assertNotNullish(context, "Failed to get 2D context for canvas"); // Impossible
Copy link
Collaborator

Choose a reason for hiding this comment

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

Impossible

Is typescript strictNull complaining here?

Copy link
Contributor Author

@fregante fregante Mar 5, 2024

Choose a reason for hiding this comment

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

Yes. The context can be null if you request an unsupported type I suppose. I could alternatively fix the global types but I think here I just copied an existing null check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I could alternatively fix the global types but I think here I just copied an existing null check.

I don't have a strong opinion that you go out of your way to do that. Obviously only makes the code marginally less verbose

@fregante fregante changed the title #7622: Add support for MV3 to setToolbarIcon and fix theme support #7622: Add support for MV3 to setToolbarIcon via chrome.offscreen Mar 6, 2024
@twschiller twschiller added this to the 1.8.11 milestone Mar 7, 2024
@fregante
Copy link
Contributor Author

fregante commented Mar 7, 2024

I'll just close this for now and open a new one. Most of the underlying code changed here.

The tracking ticket is #7622

@fregante fregante closed this Mar 7, 2024
@fregante fregante deleted the F/mv3/browser-action-icon branch March 7, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

MV3 support for custom browser action icon
4 participants