Refactor theme detection
This commit is contained in:
parent
c420699e51
commit
a62a882791
4 changed files with 31 additions and 29 deletions
|
@ -29,6 +29,7 @@ let collapseWhitespace = false;
|
|||
let TurndownService = null;
|
||||
let userTheme = 'auto';
|
||||
let currentTheme = 'light';
|
||||
let detectSystemTheme;
|
||||
|
||||
function normalizeRules(rules) {
|
||||
return Array.isArray(rules) ? rules.map(r => {
|
||||
|
@ -50,24 +51,6 @@ function iconPaths(name) {
|
|||
};
|
||||
}
|
||||
|
||||
async function detectSystemTheme() {
|
||||
try {
|
||||
const t = await browser.theme.getCurrent();
|
||||
const scheme = t?.properties?.color_scheme;
|
||||
if (scheme === 'dark' || scheme === 'light') {
|
||||
return scheme;
|
||||
}
|
||||
const color = t?.colors?.frame || t?.colors?.toolbar;
|
||||
if (color && /^#/.test(color)) {
|
||||
const r = parseInt(color.slice(1, 3), 16);
|
||||
const g = parseInt(color.slice(3, 5), 16);
|
||||
const b = parseInt(color.slice(5, 7), 16);
|
||||
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||
return lum < 0.5 ? 'dark' : 'light';
|
||||
}
|
||||
} catch {}
|
||||
return 'light';
|
||||
}
|
||||
|
||||
const ICONS = {
|
||||
logo: () => 'resources/img/logo.png',
|
||||
|
@ -298,6 +281,7 @@ async function clearCacheForMessages(idsInput) {
|
|||
|
||||
(async () => {
|
||||
logger = await import(browser.runtime.getURL("logger.js"));
|
||||
({ detectSystemTheme } = await import(browser.runtime.getURL('modules/themeUtils.js')));
|
||||
try {
|
||||
AiClassifier = await import(browser.runtime.getURL("modules/AiClassifier.js"));
|
||||
logger.aiLog("AiClassifier imported", { debug: true });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue