Skip to content

Commit

Permalink
Merge pull request #17222 from Snuffleupagus/rm-viewerCssTheme
Browse files Browse the repository at this point in the history
Remove the `viewerCssTheme`-option, since it's partially broken
  • Loading branch information
Snuffleupagus committed Nov 4, 2023
2 parents 87c83ab + d46578e commit 50f52b4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 64 deletions.
11 changes: 0 additions & 11 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
{
"type": "object",
"properties": {
"viewerCssTheme": {
"title": "Theme",
"description": "The theme to use.\n0 = Use system theme.\n1 = Light theme.\n2 = Dark theme.",
"type": "integer",
"enum": [
0,
1,
2
],
"default": 2
},
"showPreviousViewOnLoad": {
"description": "DEPRECATED. Set viewOnLoad to 1 to disable showing the last page/position on load.",
"type": "boolean",
Expand Down
48 changes: 0 additions & 48 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ const ViewOnLoad = {
INITIAL: 1,
};

const ViewerCssTheme = {
AUTOMATIC: 0, // Default value.
LIGHT: 1,
DARK: 2,
};

class DefaultExternalServices {
constructor() {
throw new Error("Cannot initialize DefaultExternalServices.");
Expand Down Expand Up @@ -233,7 +227,6 @@ const PDFViewerApplication = {
if (AppOptions.get("pdfBugEnabled")) {
await this._parseHashParams();
}
this._forceCssTheme();

// Ensure that the `L10n`-instance has been initialized before creating
// e.g. the various viewer components.
Expand Down Expand Up @@ -347,47 +340,6 @@ const PDFViewerApplication = {
}
},

/**
* @private
*/
_forceCssTheme() {
const cssTheme = AppOptions.get("viewerCssTheme");
if (
cssTheme === ViewerCssTheme.AUTOMATIC ||
!Object.values(ViewerCssTheme).includes(cssTheme)
) {
return;
}
try {
const styleSheet = document.styleSheets[0];
const cssRules = styleSheet?.cssRules || [];
for (let i = 0, ii = cssRules.length; i < ii; i++) {
const rule = cssRules[i];
if (
rule instanceof CSSMediaRule &&
rule.media?.[0] === "(prefers-color-scheme: dark)"
) {
if (cssTheme === ViewerCssTheme.LIGHT) {
styleSheet.deleteRule(i);
return;
}
// cssTheme === ViewerCssTheme.DARK
const darkRules =
/^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(
rule.cssText
);
if (darkRules?.[1]) {
styleSheet.deleteRule(i);
styleSheet.insertRule(darkRules[1], i);
}
return;
}
}
} catch (reason) {
console.error(`_forceCssTheme: "${reason?.message}".`);
}
},

/**
* @private
*/
Expand Down
5 changes: 0 additions & 5 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ const defaultOptions = {
value: 1,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
viewerCssTheme: {
/** @type {number} */
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") ? 2 : 0,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
viewOnLoad: {
/** @type {boolean} */
value: 0,
Expand Down

0 comments on commit 50f52b4

Please sign in to comment.