add dynamic theme

This commit is contained in:
marlon-erler
2026-09-17 20:03:55 +02:00
parent 839e887d85
commit 37d9016b83
13 changed files with 296 additions and 118 deletions
+12 -16
View File
@@ -172,14 +172,12 @@ body[theme=dark] [color]:not([color=standard]).subtle-background {
} }
#background-wrapper { #background-wrapper {
position: fixed; position: fixed;
top: 0px; inset: -80px;
left: var(--safe-area-left);
right: var(--safe-area-right);
bottom: 0px;
z-index: 1; z-index: 1;
pointer-events: none; pointer-events: none;
overflow: hidden; overflow: hidden;
opacity: 0.4; opacity: 0.4;
filter: blur(40px);
} }
main { main {
z-index: 2; z-index: 2;
@@ -187,24 +185,20 @@ main {
#background-wrapper div { #background-wrapper div {
content: ""; content: "";
position: absolute; position: absolute;
top: -80px; inset: 0px;
left: -80px;
right: -80px;
bottom: -80px;
z-index: -1; z-index: -1;
pointer-events: none; pointer-events: none;
filter: blur(40px);
} }
#background-wrapper #sky { #background-wrapper #sky {
left: -100%; left: -100%;
bottom: -50%; bottom: -50%;
--color-1: hsl(188, 100%, 83%); background-image: radial-gradient(var(--sky-1), var(--sky-2));
--color-2: hsl(194, 72%, 56%);
background-image: radial-gradient(var(--color-1), var(--color-2));
} }
#background-wrapper #grass-1 { #background-wrapper #grass-1 {
--color-1: hsl(150, 100%, 30%); --color-1: hsl(150, 60%, 30%);
--color-2: hsl(150, 100%, 25%); --color-2: hsl(150, 60%, 25%);
filter: var(--backdrop-grass-filter);
opacity: .7;
background-image: background-image:
linear-gradient( linear-gradient(
350deg, 350deg,
@@ -213,8 +207,10 @@ main {
transparent 40%); transparent 40%);
} }
#background-wrapper #grass-2 { #background-wrapper #grass-2 {
--color-1: hsl(110, 100%, 40%); --color-1: hsl(110, 60%, 40%);
--color-2: hsl(110, 100%, 35%); --color-2: hsl(110, 60%, 35%);
filter: var(--backdrop-grass-filter);
opacity: .7;
background-image: background-image:
linear-gradient( linear-gradient(
9deg, 9deg,
+86 -2
View File
@@ -353,6 +353,7 @@
info: "About Comms" info: "About Comms"
}, },
themes: { themes: {
dynamic: "Dynamic",
dark: "Dark", dark: "Dark",
light: "Light", light: "Light",
system: "Device theme" system: "Device theme"
@@ -586,6 +587,7 @@
info: "\xDCber Comms" info: "\xDCber Comms"
}, },
themes: { themes: {
dynamic: "Dynamisch",
dark: "Dunkel", dark: "Dunkel",
light: "Hell", light: "Hell",
system: "Ger\xE4teeinstellung" system: "Ger\xE4teeinstellung"
@@ -801,6 +803,7 @@
info: "Sobre Comms" info: "Sobre Comms"
}, },
themes: { themes: {
dynamic: "Din\xE1mico",
dark: "Oscuro", dark: "Oscuro",
light: "Claro", light: "Claro",
system: "Seg\xFAn dispositivo" system: "Seg\xFAn dispositivo"
@@ -1257,7 +1260,7 @@
this.connectionModel = connectionModel2; this.connectionModel = connectionModel2;
this.chatListModel = chatListModel2; this.chatListModel = chatListModel2;
this.fileTransferModel = fileTransferModel2; this.fileTransferModel = fileTransferModel2;
this.BUILD = "Build 26.09.09.A"; this.BUILD = "Build 26.09.17.A";
// CONTEXT // CONTEXT
this.contextStack = /* @__PURE__ */ new Map(); this.contextStack = /* @__PURE__ */ new Map();
this.closeContext = (contextId, fromHistoryEvent = false) => { this.closeContext = (contextId, fromHistoryEvent = false) => {
@@ -1800,10 +1803,42 @@
// view // view
this.applyTheme = () => { this.applyTheme = () => {
let theme = this.theme.value; let theme = this.theme.value;
if (theme == "dynamic" /* Dynamic */) {
const scene = this.selectDynamicScene();
this.setScene(scene);
return;
}
if (theme == "system" /* System */) { if (theme == "system" /* System */) {
theme = _SettingsViewModel.getSystemTheme(); theme = _SettingsViewModel.getSystemTheme();
} }
document.body.setAttribute("theme", theme); if (theme == "dark" /* Dark */) {
this.setScene(DynamicSceneNight);
} else {
this.setScene(DynamicSceneDay);
}
};
this.selectDynamicScene = () => {
let hour = (/* @__PURE__ */ new Date()).getHours();
if (hour >= 21 || hour <= 6) {
return DynamicSceneNight;
} else if (hour > 6 && hour < 10) {
return DynamicSceneSunrise;
} else if (hour < 14) {
return DynamicSceneDay;
} else if (hour < 17) {
return DynamicSceneAfternoon;
} else if (hour < 21) {
return DynamicSceneSunset;
}
};
this.setScene = (scene) => {
document.body.style.setProperty("--backdrop-grass-filter", `brightness(${scene.brightness})`);
function setSkyColor(tone, hue, saturation, luma) {
document.body.style.setProperty(`--sky-${tone}`, `hsl(${hue}, ${saturation}%, ${luma}%)`);
}
setSkyColor(1, scene.hue1, scene.saturation, scene.luma);
setSkyColor(2, scene.hue2, scene.saturation - 10, scene.luma - 10);
document.body.setAttribute("theme", scene.baseTheme);
}; };
// exit // exit
this.close = () => { this.close = () => {
@@ -1835,6 +1870,11 @@
"change", "change",
() => this.applyTheme() () => this.applyTheme()
); );
const seconds = (/* @__PURE__ */ new Date()).getSeconds();
const secondsUntilNewMinute = 60 - seconds;
setTimeout(() => {
setInterval(this.applyTheme, 1e3 * 60);
}, secondsUntilNewMinute);
this.registerKeyStroke("backspace" /* CloseOrCancel */, this.close); this.registerKeyStroke("backspace" /* CloseOrCancel */, this.close);
} }
static generateThemeMedia() { static generateThemeMedia() {
@@ -1845,6 +1885,46 @@
return media.matches == true ? "dark" /* Dark */ : "light" /* Light */; return media.matches == true ? "dark" /* Dark */ : "light" /* Light */;
} }
}; };
var DynamicSceneNight = {
hue1: 215,
hue2: 220,
saturation: 50,
luma: 25,
brightness: 0.4,
baseTheme: "dark" /* Dark */
};
var DynamicSceneSunrise = {
hue1: 45,
hue2: 190,
saturation: 100,
luma: 50,
brightness: 1.2,
baseTheme: "light" /* Light */
};
var DynamicSceneDay = {
hue1: 190,
hue2: 180,
saturation: 100,
luma: 70,
brightness: 1.4,
baseTheme: "light" /* Light */
};
var DynamicSceneAfternoon = {
hue1: 195,
hue2: 220,
saturation: 100,
luma: 50,
brightness: 0.8,
baseTheme: "light" /* Light */
};
var DynamicSceneSunset = {
hue1: 20,
hue2: 260,
saturation: 100,
luma: 50,
brightness: 0.4,
baseTheme: "dark" /* Dark */
};
// src/ViewModel/Global/fileTransferViewModel.ts // src/ViewModel/Global/fileTransferViewModel.ts
var FileTransferViewModel = class extends Context { var FileTransferViewModel = class extends Context {
@@ -6867,6 +6947,10 @@
function SettingsAppearancePane(coreViewModel2, settingsViewModel2) { function SettingsAppearancePane(coreViewModel2, settingsViewModel2) {
return /* @__PURE__ */ createElement("div", { class: "slide-up" }, /* @__PURE__ */ createElement("h2", null, coreViewModel2.translations.settings.pages.appearance), /* @__PURE__ */ createElement("hr", null), OptionButtonList( return /* @__PURE__ */ createElement("div", { class: "slide-up" }, /* @__PURE__ */ createElement("h2", null, coreViewModel2.translations.settings.pages.appearance), /* @__PURE__ */ createElement("hr", null), OptionButtonList(
new ListState([ new ListState([
[
coreViewModel2.translations.settings.themes.dynamic,
"dynamic" /* Dynamic */
],
[ [
coreViewModel2.translations.settings.themes.dark, coreViewModel2.translations.settings.themes.dark,
"dark" /* Dark */ "dark" /* Dark */
Binary file not shown.
+1
View File
@@ -106,4 +106,5 @@ export enum ThemeSettings {
Dark = "dark", Dark = "dark",
Light = "light", Light = "light",
System = "system", System = "system",
Dynamic = "dynamic",
} }
Binary file not shown.
+4
View File
@@ -170,6 +170,10 @@ function SettingsAppearancePane(
<hr></hr> <hr></hr>
{OptionButtonList( {OptionButtonList(
new React.ListState<[string, string]>([ new React.ListState<[string, string]>([
[
coreViewModel.translations.settings.themes.dynamic,
ThemeSettings.Dynamic,
],
[ [
coreViewModel.translations.settings.themes.dark, coreViewModel.translations.settings.themes.dark,
ThemeSettings.Dark, ThemeSettings.Dark,
+3
View File
@@ -83,6 +83,7 @@ const englishTranslations = {
info: "About Comms", info: "About Comms",
}, },
themes: { themes: {
dynamic: "Dynamic",
dark: "Dark", dark: "Dark",
light: "Light", light: "Light",
system: "Device theme", system: "Device theme",
@@ -410,6 +411,7 @@ export const allTranslations: {
info: "Über Comms", info: "Über Comms",
}, },
themes: { themes: {
dynamic: "Dynamisch",
dark: "Dunkel", dark: "Dunkel",
light: "Hell", light: "Hell",
system: "Geräteeinstellung", system: "Geräteeinstellung",
@@ -705,6 +707,7 @@ export const allTranslations: {
info: "Sobre Comms", info: "Sobre Comms",
}, },
themes: { themes: {
dynamic: "Dinámico",
dark: "Oscuro", dark: "Oscuro",
light: "Claro", light: "Claro",
system: "Según dispositivo", system: "Según dispositivo",
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -9,7 +9,7 @@ import ConnectionModel from "../../Model/Global/connectionModel";
import ChatListModel from "../../Model/Chat/chatListModel"; import ChatListModel from "../../Model/Chat/chatListModel";
export default class CoreViewModel { export default class CoreViewModel {
readonly BUILD = "Build 26.09.09.A"; readonly BUILD = "Build 26.09.17.A";
translations: Translations; translations: Translations;
+95 -1
View File
@@ -54,12 +54,52 @@ export default class SettingsViewModel extends Context {
// view // view
applyTheme = (): void => { applyTheme = (): void => {
let theme: string = this.theme.value; let theme: string = this.theme.value;
if (theme == ThemeSettings.Dynamic) {
const scene = this.selectDynamicScene();
this.setScene(scene);
return;
}
if (theme == ThemeSettings.System) { if (theme == ThemeSettings.System) {
theme = SettingsViewModel.getSystemTheme(); theme = SettingsViewModel.getSystemTheme();
} }
document.body.setAttribute("theme", theme);
if (theme == ThemeSettings.Dark) {
this.setScene(DynamicSceneNight);
} else {
this.setScene(DynamicSceneDay);
}
}; };
selectDynamicScene = (): DynamicScene => {
let hour = new Date().getHours();
if (hour >= 21 || hour <= 6) {
return DynamicSceneNight;
} else if (hour > 6 && hour < 10) {
return DynamicSceneSunrise;
} else if (hour < 14) {
return DynamicSceneDay;
} else if (hour < 17) {
return DynamicSceneAfternoon
} else if (hour < 21) {
return DynamicSceneSunset
}
}
setScene = (scene: DynamicScene): void => {
document.body.style.setProperty("--backdrop-grass-filter", `brightness(${scene.brightness})`);
function setSkyColor(tone: 1|2, hue: number, saturation: number, luma: number) {
document.body.style.setProperty(`--sky-${tone}`, `hsl(${hue}, ${saturation}%, ${luma}%)`);
}
setSkyColor(1, scene.hue1, scene.saturation, scene.luma);
setSkyColor(2, scene.hue2, scene.saturation - 10, scene.luma-10);
document.body.setAttribute("theme", scene.baseTheme);
}
// exit // exit
close = (): void => { close = (): void => {
this.coreViewModel.closeContext(this.contextId); this.coreViewModel.closeContext(this.contextId);
@@ -99,6 +139,11 @@ export default class SettingsViewModel extends Context {
SettingsViewModel.generateThemeMedia().addEventListener("change", () => SettingsViewModel.generateThemeMedia().addEventListener("change", () =>
this.applyTheme(), this.applyTheme(),
); );
const seconds = new Date().getSeconds();
const secondsUntilNewMinute = 60-seconds;
setTimeout(() => {
setInterval(this.applyTheme, 1000*60);
}, secondsUntilNewMinute);
// keystrokes // keystrokes
this.registerKeyStroke(CommonKeys.CloseOrCancel, this.close); this.registerKeyStroke(CommonKeys.CloseOrCancel, this.close);
@@ -119,3 +164,52 @@ export enum SettingsModalPages {
Regional, Regional,
Info, Info,
} }
export interface DynamicScene {
hue1: number;
hue2: number;
saturation: number;
luma: number;
brightness: number;
baseTheme: ThemeSettings;
}
export const DynamicSceneNight: DynamicScene = {
hue1: 215,
hue2: 220,
saturation : 50,
luma: 25,
brightness: 0.4,
baseTheme: ThemeSettings.Dark,
}
export const DynamicSceneSunrise: DynamicScene = {
hue1: 45,
hue2: 190,
saturation : 100,
luma: 50,
brightness: 1.2,
baseTheme: ThemeSettings.Light,
}
export const DynamicSceneDay: DynamicScene = {
hue1: 190,
hue2: 180,
saturation : 100,
luma: 70,
brightness: 1.4,
baseTheme: ThemeSettings.Light,
}
export const DynamicSceneAfternoon: DynamicScene = {
hue1: 195,
hue2: 220,
saturation : 100,
luma: 50,
brightness: 0.8,
baseTheme: ThemeSettings.Light,
}
export const DynamicSceneSunset: DynamicScene = {
hue1: 20,
hue2: 260,
saturation : 100,
luma: 50,
brightness: 0.4,
baseTheme: ThemeSettings.Dark,
}
+14 -18
View File
@@ -7,14 +7,10 @@
} }
/* Gradient */ /* Gradient */
#background-wrapper { #background-wrapper {
position: fixed; position: fixed;
top: 0px; inset: -80px;
left: var(--safe-area-left);
right: var(--safe-area-right);
bottom: 0px;
z-index: 1; z-index: 1;
pointer-events: none; pointer-events: none;
@@ -22,6 +18,7 @@
overflow: hidden; overflow: hidden;
opacity: 0.4; opacity: 0.4;
filter: blur(40px);
} }
main { main {
@@ -32,29 +29,25 @@ main {
content: ""; content: "";
position: absolute; position: absolute;
top: -80px; inset: 0px;
left: -80px;
right: -80px;
bottom: -80px;
z-index: -1; z-index: -1;
pointer-events: none; pointer-events: none;
filter: blur(40px);
} }
#background-wrapper #sky { #background-wrapper #sky {
left: -100%; left: -100%;
bottom: -50%; bottom: -50%;
--color-1: hsl(188, 100%, 83%); background-image: radial-gradient(var(--sky-1), var(--sky-2));
--color-2: hsl(194, 72%, 56%);
background-image: radial-gradient(var(--color-1), var(--color-2));
} }
#background-wrapper #grass-1 { #background-wrapper #grass-1 {
--color-1: hsl(150, 100%, 30%); --color-1: hsl(150, 60%, 30%);
--color-2: hsl(150, 100%, 25%); --color-2: hsl(150, 60%, 25%);
filter: var(--backdrop-grass-filter);
opacity: .7;
background-image: linear-gradient( background-image: linear-gradient(
350deg, 350deg,
@@ -65,8 +58,11 @@ main {
} }
#background-wrapper #grass-2 { #background-wrapper #grass-2 {
--color-1: hsl(110, 100%, 40%); --color-1: hsl(110, 60%, 40%);
--color-2: hsl(110, 100%, 35%); --color-2: hsl(110, 60%, 35%);
filter: var(--backdrop-grass-filter);
opacity: .7;
background-image: linear-gradient( background-image: linear-gradient(
9deg, 9deg,