mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-02 13:27:33 +09:00
parent
89ae9a0b36
commit
035134a520
3 changed files with 2 additions and 93 deletions
|
|
@ -70,8 +70,6 @@ var AboutReader = function(win, articlePromise) {
|
||||||
|
|
||||||
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
||||||
|
|
||||||
doc.addEventListener("visibilitychange", this);
|
|
||||||
|
|
||||||
this._setupStyleDropdown();
|
this._setupStyleDropdown();
|
||||||
this._setupButton("close-button", this._onReaderClose.bind(this), "aboutReader.toolbar.close");
|
this._setupButton("close-button", this._onReaderClose.bind(this), "aboutReader.toolbar.close");
|
||||||
|
|
||||||
|
|
@ -238,14 +236,6 @@ AboutReader.prototype = {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "devicelight":
|
|
||||||
this._handleDeviceLight(aEvent.value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "visibilitychange":
|
|
||||||
this._handleVisibilityChange();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pagehide":
|
case "pagehide":
|
||||||
// Close the Banners Font-dropdown, cleanup Android BackPressListener.
|
// Close the Banners Font-dropdown, cleanup Android BackPressListener.
|
||||||
this._closeDropdowns();
|
this._closeDropdowns();
|
||||||
|
|
@ -310,10 +300,6 @@ AboutReader.prototype = {
|
||||||
const FONT_SIZE_MIN = 1;
|
const FONT_SIZE_MIN = 1;
|
||||||
const FONT_SIZE_MAX = 9;
|
const FONT_SIZE_MAX = 9;
|
||||||
|
|
||||||
// Sample text shown in Android UI.
|
|
||||||
let sampleText = this._doc.querySelector(".font-size-sample");
|
|
||||||
sampleText.textContent = gStrings.GetStringFromName("aboutReader.fontTypeSample");
|
|
||||||
|
|
||||||
let currentSize = Services.prefs.getIntPref("reader.font_size");
|
let currentSize = Services.prefs.getIntPref("reader.font_size");
|
||||||
currentSize = Math.max(FONT_SIZE_MIN, Math.min(FONT_SIZE_MAX, currentSize));
|
currentSize = Math.max(FONT_SIZE_MIN, Math.min(FONT_SIZE_MAX, currentSize));
|
||||||
|
|
||||||
|
|
@ -503,77 +489,8 @@ AboutReader.prototype = {
|
||||||
}, true);
|
}, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleDeviceLight(newLux) {
|
|
||||||
// Desired size of the this._luxValues array.
|
|
||||||
let luxValuesSize = 10;
|
|
||||||
// Add new lux value at the front of the array.
|
|
||||||
this._luxValues.unshift(newLux);
|
|
||||||
// Add new lux value to this._totalLux for averaging later.
|
|
||||||
this._totalLux += newLux;
|
|
||||||
|
|
||||||
// Don't update when length of array is less than luxValuesSize except when it is 1.
|
|
||||||
if (this._luxValues.length < luxValuesSize) {
|
|
||||||
// Use the first lux value to set the color scheme until our array equals luxValuesSize.
|
|
||||||
if (this._luxValues.length == 1) {
|
|
||||||
this._updateColorScheme(newLux);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Holds the average of the lux values collected in this._luxValues.
|
|
||||||
let averageLuxValue = this._totalLux / luxValuesSize;
|
|
||||||
|
|
||||||
this._updateColorScheme(averageLuxValue);
|
|
||||||
// Pop the oldest value off the array.
|
|
||||||
let oldLux = this._luxValues.pop();
|
|
||||||
// Subtract oldLux since it has been discarded from the array.
|
|
||||||
this._totalLux -= oldLux;
|
|
||||||
},
|
|
||||||
|
|
||||||
_handleVisibilityChange() {
|
|
||||||
let colorScheme = Services.prefs.getCharPref("reader.color_scheme");
|
|
||||||
if (colorScheme != "auto") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn off the ambient light sensor if the page is hidden
|
|
||||||
this._enableAmbientLighting(!this._doc.hidden);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Setup or teardown the ambient light tracking system.
|
|
||||||
_enableAmbientLighting(enable) {
|
|
||||||
if (enable) {
|
|
||||||
this._win.addEventListener("devicelight", this);
|
|
||||||
this._luxValues = [];
|
|
||||||
this._totalLux = 0;
|
|
||||||
} else {
|
|
||||||
this._win.removeEventListener("devicelight", this);
|
|
||||||
delete this._luxValues;
|
|
||||||
delete this._totalLux;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_updateColorScheme(luxValue) {
|
|
||||||
// Upper bound value for "dark" color scheme beyond which it changes to "light".
|
|
||||||
let upperBoundDark = 50;
|
|
||||||
// Lower bound value for "light" color scheme beyond which it changes to "dark".
|
|
||||||
let lowerBoundLight = 10;
|
|
||||||
// Threshold for color scheme change.
|
|
||||||
let colorChangeThreshold = 20;
|
|
||||||
|
|
||||||
// Ignore changes that are within a certain threshold of previous lux values.
|
|
||||||
if ((this._colorScheme === "dark" && luxValue < upperBoundDark) ||
|
|
||||||
(this._colorScheme === "light" && luxValue > lowerBoundLight))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (luxValue < colorChangeThreshold)
|
|
||||||
this._setColorScheme("dark");
|
|
||||||
else
|
|
||||||
this._setColorScheme("light");
|
|
||||||
},
|
|
||||||
|
|
||||||
_setColorScheme(newColorScheme) {
|
_setColorScheme(newColorScheme) {
|
||||||
// "auto" is not a real color scheme
|
if (this._colorScheme === newColorScheme)
|
||||||
if (this._colorScheme === newColorScheme || newColorScheme === "auto")
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let bodyClasses = this._doc.body.classList;
|
let bodyClasses = this._doc.body.classList;
|
||||||
|
|
@ -585,10 +502,8 @@ AboutReader.prototype = {
|
||||||
bodyClasses.add(this._colorScheme);
|
bodyClasses.add(this._colorScheme);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Pref values include "dark", "light", and "auto", which automatically switches
|
// Pref values include "dark", "light", and "sepia".
|
||||||
// between light and dark color schemes based on the ambient light level.
|
|
||||||
_setColorSchemePref(colorSchemePref) {
|
_setColorSchemePref(colorSchemePref) {
|
||||||
this._enableAmbientLighting(colorSchemePref === "auto");
|
|
||||||
this._setColorScheme(colorSchemePref);
|
this._setColorScheme(colorSchemePref);
|
||||||
|
|
||||||
AsyncPrefs.set("reader.color_scheme", colorSchemePref);
|
AsyncPrefs.set("reader.color_scheme", colorSchemePref);
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@
|
||||||
<hr>
|
<hr>
|
||||||
<div class="font-size-buttons">
|
<div class="font-size-buttons">
|
||||||
<button class="minus-button"/>
|
<button class="minus-button"/>
|
||||||
<button class="font-size-sample"/>
|
|
||||||
<button class="plus-button"/>
|
<button class="plus-button"/>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
||||||
|
|
@ -445,11 +445,6 @@ body:not(.loaded) .toolbar:-moz-locale-dir(rtl) {
|
||||||
background-color: #dadada;
|
background-color: #dadada;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only used on Android */
|
|
||||||
.font-size-sample {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.minus-button,
|
.minus-button,
|
||||||
.plus-button,
|
.plus-button,
|
||||||
.content-width-minus-button,
|
.content-width-minus-button,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue