Implement dark mode using color-scheme CSS property

This commit is contained in:
mooff 2023-05-16 05:14:19 +01:00 committed by Serhii Tereshchenko
parent 0ab9f5a72d
commit 2ef32d2d2d
5 changed files with 28 additions and 6 deletions

View file

@ -12,18 +12,23 @@ public class Accounts.SignatureWebView : Components.WebView {
private static WebKit.UserScript? app_script = null; private static WebKit.UserScript? app_script = null;
private static WebKit.UserStyleSheet? app_stylesheet = null;
public static new void load_resources() public static new void load_resources()
throws GLib.Error { throws GLib.Error {
SignatureWebView.app_script = Components.WebView.load_app_script( SignatureWebView.app_script = Components.WebView.load_app_script(
"signature-web-view.js" "signature-web-view.js"
); );
SignatureWebView.app_stylesheet = Components.WebView.load_app_stylesheet(
"signature-web-view.css"
);
} }
public SignatureWebView(Application.Configuration config) { public SignatureWebView(Application.Configuration config) {
base(config); base(config);
this.user_content_manager.add_script(SignatureWebView.app_script); this.user_content_manager.add_script(SignatureWebView.app_script);
this.user_content_manager.add_style_sheet(SignatureWebView.app_stylesheet);
} }
} }

View file

@ -3,12 +3,22 @@
* Copyright 2017 Michael Gratton <mike@vee.net> * Copyright 2017 Michael Gratton <mike@vee.net>
*/ */
:root {
/* Adjust default controls and system colors for light and dark mode.
See https://www.w3.org/TR/css-color-adjust-1/#color-scheme-effect */
color-scheme: light dark;
/* Apply canvas background to the root element, so body can darken
it using alpha. */
background-color: canvas;
}
body { body {
background-color: rgb(50% 50% 50% / .05);
margin: 0 !important; margin: 0 !important;
border: 0 !important; border: 0 !important;
padding: 0 !important; padding: 0 !important;
color: black;
background-color: #f9f9f9;
font-size: medium !important; font-size: medium !important;
} }
@ -40,7 +50,7 @@ body > div#geary-quote {
} }
body > div:focus-within { body > div:focus-within {
background-color: white; background-color: canvas;
} }
body > div#geary-signature:focus-within, body > div#geary-signature:focus-within,

View file

@ -13,9 +13,10 @@
transition: height 0.25s !important; transition: height 0.25s !important;
} }
html { :root {
color: black; /* Adjust default controls and system colors for light and dark mode.
background-color: white; See https://www.w3.org/TR/css-color-adjust-1/#color-scheme-effect */
color-scheme: light dark;
/* Width must always be defined by the viewport so content doesn't /* Width must always be defined by the viewport so content doesn't
overflow inside the WebView, height must always be defined by the overflow inside the WebView, height must always be defined by the

View file

@ -49,6 +49,7 @@
<file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file> <file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file compressed="true" preprocess="xml-stripblanks">password-dialog.glade</file> <file compressed="true" preprocess="xml-stripblanks">password-dialog.glade</file>
<file compressed="true" preprocess="xml-stripblanks">problem-details-dialog.ui</file> <file compressed="true" preprocess="xml-stripblanks">problem-details-dialog.ui</file>
<file compressed="true">signature-web-view.css</file>
<file compressed="true">signature-web-view.js</file> <file compressed="true">signature-web-view.js</file>
<file compressed="true">geary.css</file> <file compressed="true">geary.css</file>
<file compressed="true">single-key-shortcuts.css</file> <file compressed="true">single-key-shortcuts.css</file>

View file

@ -0,0 +1,5 @@
:root {
/* Adjust default controls and system colors for light and dark mode.
See https://www.w3.org/TR/css-color-adjust-1/#color-scheme-effect */
color-scheme: light dark;
}