Night Mode System Settings on Android client.
This commit is contained in:
+27
-6
@@ -6,6 +6,7 @@
|
|||||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#000000" />
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta name="color-scheme" content="dark light"/> <!-- uses media queries in web views. -->
|
||||||
<meta name="description" content="PiPedal Guitar Pedals" />
|
<meta name="description" content="PiPedal Guitar Pedals" />
|
||||||
<!--
|
<!--
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
|
||||||
@@ -42,19 +43,39 @@
|
|||||||
<script>
|
<script>
|
||||||
const androidHosted = !!(window.AndroidHost);
|
const androidHosted = !!(window.AndroidHost);
|
||||||
|
|
||||||
|
var colorScheme = localStorage.getItem("colorScheme");
|
||||||
|
if (androidHosted)
|
||||||
|
{
|
||||||
|
var hostColorScheme = window.AndroidHost.getThemePreference();
|
||||||
|
switch (hostColorScheme)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
colorScheme = "Light";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorScheme = "Dark";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
// use the host's interpretation of the current system night mode.
|
||||||
|
colorScheme = window.AndroidHost.isDarkTheme() ? "Dark": "Light";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!colorScheme)
|
||||||
|
{
|
||||||
|
colorScheme = "Dark";
|
||||||
|
}
|
||||||
var darkMode = false;
|
var darkMode = false;
|
||||||
var useSystem = false;
|
var useSystem = false;
|
||||||
|
|
||||||
var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
|
||||||
switch (localStorage.getItem("colorScheme")) {
|
switch (colorScheme) {
|
||||||
case null:
|
case null:
|
||||||
default:
|
default:
|
||||||
if (androidHosted) {
|
|
||||||
useSystem = true;
|
|
||||||
} else {
|
|
||||||
darkMode = false;
|
darkMode = false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Light":
|
case "Light":
|
||||||
@@ -68,7 +89,7 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (useSystem) {
|
if (useSystem) {
|
||||||
darkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
darkMode = prefersDark;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!darkMode) {
|
if (!darkMode) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export interface AndroidHostInterface {
|
|||||||
launchExternalUrl(url:string): boolean;
|
launchExternalUrl(url:string): boolean;
|
||||||
setThemePreference(theme: number): void;
|
setThemePreference(theme: number): void;
|
||||||
getThemePreference(): number;
|
getThemePreference(): number;
|
||||||
|
isDarkTheme?: ()=> boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class FakeAndroidHost implements AndroidHostInterface
|
export class FakeAndroidHost implements AndroidHostInterface
|
||||||
@@ -43,6 +44,9 @@ export class FakeAndroidHost implements AndroidHostInterface
|
|||||||
}
|
}
|
||||||
chooseNewDevice(): void {
|
chooseNewDevice(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
isDarkTheme(): boolean {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
setDisconnected(isDisconnected: boolean): void {
|
setDisconnected(isDisconnected: boolean): void {
|
||||||
|
|
||||||
|
|||||||
+27
-3
@@ -17,7 +17,7 @@
|
|||||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import { AndroidHostInterface } from "./AndroidHost";
|
import { AndroidHostInterface, getAndroidHost } from "./AndroidHost";
|
||||||
|
|
||||||
export enum ColorTheme {
|
export enum ColorTheme {
|
||||||
Light,
|
Light,
|
||||||
@@ -25,7 +25,16 @@ export enum ColorTheme {
|
|||||||
System
|
System
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getEffectiveColorScheme(): ColorTheme {
|
||||||
|
let androidHost = (window as any).AndroidHost as AndroidHostInterface;
|
||||||
|
if (androidHost) {
|
||||||
|
if (androidHost.isDarkTheme)
|
||||||
|
return androidHost.isDarkTheme() ? ColorTheme.Dark: ColorTheme.Light;
|
||||||
|
return ColorTheme.Dark;
|
||||||
|
}
|
||||||
|
return getColorScheme();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export function getColorScheme(): ColorTheme {
|
export function getColorScheme(): ColorTheme {
|
||||||
let androidHost = (window as any).AndroidHost as AndroidHostInterface;
|
let androidHost = (window as any).AndroidHost as AndroidHostInterface;
|
||||||
@@ -85,13 +94,28 @@ export function setColorScheme(value: ColorTheme): void {
|
|||||||
localStorage.setItem("colorScheme", storageValue);
|
localStorage.setItem("colorScheme", storageValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gIsDarkTheme: boolean| undefined = undefined;
|
||||||
|
|
||||||
export function isDarkMode(): boolean {
|
export function isDarkMode(): boolean {
|
||||||
|
if (gIsDarkTheme !== undefined)
|
||||||
|
{
|
||||||
|
return gIsDarkTheme;
|
||||||
|
}
|
||||||
var colorTheme = getColorScheme();
|
var colorTheme = getColorScheme();
|
||||||
if (colorTheme === ColorTheme.System) {
|
if (colorTheme === ColorTheme.System) {
|
||||||
|
let androidHost = getAndroidHost();
|
||||||
|
if (androidHost)
|
||||||
|
{
|
||||||
|
if (androidHost.isDarkTheme)
|
||||||
|
{
|
||||||
|
return gIsDarkTheme = androidHost.isDarkTheme();
|
||||||
|
}
|
||||||
|
return gIsDarkTheme = true;
|
||||||
|
}
|
||||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
return true;
|
return gIsDarkTheme = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return colorTheme === ColorTheme.Dark;
|
return gIsDarkTheme = (colorTheme === ColorTheme.Dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user