Skip to content

Commit

Permalink
updateIcon: Respect system colour scheme (go-shiori#71)
Browse files Browse the repository at this point in the history
Currently the extension toolbar icon does not respect the selected colour scheme (light/dark mode). This causes the light-mode icon to be used on a dark mode toolbar, thus making the icon almost unreadable.

This change implements a simple check that picks the correct icon based on the system's colour scheme instead.
  • Loading branch information
tsukasa authored May 18, 2024
1 parent bf4835e commit cff781d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions js/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,15 @@ async function saveBookmark(tags) {
}

async function updateIcon() {
// Determine the colour scheme for the icons
var colourScheme = getDarkModeEnabled() ? "light" : "default";

// Set initial icon
var runtimeUrl = await browser.runtime.getURL("/"),
icon = {path: {
16: "icons/action-default-16.png",
32: "icons/action-default-32.png",
64: "icons/action-default-64.png"
16: `icons/action-${colourScheme}-16.png`,
32: `icons/action-${colourScheme}-32.png`,
64: `icons/action-${colourScheme}-64.png`
}};

// Firefox allows using empty object as default icon.
Expand Down Expand Up @@ -290,6 +293,11 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
return task;
});

// Check if dark mode is enabled
function getDarkModeEnabled() {
return window.matchMedia("(prefers-color-scheme: dark)").matches || false;
}

// Add handler for icon change
function updateActiveTab() {
updateIcon().catch(err => console.error(err.message));
Expand Down

0 comments on commit cff781d

Please sign in to comment.