Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic light/dark palette switching through matchMedia Listener and toggle Button #5085

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eb1a457
Create matchmedia.js
BurningTreeC Nov 21, 2020
cc59799
Update matchmedia.js
BurningTreeC Nov 21, 2020
b308604
Update CSS.tid
BurningTreeC Nov 21, 2020
aef4864
Create light-dark.tid
BurningTreeC Nov 21, 2020
d9dc510
Update Buttons.multids
BurningTreeC Nov 21, 2020
c22d325
Update light-dark.tid
BurningTreeC Nov 21, 2020
1374e96
Update PageControlButtons.multids
BurningTreeC Nov 21, 2020
50e23d4
Update framed.js
BurningTreeC Nov 21, 2020
5f16b3d
Update matchmedia.js
BurningTreeC Nov 21, 2020
84ccfc4
Update tag.tid
BurningTreeC Nov 21, 2020
6848ac4
Update TagTemplate.tid
BurningTreeC Nov 21, 2020
5aff843
Update tags.tid
BurningTreeC Nov 21, 2020
75fc0ff
Update light-dark.tid
BurningTreeC Nov 22, 2020
676b7a3
Update light-dark.tid
BurningTreeC Nov 22, 2020
4bd5158
Update Palette.tid
BurningTreeC Nov 22, 2020
20ba774
Create Light.tid
BurningTreeC Nov 22, 2020
55c68fe
Create Dark.tid
BurningTreeC Nov 22, 2020
b0048d4
Update paletteswitcher.tid
BurningTreeC Nov 22, 2020
edda124
Update PaletteManager.tid
BurningTreeC Nov 22, 2020
1748958
Update ControlPanel.multids
BurningTreeC Nov 22, 2020
4e4cf01
Delete matchmedia.js
BurningTreeC Nov 23, 2020
42dd393
Update platform.js
BurningTreeC Nov 23, 2020
fe2458d
Update Dark.tid
BurningTreeC Nov 23, 2020
725613c
Update tags.tid
BurningTreeC Nov 23, 2020
5debb6e
Update light-dark.tid
BurningTreeC Nov 23, 2020
fb51700
Update TagTemplate.tid
BurningTreeC Nov 23, 2020
28fc10e
Update platform.js
BurningTreeC Nov 23, 2020
95e04b2
Update tags.tid
BurningTreeC Nov 23, 2020
67c56c9
Update light-dark.tid
BurningTreeC Nov 23, 2020
8efa185
Update TagTemplate.tid
BurningTreeC Nov 23, 2020
2c8670f
Update CSS.tid
BurningTreeC Nov 23, 2020
0a07e0f
Update tag.tid
BurningTreeC Nov 23, 2020
e96a60b
Update tags.tid
BurningTreeC Nov 25, 2020
43d30d2
Update light-dark.tid
BurningTreeC Nov 25, 2020
274cb58
Update TagTemplate.tid
BurningTreeC Nov 25, 2020
bdd7d35
Update CSS.tid
BurningTreeC Nov 25, 2020
9bd014f
Update tag.tid
BurningTreeC Nov 25, 2020
48cd037
Update platform.js
BurningTreeC Nov 25, 2020
fced9b3
Create paletteDark.tid
BurningTreeC Nov 26, 2020
fb5f43d
Update palette.tid
BurningTreeC Nov 26, 2020
12c720b
Create AutoDarkMode.tid
BurningTreeC Nov 27, 2020
12e9660
Update palette.tid
BurningTreeC Nov 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/language/en-GB/Buttons.multids
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Home/Caption: home
Home/Hint: Open the default tiddlers
Language/Caption: language
Language/Hint: Choose the user interface language
LightDark/Caption: light/dark palette
LightDark/Hint: Switch between light and dark palettes
Manager/Caption: tiddler manager
Manager/Hint: Open tiddler manager
More/Caption: more
Expand Down
3 changes: 3 additions & 0 deletions core/language/en-GB/ControlPanel.multids
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ KeyboardShortcuts/Platform/Windows: Windows platform only
KeyboardShortcuts/Platform/NonWindows: Non-Windows platforms only
LoadedModules/Caption: Loaded Modules
LoadedModules/Hint: These are the currently loaded tiddler modules linked to their source tiddlers. Any italicised modules lack a source tiddler, typically because they were setup during the boot process.
Palette/AutoDarkMode/Hint: Enable automatic setting of Dark / Light Mode based on the OS configuration
Palette/Caption: Palette
Palette/Dark/Caption: Dark Palette
Palette/Editor/Clone/Caption: clone
Palette/Editor/Clone/Prompt: It is recommended that you clone this shadow palette before editing it
Palette/Editor/Delete/Hint: delete this entry from the current palette
Expand All @@ -55,6 +57,7 @@ Palette/Editor/Prompt/Modified: This shadow palette has been modified
Palette/Editor/Prompt: Editing
Palette/Editor/Reset/Caption: reset
Palette/HideEditor/Caption: hide editor
Palette/Light/Caption: Light Palette
Palette/Prompt: Current palette:
Palette/ShowEditor/Caption: show editor
Parsing/Caption: Parsing
Expand Down
2 changes: 0 additions & 2 deletions core/modules/editor/engines/framed.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function FramedEngine(options) {
this.iframeNode.style.border = "none";
this.iframeNode.style.padding = "0";
this.iframeNode.style.resize = "none";
this.iframeNode.style["background-color"] = this.widget.wiki.extractTiddlerDataItem(this.widget.wiki.getTiddlerText("$:/palette"),"tiddler-editor-background");
this.iframeDoc.body.style.margin = "0";
this.iframeDoc.body.style.padding = "0";
this.widget.domNodes.push(this.iframeNode);
Expand Down Expand Up @@ -100,7 +99,6 @@ FramedEngine.prototype.copyStyles = function() {
this.domNode.style.display = "block";
this.domNode.style.width = "100%";
this.domNode.style.margin = "0";
this.domNode.style["background-color"] = this.widget.wiki.extractTiddlerDataItem(this.widget.wiki.getTiddlerText("$:/palette"),"tiddler-editor-background");
// In Chrome setting -webkit-text-fill-color overrides the placeholder text colour
this.domNode.style["-webkit-text-fill-color"] = "currentcolor";
};
Expand Down
9 changes: 8 additions & 1 deletion core/modules/info/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Initialise basic platform $:/info/ tiddlers
/*global $tw: false */
"use strict";

exports.getInfoTiddlerFields = function() {
exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) {
var mapBoolean = function(value) {return value ? "yes" : "no";},
infoTiddlerFields = [];
// Basics
Expand All @@ -36,6 +36,13 @@ exports.getInfoTiddlerFields = function() {
// Screen size
infoTiddlerFields.push({title: "$:/info/browser/screen/width", text: window.screen.width.toString()});
infoTiddlerFields.push({title: "$:/info/browser/screen/height", text: window.screen.height.toString()});
// Dark mode through event listener on MediaQueryList
var mqList = window.matchMedia("(prefers-color-scheme: dark)"),
getDarkModeTiddler = function() {return {title: "$:/info/darkmode", text: mqList.matches ? "yes" : "no"};};
infoTiddlerFields.push(getDarkModeTiddler());
mqList.addListener(function(event) {
updateInfoTiddlersCallback([getDarkModeTiddler()]);
});
// Language
infoTiddlerFields.push({title: "$:/info/browser/language", text: navigator.language || ""});
}
Expand Down
15 changes: 2 additions & 13 deletions core/ui/ControlPanel/Palette.tid
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@ caption: {{$:/language/ControlPanel/Palette/Caption}}

\define lingo-base() $:/language/ControlPanel/Palette/

{{$:/snippets/paletteswitcher}}
<$checkbox tiddler="$:/config/AutoDarkMode" field="text" checked="yes" unchecked="no" default="no"> <<lingo AutoDarkMode/Hint>></$checkbox>

<$reveal type="nomatch" state="$:/state/ShowPaletteEditor" text="yes">

<$button set="$:/state/ShowPaletteEditor" setTo="yes"><<lingo ShowEditor/Caption>></$button>

</$reveal>

<$reveal type="match" state="$:/state/ShowPaletteEditor" text="yes">

<$button set="$:/state/ShowPaletteEditor" setTo="no"><<lingo HideEditor/Caption>></$button>
{{$:/PaletteManager}}

</$reveal>
<<tabs "$:/core/ui/ControlPanel/Palette/Light $:/core/ui/ControlPanel/Palette/Dark" "$:/core/ui/ControlPanel/Palette/Light">>

23 changes: 23 additions & 0 deletions core/ui/ControlPanel/Palette/Dark.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
title: $:/core/ui/ControlPanel/Palette/Dark
caption: {{$:/language/ControlPanel/Palette/Dark/Caption}}

\define lingo-base() $:/language/ControlPanel/Palette/

<$vars currPaletteTiddler="$:/paletteDark" state=<<qualify "$:/state/ShowPaletteEditor">>>

{{$:/snippets/paletteswitcher}}

<$reveal type="nomatch" state=<<state>> text="yes">

<$button set=<<state>> setTo="yes"><<lingo ShowEditor/Caption>></$button>

</$reveal>

<$reveal type="match" state=<<state>> text="yes">

<$button set=<<state>> setTo="no"><<lingo HideEditor/Caption>></$button>
{{$:/PaletteManager}}

</$reveal>

</$vars>
23 changes: 23 additions & 0 deletions core/ui/ControlPanel/Palette/Light.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
title: $:/core/ui/ControlPanel/Palette/Light
caption: {{$:/language/ControlPanel/Palette/Light/Caption}}

\define lingo-base() $:/language/ControlPanel/Palette/

<$vars currPaletteTiddler="$:/palette" state=<<qualify "$:/state/ShowPaletteEditor">>>

{{$:/snippets/paletteswitcher}}

<$reveal type="nomatch" state=<<state>> text="yes">

<$button set=<<state>> setTo="yes"><<lingo ShowEditor/Caption>></$button>

</$reveal>

<$reveal type="match" state=<<state>> text="yes">

<$button set=<<state>> setTo="no"><<lingo HideEditor/Caption>></$button>
{{$:/PaletteManager}}

</$reveal>

</$vars>
2 changes: 1 addition & 1 deletion core/ui/EditTemplate/tags.tid
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ color:$(foregroundColor)$;
\whitespace trim
<div class="tc-edit-tags">
<$list filter="[list[!!$tagField$]sort[title]]" storyview="pop">
<$macrocall $name="tag-body" colour={{!!color}} palette={{$:/palette}} icon={{!!icon}} tagField=<<__tagField__>>/>
<$macrocall $name="tag-body" colour={{!!color}} palette={{{ [{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]then{$:/paletteDark}] ~[{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]then{$:/paletteDark}] ~[{$:/palette}] }}} icon={{!!icon}} tagField=<<__tagField__>>/>
</$list>
<$vars tabIndex={{$:/config/EditTabIndex}} cancelPopups="yes">
<$macrocall $name="tag-picker" tagField=<<__tagField__>>/>
Expand Down
19 changes: 19 additions & 0 deletions core/ui/PageControls/light-dark.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
title: $:/core/ui/Buttons/light-dark
tags: $:/tags/PageControls
caption: {{$:/core/images/tip}} {{$:/language/Buttons/LightDark/Caption}}
description: {{$:/language/Buttons/LightDark/Hint}}

\whitespace trim
<$button class=<<tv-config-toolbar-class>> tooltip={{$:/language/Buttons/LightDark/Hint}}>
<$list filter="[{$:/config/AutoDarkMode}!match[yes]]">
<$action-listops $tiddler="$:/config/DarkMode" $field="text" $subfilter="+[toggle[yes],[no]]"/>
</$list>
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
<$list filter="[{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]] ~[{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]]" emptyMessage="""{{$:/core/images/tip}}""">
{{$:/core/images/tip}}
</$list>
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text"><$text text={{$:/language/Buttons/LightDark/Caption}}/></span>
</$list>
</$button>
2 changes: 2 additions & 0 deletions core/ui/PageControls/palette.tid
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: {{$:/language/Buttons/Palette/Hint}}
</span>
<$reveal state=<<qualify "$:/state/popup/palette">> type="popup" position="below" animate="yes">
<div class="tc-drop-down" style="font-size:0.7em;">
<$set name="currPaletteTiddler" value={{{ [{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]then[$:/paletteDark]] [{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]then[$:/paletteDark]] ~[[$:/palette]] }}}>
{{$:/snippets/paletteswitcher}}
</$set>
</div>
</$reveal>
8 changes: 4 additions & 4 deletions core/ui/PaletteManager.tid
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ title: $:/PaletteManager
</tbody>
</table>
\end
<$set name="currentTiddler" value={{$:/palette}}>
<$set name="currentTiddler" value={{{ [<currPaletteTiddler>get[text]] }}}>

<<lingo Prompt>> <$link to={{$:/palette}}><$macrocall $name="currentTiddler" $output="text/plain"/></$link>
<<lingo Prompt>> <$link to={{{ [<currPaletteTiddler>get[text]] }}}><$macrocall $name="currentTiddler" $output="text/plain"/></$link>

<$list filter="[all[current]is[shadow]is[tiddler]]" variable="listItem">
<<lingo Prompt/Modified>>
<$button message="tm-delete-tiddler" param={{$:/palette}}><<lingo Reset/Caption>></$button>
<$button message="tm-delete-tiddler" param={{{ [<currPaletteTiddler>get[text]] }}}><<lingo Reset/Caption>></$button>
</$list>

<$list filter="[all[current]is[shadow]!is[tiddler]]" variable="listItem">
<<lingo Clone/Prompt>>
</$list>

<$button message="tm-new-tiddler" param={{$:/palette}}><<lingo Clone/Caption>></$button>
<$button message="tm-new-tiddler" param={{{ [<currPaletteTiddler>get[text]] }}}><<lingo Clone/Caption>></$button>

<$checkbox tiddler="$:/state/palettemanager/showexternal" field="text" checked="yes" unchecked="no"><span class="tc-small-gap-left"><<lingo Names/External/Show>></span></$checkbox>

Expand Down
2 changes: 1 addition & 1 deletion core/ui/TagTemplate.tid
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: $:/core/ui/TagTemplate
\whitespace trim
<span class="tc-tag-list-item">
<$set name="transclusion" value=<<currentTiddler>>>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{{ [{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]then{$:/paletteDark}] ~[{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]then{$:/paletteDark}] ~[{$:/palette}] }}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$reveal state=<<qualify "$:/state/popup/tag">> type="popup" position="below" animate="yes" class="tc-drop-down">
<$set name="tv-show-missing-links" value="yes">
<$transclude tiddler="$:/core/ui/ListItemTemplate"/>
Expand Down
2 changes: 2 additions & 0 deletions core/wiki/config/AutoDarkMode.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: $:/config/AutoDarkMode
text: no
1 change: 1 addition & 0 deletions core/wiki/config/PageControlButtons.multids
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ core/ui/Buttons/refresh: hide
core/ui/Buttons/import: hide
core/ui/Buttons/language: hide
core/ui/Buttons/tag-manager: hide
core/ui/Buttons/light-dark: hide
core/ui/Buttons/manager: hide
core/ui/Buttons/more-page-actions: hide
core/ui/Buttons/new-journal: hide
Expand Down
2 changes: 1 addition & 1 deletion core/wiki/macros/CSS.tid
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ title: $:/core/macros/CSS
tags: $:/tags/Macro

\define colour(name)
<$transclude tiddler={{$:/palette}} index="$name$"><$transclude tiddler="$:/palettes/Vanilla" index="$name$"><$transclude tiddler="$:/config/DefaultColourMappings/$name$"/></$transclude></$transclude>
<$transclude tiddler={{{ [{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]then{$:/paletteDark}] ~[{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]then{$:/paletteDark}] ~[{$:/palette}] }}} index="$name$"><$transclude tiddler="$:/palettes/Vanilla" index="$name$"><$transclude tiddler="$:/config/DefaultColourMappings/$name$"/></$transclude></$transclude>
\end

\define color(name)
Expand Down
2 changes: 1 addition & 1 deletion core/wiki/macros/tag.tid
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $actions$<$transclude tiddler="""$icon$"""/><$view tiddler=<<__tag__>> field="ti

\define tag-pill(tag,element-tag:"span",element-attributes:"",actions:"")
<span class="tc-tag-list-item">
<$macrocall $name="tag-pill-body" tag=<<__tag__>> icon={{{ [<__tag__>get[icon]] }}} colour={{{ [<__tag__>get[color]] }}} palette={{$:/palette}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
<$macrocall $name="tag-pill-body" tag=<<__tag__>> icon={{{ [<__tag__>get[icon]] }}} colour={{{ [<__tag__>get[color]] }}} palette={{{ [{$:/config/AutoDarkMode}!match[yes]then{$:/config/DarkModeSetting}match[yes]then{$:/paletteDark}] ~[{$:/config/AutoDarkMode}match[yes]then{$:/info/darkmode}match[yes]then{$:/paletteDark}] ~[{$:/palette}] }}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
</span>
\end

Expand Down
3 changes: 3 additions & 0 deletions core/wiki/paletteDark.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: $:/paletteDark

$:/palettes/CupertinoDark
6 changes: 4 additions & 2 deletions core/wiki/paletteswitcher.tid
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
title: $:/snippets/paletteswitcher

<$linkcatcher to="$:/palette">
<div class="tc-chooser"><$list filter="[all[shadows+tiddlers]tag[$:/tags/Palette]sort[name]]"><$set name="cls" filter="[all[current]prefix{$:/palette}]" value="tc-chooser-item tc-chosen" emptyValue="tc-chooser-item"><div class=<<cls>>><$link to={{!!title}}>''<$view field="name" format="text"/>'' - <$view field="description" format="text"/>{{||$:/snippets/currpalettepreview}}</$link>
<$linkcatcher to=<<currPaletteTiddler>>>
<$set name="currPalette" value={{{ [<currPaletteTiddler>get[text]] }}}>
<div class="tc-chooser"><$list filter="[all[shadows+tiddlers]tag[$:/tags/Palette]sort[name]]"><$set name="cls" filter="[all[current]prefix<currPalette>]" value="tc-chooser-item tc-chosen" emptyValue="tc-chooser-item"><div class=<<cls>>><$link to={{!!title}}>''<$view field="name" format="text"/>'' - <$view field="description" format="text"/>{{||$:/snippets/currpalettepreview}}</$link>
</div></$set>
</$list>
</div>
</$set>
</$linkcatcher>