Skip to content

Commit

Permalink
Determine icon color with CSS prefers-color-scheme feature #3401
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Oct 19, 2023
1 parent 08171b3 commit 00645f5
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 180 deletions.
5 changes: 0 additions & 5 deletions webextensions/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@
"config_suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation_label": { "message": "Nur wenn von einer Mausaktion auf der Seitenleiste ausgelöst" },
"config_showDialogInSidebar_label": { "message": "Zeige Dialoge in Seitenleiste falls möglich" },

"config_iconColor_caption": { "message": "Toolbar Icon Farbe:" },
"config_iconColor_auto": { "message": "Auto" },
"config_iconColor_bright": { "message": "für helles Theme" },
"config_iconColor_dark": { "message": "für dunkles Theme" },


"config_context_caption": { "message": "Kontexmenü" },
"config_emulateDefaultContextMenu_label": { "message": "Tab-Kontextmenü in der Seitenleiste simulieren" },
Expand Down
5 changes: 0 additions & 5 deletions webextensions/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@
"config_suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation_label": { "message": "Only when triggered by a mouse operation in the sidebar" },
"config_showDialogInSidebar_label": { "message": "Show dialogs in the sidebar if possible" },

"config_iconColor_caption": { "message": "Toolbar Icon Color:" },
"config_iconColor_auto": { "message": "Auto" },
"config_iconColor_bright": { "message": "for Bright Theme" },
"config_iconColor_dark": { "message": "for Dark Theme" },


"config_context_caption": { "message": "Context Menu" },
"config_emulateDefaultContextMenu_label": { "message": "Simulate Tab Context Menu on the sidebar" },
Expand Down
5 changes: 0 additions & 5 deletions webextensions/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@
"config_suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation_label": { "message": "サイドバーをマウスで操作した場合のみ抑制する" },
"config_showDialogInSidebar_label": { "message": "可能であればサイドバー内でダイアログを表示する" },

"config_iconColor_caption": { "message": "ツールバーアイコンの色:" },
"config_iconColor_auto": { "message": "自動" },
"config_iconColor_bright": { "message": "明るいテーマ用" },
"config_iconColor_dark": { "message": "暗いテーマ用" },


"config_context_caption": { "message": "コンテキストメニュー" },
"config_emulateDefaultContextMenu_label": { "message": "サイドバー上でタブのコンテキストメニューを再現する" },
Expand Down
5 changes: 0 additions & 5 deletions webextensions/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@
"config_suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation_label": { "message": "Только при щелчках на боковой панели." },
"config_showDialogInSidebar_label": { "message": "Показать диалоги на боковой панели, если возможно" },

"config_iconColor_caption": { "message": "Цвет значка панели:" },
"config_iconColor_auto": { "message": "Авто" },
"config_iconColor_bright": { "message": "для светлой темы" },
"config_iconColor_dark": { "message": "для темной темы" },


"config_context_caption": { "message": "Контекстное меню" },
"config_emulateDefaultContextMenu_label": { "message": "Имитация контекстного меню вкладок на боковой панели" },
Expand Down
12 changes: 0 additions & 12 deletions webextensions/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,6 @@
"config_showDialogInSidebar_label": {
"message": "在侧栏中显示对话框(如果可能的话)"
},
"config_iconColor_caption": {
"message": "工具栏图标颜色:"
},
"config_iconColor_auto": {
"message": "自动"
},
"config_iconColor_bright": {
"message": "匹配明亮主题"
},
"config_iconColor_dark": {
"message": "匹配深邃主题"
},
"config_context_caption": {
"message": "上下文菜单",
"hash": "b3bfec7867f2835dbcb05a2f1cf5647f"
Expand Down
5 changes: 0 additions & 5 deletions webextensions/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,6 @@
"config_suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation_label": { "message": "Only when triggered by a mouse operation in the sidebar" },
"config_showDialogInSidebar_label": { "message": "Show dialogs in the sidebar if possible" },

"config_iconColor_caption": { "message": "工具列圖示顏色:" },
"config_iconColor_auto": { "message": "自動" },
"config_iconColor_bright": { "message": "亮色主題" },
"config_iconColor_dark": { "message": "暗色主題" },


"config_context_caption": { "message": "快捷選單" },
"config_emulateDefaultContextMenu_label": { "message": "模擬分頁列上的快捷選單" },
Expand Down
32 changes: 2 additions & 30 deletions webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,6 @@ async function updateIconForBrowserTheme(theme) {
const menuIcons = {};
const sidebarIcons = {};

switch (configs.iconColor) {
case 'auto': {
if (!theme) {
const window = await browser.windows.getLastFocused();
theme = await browser.theme.getCurrent(window.id);
Expand All @@ -797,34 +795,12 @@ async function updateIconForBrowserTheme(theme) {
sidebarIcons[size] = `data:image/svg+xml,${escape(sidebarIconSource)}#default-theme`;
}));
}
else if (mDarkModeMatchMedia.matches) { // dark mode
for (const [size, url] of Object.entries(BASE_ICONS)) {
toolbarIcons[size] = `${url}#toolbar-dark`;
menuIcons[size] = sidebarIcons[size] = `${url}#default-dark`;
}
}
else {
for (const [size, url] of Object.entries(BASE_ICONS)) {
toolbarIcons[size] = `${url}#toolbar-bright`;
menuIcons[size] = sidebarIcons[size] = `${url}#default-bright`;
toolbarIcons[size] = `${url}#toolbar`;
menuIcons[size] = sidebarIcons[size] = `${url}#default`;
}
}
}; break;

case 'bright':
for (const [size, url] of Object.entries(BASE_ICONS)) {
toolbarIcons[size] = `${url}#toolbar-bright`;
menuIcons[size] = sidebarIcons[size] = `${url}#default-bright`;
}
break;

case 'dark':
for (const [size, url] of Object.entries(BASE_ICONS)) {
toolbarIcons[size] = `${url}#toolbar-dark`;
menuIcons[size] = sidebarIcons[size] = `${url}#default-dark`;
}
break;
}

log('updateIconForBrowserTheme: applying icons: ', {
toolbarIcons,
Expand Down Expand Up @@ -856,10 +832,6 @@ configs.$addObserver(key => {
updatePanelUrl();
break;

case 'iconColor':
updateIconForBrowserTheme();
break;

case 'debug':
EventListenerManager.debug = configs.debug;
break;
Expand Down
23 changes: 0 additions & 23 deletions webextensions/background/browser-action-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,6 @@ const mItems = [
key: 'showDialogInSidebar',
type: 'checkbox'
},
{
title: browser.i18n.getMessage('config_iconColor_caption'),
children: [
{
title: browser.i18n.getMessage('config_iconColor_auto'),
key: 'iconColor',
value: 'auto',
type: 'radio'
},
{
title: browser.i18n.getMessage('config_iconColor_bright'),
key: 'iconColor',
value: 'bright',
type: 'radio'
},
{
title: browser.i18n.getMessage('config_iconColor_dark'),
key: 'iconColor',
value: 'dark',
type: 'radio'
},
],
},
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions webextensions/common/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function bindToCheckbox(permissions, checkbox, options = {}) {
notify({
title: browser.i18n.getMessage('config_requestPermissions_fallbackToToolbarButton_title'),
message: browser.i18n.getMessage('config_requestPermissions_fallbackToToolbarButton_message'),
icon: 'resources/24x24.svg#default-bright'
icon: 'resources/24x24.svg#default'
});
return;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ export function bindToClickable(permissions, node, { onChanged } = {}) {
notify({
title: browser.i18n.getMessage('config_requestPermissions_fallbackToToolbarButton_title'),
message: browser.i18n.getMessage('config_requestPermissions_fallbackToToolbarButton_message'),
icon: 'resources/24x24.svg#default-bright'
icon: 'resources/24x24.svg#default'
});
return;
}
Expand Down
24 changes: 12 additions & 12 deletions webextensions/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
"tabHide"
],
"icons": {
"16": "/resources/16x16.svg#default-bright",
"20": "/resources/20x20.svg#default-bright",
"24": "/resources/24x24.svg#default-bright",
"32": "/resources/32x32.svg#default-bright"
"16": "/resources/16x16.svg#default",
"20": "/resources/20x20.svg#default",
"24": "/resources/24x24.svg#default",
"32": "/resources/32x32.svg#default"
},
"background": {
"page": "/background/background.html"
},
"browser_action": {
"default_title": "__MSG_sidebarTitle__",
"default_icon": {
"16": "/resources/16x16.svg#toolbar-bright",
"20": "/resources/20x20.svg#toolbar-bright",
"24": "/resources/24x24.svg#toolbar-bright",
"32": "/resources/32x32.svg#toolbar-bright"
"16": "/resources/16x16.svg#toolbar",
"20": "/resources/20x20.svg#toolbar",
"24": "/resources/24x24.svg#toolbar",
"32": "/resources/32x32.svg#toolbar"
}
},
"sidebar_action": {
"default_title": "__MSG_sidebarTitle__",
"default_icon": {
"16": "/resources/16x16.svg#default-bright",
"20": "/resources/20x20.svg#default-bright",
"24": "/resources/24x24.svg#default-bright",
"32": "/resources/32x32.svg#default-bright"
"16": "/resources/16x16.svg#default",
"20": "/resources/20x20.svg#default",
"24": "/resources/24x24.svg#default",
"32": "/resources/32x32.svg#default"
},
"default_panel": "/sidebar/sidebar.html",
"browser_style": false
Expand Down
17 changes: 0 additions & 17 deletions webextensions/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,6 @@ <h1>__MSG_config_appearance_caption__</h1>
><input id="showDialogInSidebar"
type="checkbox">
__MSG_config_showDialogInSidebar_label__</label></p>
<p>__MSG_config_iconColor_caption__
<label class="has-radio inline"
><input type="radio"
name="iconColor"
value="auto">
__MSG_config_iconColor_auto__</label>
<label class="has-radio inline"
><input type="radio"
name="iconColor"
value="bright">
__MSG_config_iconColor_bright__</label>
<label class="has-radio inline"
><input type="radio"
name="iconColor"
value="dark">
__MSG_config_iconColor_dark__</label>
</p>

</section>

Expand Down
23 changes: 11 additions & 12 deletions webextensions/resources/16x16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 11 additions & 12 deletions webextensions/resources/20x20.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 11 additions & 12 deletions webextensions/resources/24x24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 00645f5

Please sign in to comment.