mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-11 15:44:43 +08:00
Keep AUTH_SPEC_TOKEN_KEY
And now we can embed theme and language in index.html template
This commit is contained in:
parent
4579a786ab
commit
ce63ba506a
7 changed files with 30 additions and 49 deletions
|
@ -3,7 +3,7 @@ import { Notification, UploadErrorCode } from 'Common/Enums';
|
||||||
import { langLink } from 'Common/Links';
|
import { langLink } from 'Common/Links';
|
||||||
import { doc, createElement } from 'Common/Globals';
|
import { doc, createElement } from 'Common/Globals';
|
||||||
|
|
||||||
let I18N_DATA = window.snappymailI18N || {};
|
let I18N_DATA = {};
|
||||||
|
|
||||||
export const trigger = ko.observable(false);
|
export const trigger = ko.observable(false);
|
||||||
|
|
||||||
|
@ -49,10 +49,21 @@ const i18nToNode = element => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
init = () => {
|
||||||
|
if (rl.I18N) {
|
||||||
|
I18N_DATA = rl.I18N;
|
||||||
|
Date.defineRelativeTimeFormat(rl.relativeTime || {});
|
||||||
|
rl.I18N = null;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(),
|
i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(),
|
||||||
|
|
||||||
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
|
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} elements
|
* @param {Object} elements
|
||||||
* @param {boolean=} animate = false
|
* @param {boolean=} animate = false
|
||||||
|
@ -127,13 +138,11 @@ export function reload(admin, language) {
|
||||||
const script = createElement('script');
|
const script = createElement('script');
|
||||||
script.onload = () => {
|
script.onload = () => {
|
||||||
// reload the data
|
// reload the data
|
||||||
if (window.snappymailI18N) {
|
if (init()) {
|
||||||
I18N_DATA = window.snappymailI18N;
|
|
||||||
i18nToNodes(doc);
|
i18nToNodes(doc);
|
||||||
dispatchEvent(new CustomEvent('reload-time'));
|
dispatchEvent(new CustomEvent('reload-time'));
|
||||||
trigger(!trigger());
|
trigger(!trigger());
|
||||||
}
|
}
|
||||||
window.snappymailI18N = null;
|
|
||||||
script.remove();
|
script.remove();
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SaveSettingsStep } from 'Common/Enums';
|
import { SaveSettingsStep } from 'Common/Enums';
|
||||||
import { doc, createElement, elementById } from 'Common/Globals';
|
import { doc, elementById } from 'Common/Globals';
|
||||||
|
|
||||||
export const
|
export const
|
||||||
isArray = Array.isArray,
|
isArray = Array.isArray,
|
||||||
|
@ -84,14 +84,13 @@ let __themeTimer = 0,
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
export function changeTheme(value, themeTrigger = ()=>{}) {
|
export function changeTheme(value, themeTrigger = ()=>{}) {
|
||||||
const themeLink = elementById('app-theme-link'),
|
const themeStyle = elementById('app-theme-style'),
|
||||||
clearTimer = () => {
|
clearTimer = () => {
|
||||||
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
|
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
|
||||||
__themeJson = null;
|
__themeJson = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
let themeStyle = elementById('app-theme-style'),
|
let url = themeStyle.dataset.href;
|
||||||
url = (themeLink && themeLink.href) || (themeStyle && themeStyle.dataset.href);
|
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
url = url.toString()
|
url = url.toString()
|
||||||
|
@ -118,19 +117,9 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
|
||||||
rl.fetchJSON(url, init)
|
rl.fetchJSON(url, init)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data && isArray(data) && 2 === data.length) {
|
if (data && isArray(data) && 2 === data.length) {
|
||||||
if (themeLink && !themeStyle) {
|
themeStyle.textContent = data[1];
|
||||||
themeStyle = createElement('style');
|
themeStyle.dataset.href = url;
|
||||||
themeStyle.id = 'app-theme-style';
|
themeStyle.dataset.theme = data[0];
|
||||||
themeLink.after(themeStyle);
|
|
||||||
themeLink.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (themeStyle) {
|
|
||||||
themeStyle.textContent = data[1];
|
|
||||||
themeStyle.dataset.href = url;
|
|
||||||
themeStyle.dataset.theme = data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
themeTrigger(SaveSettingsStep.TrueResult);
|
themeTrigger(SaveSettingsStep.TrueResult);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -144,12 +144,7 @@ win.rl = {
|
||||||
rl.hash.set();
|
rl.hash.set();
|
||||||
|
|
||||||
if (appData) {
|
if (appData) {
|
||||||
if (appData.NewThemeLink) {
|
|
||||||
eId('app-theme-link').href = appData.NewThemeLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadScript(appData.StaticLibJsLink)
|
loadScript(appData.StaticLibJsLink)
|
||||||
.then(() => loadScript(appData.LangLink))
|
|
||||||
.then(() => loadScript(appData.StaticAppJsLink))
|
.then(() => loadScript(appData.StaticAppJsLink))
|
||||||
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
||||||
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
|
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
|
||||||
|
@ -170,7 +165,7 @@ Storage('local');
|
||||||
// init section
|
// init section
|
||||||
setInterval(setTimestamp, 60000); // 1m
|
setInterval(setTimestamp, 60000); // 1m
|
||||||
|
|
||||||
[eId('app-css'),eId('app-theme-link')].forEach(css => css.href = css.dataset.href);
|
eId('app-css').href = eId('app-css').dataset.href;
|
||||||
|
|
||||||
loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`)
|
loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`)
|
||||||
.then(() => {});
|
.then(() => {});
|
||||||
|
|
|
@ -508,12 +508,7 @@ class Actions
|
||||||
|
|
||||||
public function GetSpecAuthTokenWithDeletion(): string
|
public function GetSpecAuthTokenWithDeletion(): string
|
||||||
{
|
{
|
||||||
$sResult = Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, '');
|
return Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, '');
|
||||||
if (0 < strlen($sResult)) {
|
|
||||||
// TODO: Browser F5 issue
|
|
||||||
Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY);
|
|
||||||
}
|
|
||||||
return $sResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSpecAuthLogoutTokenWithDeletion(): string
|
public function GetSpecAuthLogoutTokenWithDeletion(): string
|
||||||
|
@ -1252,7 +1247,6 @@ class Actions
|
||||||
$sStaticCache = $this->StaticCache();
|
$sStaticCache = $this->StaticCache();
|
||||||
|
|
||||||
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
||||||
$aResult['NewThemeLink'] = $this->ThemeLink($bAdmin);
|
|
||||||
|
|
||||||
$aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false);
|
$aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false);
|
||||||
$aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
$aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
||||||
|
@ -1260,8 +1254,6 @@ class Actions
|
||||||
$aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
|
$aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
|
||||||
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
|
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
|
||||||
}
|
}
|
||||||
$aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' .
|
|
||||||
($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/';
|
|
||||||
|
|
||||||
$aResult['PluginsLink'] = '';
|
$aResult['PluginsLink'] = '';
|
||||||
if (0 < $this->Plugins()->Count() && $this->Plugins()->HaveJs($bAdmin)) {
|
if (0 < $this->Plugins()->Count() && $this->Plugins()->HaveJs($bAdmin)) {
|
||||||
|
|
|
@ -143,6 +143,6 @@ trait Localization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "document.documentElement.lang = '{$sLanguage}';\nwindow.snappymailI18N={$sResult};\nDate.defineRelativeTimeFormat({$sTimeFormat});";
|
return "document.documentElement.lang = '{$sLanguage}';\nrl.I18N={$sResult};\nrl.relativeTime = {$sTimeFormat};";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,26 +158,22 @@ class Service
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
|
$this->oServiceActions->getAuthAccountHash($bAdmin);
|
||||||
|
$sLanguage = $this->oActions->GetLanguage($bAdmin);
|
||||||
|
|
||||||
// TODO: Browser F5 issue
|
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
|
||||||
// $this->oServiceActions->getAuthAccountHash($bAdmin);
|
|
||||||
// $sLanguage = $this->oActions->GetLanguage($bAdmin);
|
|
||||||
|
|
||||||
$sCacheFileName = '';
|
$sCacheFileName = '';
|
||||||
if ($this->oActions->Config()->Get('labs', 'cache_system_data', true) && !empty($aTemplateParameters['{{BaseHash}}']))
|
if ($this->oActions->Config()->Get('labs', 'cache_system_data', true) && !empty($aTemplateParameters['{{BaseHash}}']))
|
||||||
{
|
{
|
||||||
// TODO: Browser F5 issue
|
$sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}'];
|
||||||
// $sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}'];
|
|
||||||
$sCacheFileName = 'TMPL:'.$aTemplateParameters['{{BaseHash}}'];
|
|
||||||
$sResult = $this->oActions->Cacher()->Get($sCacheFileName);
|
$sResult = $this->oActions->Cacher()->Get($sCacheFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === \strlen($sResult))
|
if (0 === \strlen($sResult))
|
||||||
{
|
{
|
||||||
// $aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oServiceActions->compileCss($this->oActions->GetTheme($bAdmin));
|
$aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oActions->compileCss($this->oActions->GetTheme($bAdmin), $bAdmin);
|
||||||
// TODO: Browser F5 issue
|
$aTemplateParameters['{{BaseLanguage}}'] = $this->oActions->compileLanguage($sLanguage, $bAdmin);
|
||||||
// $aTemplateParameters['{{BaseLanguage}}'] = $this->oServiceActions->compileLanguage($sLanguage, $bAdmin);
|
|
||||||
$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
|
$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
|
||||||
$sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters);
|
$sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters);
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<title></title>
|
<title></title>
|
||||||
<style id="app-boot-css">{{BaseAppBootCss}}</style>
|
<style id="app-boot-css">{{BaseAppBootCss}}</style>
|
||||||
<link type="text/css" rel="stylesheet" data-href="{{BaseAppMainCssLink}}" id="app-css" rel="preload">
|
<link type="text/css" rel="stylesheet" data-href="{{BaseAppMainCssLink}}" id="app-css" rel="preload">
|
||||||
<link type="text/css" rel="stylesheet" data-href="{{BaseAppThemeCssLink}}" id="app-theme-link" rel="preload">
|
|
||||||
<link rel="manifest" href="{{BaseAppManifestLink}}">
|
<link rel="manifest" href="{{BaseAppManifestLink}}">
|
||||||
|
<style id="app-theme-style" data-href="{{BaseAppThemeCssLink}}">{{BaseAppThemeCss}}</style>
|
||||||
<script>document.append||document.location.replace('./?/BadBrowser');</script>
|
<script>document.append||document.location.replace('./?/BadBrowser');</script>
|
||||||
{{BaseAppFaviconPngLinkTag}}
|
{{BaseAppFaviconPngLinkTag}}
|
||||||
{{BaseAppFaviconTouchLinkTag}}
|
{{BaseAppFaviconTouchLinkTag}}
|
||||||
|
@ -40,8 +40,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="progressjs"><div></div></div>
|
<div id="progressjs"><div></div></div>
|
||||||
<script type="text/javascript">{{BaseAppBootScript}}{{BaseLanguage}}</script>
|
|
||||||
{{BaseTemplates}}
|
{{BaseTemplates}}
|
||||||
|
<script type="text/javascript">{{BaseAppBootScript}}{{BaseLanguage}}</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue