Update content of files

This commit is contained in:
GitHub Action 2024-11-17 13:48:48 +00:00
parent 75110f7544
commit 839b58b66d
3 changed files with 54 additions and 19 deletions

View file

@ -291,6 +291,9 @@
var webAppIsActive = true; var webAppIsActive = true;
var webAppIsFullscreen = false; var webAppIsFullscreen = false;
var webAppIsOrientationLocked = false; var webAppIsOrientationLocked = false;
var webAppBackgroundColor = 'bg_color';
var webAppHeaderColorKey = 'bg_color';
var webAppHeaderColor = null;
if (initParams.tgWebAppData && initParams.tgWebAppData.length) { if (initParams.tgWebAppData && initParams.tgWebAppData.length) {
webAppInitData = initParams.tgWebAppData; webAppInitData = initParams.tgWebAppData;
@ -318,6 +321,19 @@
if (stored_theme_params) { if (stored_theme_params) {
setThemeParams(stored_theme_params); setThemeParams(stored_theme_params);
} }
var stored_def_colors = Utils.sessionStorageGet('defaultColors');
if (initParams.tgWebAppDefaultColors && initParams.tgWebAppDefaultColors.length) {
var defColorsRaw = initParams.tgWebAppDefaultColors;
try {
var def_colors = JSON.parse(defColorsRaw);
if (def_colors) {
setDefaultColors(def_colors);
}
} catch (e) {}
}
if (stored_def_colors) {
setDefaultColors(stored_def_colors);
}
if (initParams.tgWebAppVersion) { if (initParams.tgWebAppVersion) {
webAppVersion = initParams.tgWebAppVersion; webAppVersion = initParams.tgWebAppVersion;
} }
@ -461,6 +477,27 @@
Utils.sessionStorageSet('themeParams', themeParams); Utils.sessionStorageSet('themeParams', themeParams);
} }
function setDefaultColors(def_colors) {
if (colorScheme == 'dark') {
if (def_colors.bg_dark_color) {
webAppBackgroundColor = def_colors.bg_dark_color;
}
if (def_colors.header_dark_color) {
webAppHeaderColorKey = null;
webAppHeaderColor = def_colors.header_dark_color;
}
} else {
if (def_colors.bg_color) {
webAppBackgroundColor = def_colors.bg_color;
}
if (def_colors.header_color) {
webAppHeaderColorKey = null;
webAppHeaderColor = def_colors.header_color;
}
}
Utils.sessionStorageSet('defaultColors', def_colors);
}
var webAppCallbacks = {}; var webAppCallbacks = {};
function generateCallbackId(len) { function generateCallbackId(len) {
var tries = 100; var tries = 100;
@ -690,14 +727,13 @@
} }
var headerColorKey = 'bg_color', headerColor = null;
function getHeaderColor() { function getHeaderColor() {
if (headerColorKey == 'secondary_bg_color') { if (webAppHeaderColorKey == 'secondary_bg_color') {
return themeParams.secondary_bg_color; return themeParams.secondary_bg_color;
} else if (headerColorKey == 'bg_color') { } else if (webAppHeaderColorKey == 'bg_color') {
return themeParams.bg_color; return themeParams.bg_color;
} }
return headerColor; return webAppHeaderColor;
} }
function setHeaderColor(color) { function setHeaderColor(color) {
if (!versionAtLeast('6.1')) { if (!versionAtLeast('6.1')) {
@ -729,32 +765,31 @@
console.error('[Telegram.WebApp] Header color key should be one of Telegram.WebApp.themeParams.bg_color, Telegram.WebApp.themeParams.secondary_bg_color, \'bg_color\', \'secondary_bg_color\'', color); console.error('[Telegram.WebApp] Header color key should be one of Telegram.WebApp.themeParams.bg_color, Telegram.WebApp.themeParams.secondary_bg_color, \'bg_color\', \'secondary_bg_color\'', color);
throw Error('WebAppHeaderColorKeyInvalid'); throw Error('WebAppHeaderColorKeyInvalid');
} }
headerColorKey = color_key; webAppHeaderColorKey = color_key;
headerColor = head_color; webAppHeaderColor = head_color;
updateHeaderColor(); updateHeaderColor();
} }
var appHeaderColorKey = null, appHeaderColor = null; var appHeaderColorKey = null, appHeaderColor = null;
function updateHeaderColor() { function updateHeaderColor() {
if (appHeaderColorKey != headerColorKey || if (appHeaderColorKey != webAppHeaderColorKey ||
appHeaderColor != headerColor) { appHeaderColor != webAppHeaderColor) {
appHeaderColorKey = headerColorKey; appHeaderColorKey = webAppHeaderColorKey;
appHeaderColor = headerColor; appHeaderColor = webAppHeaderColor;
if (appHeaderColor) { if (appHeaderColor) {
WebView.postEvent('web_app_set_header_color', false, {color: headerColor}); WebView.postEvent('web_app_set_header_color', false, {color: webAppHeaderColor});
} else { } else {
WebView.postEvent('web_app_set_header_color', false, {color_key: headerColorKey}); WebView.postEvent('web_app_set_header_color', false, {color_key: webAppHeaderColorKey});
} }
} }
} }
var backgroundColor = 'bg_color';
function getBackgroundColor() { function getBackgroundColor() {
if (backgroundColor == 'secondary_bg_color') { if (webAppBackgroundColor == 'secondary_bg_color') {
return themeParams.secondary_bg_color; return themeParams.secondary_bg_color;
} else if (backgroundColor == 'bg_color') { } else if (webAppBackgroundColor == 'bg_color') {
return themeParams.bg_color; return themeParams.bg_color;
} }
return backgroundColor; return webAppBackgroundColor;
} }
function setBackgroundColor(color) { function setBackgroundColor(color) {
if (!versionAtLeast('6.1')) { if (!versionAtLeast('6.1')) {
@ -771,7 +806,7 @@
throw Error('WebAppBackgroundColorInvalid'); throw Error('WebAppBackgroundColorInvalid');
} }
} }
backgroundColor = bg_color; webAppBackgroundColor = bg_color;
updateBackgroundColor(); updateBackgroundColor();
} }
var appBackgroundColor = null; var appBackgroundColor = null;

View file

@ -9,7 +9,7 @@
<meta name="MobileOptimized" content="176" /> <meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" /> <meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex, nofollow" /> <meta name="robots" content="noindex, nofollow" />
<script src="https://tg.dev/js/telegram-web-app-beta.js?79"></script> <script src="https://tg.dev/js/telegram-web-app-beta.js?80"></script>
<script> <script>
function setThemeClass() { function setThemeClass() {
document.documentElement.className = Telegram.WebApp.colorScheme; document.documentElement.className = Telegram.WebApp.colorScheme;

View file

@ -8,7 +8,7 @@
<meta name="MobileOptimized" content="176" /> <meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" /> <meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex,nofollow" /> <meta name="robots" content="noindex,nofollow" />
<script src="https://tg.dev/js/telegram-web-app-beta.js?79"></script> <script src="https://tg.dev/js/telegram-web-app-beta.js?80"></script>
<script> <script>
function setThemeClass() { function setThemeClass() {
document.documentElement.className = Telegram.WebApp.colorScheme; document.documentElement.className = Telegram.WebApp.colorScheme;