Improved boot.js with existing global window.rl

Put dev/Storage/Settings.js in boots.js global rl.settings
This commit is contained in:
djmaze 2020-09-04 12:05:17 +02:00
parent f90dbcc84b
commit aeb5275648
57 changed files with 284 additions and 380 deletions

View file

@ -8,9 +8,8 @@ import {
} from 'Common/Globals';
import { KeyState } from 'Common/Enums';
import { root, rootAdmin, rootUser, populateAuthSuffix } from 'Common/Links';
import { root, rootAdmin, rootUser } from 'Common/Links';
import { initOnStartOrLangChange, initNotificationLanguage } from 'Common/Translator';
import * as Settings from 'Storage/Settings';
import LanguageStore from 'Stores/Language';
import ThemeStore from 'Stores/Theme';
@ -18,6 +17,8 @@ import ThemeStore from 'Stores/Theme';
import { routeOff, setHash } from 'Knoin/Knoin';
import { AbstractBoot } from 'Knoin/AbstractBoot';
const Settings = rl.settings;
class AbstractApp extends AbstractBoot {
/**
* @param {RemoteStorage|AdminRemoteStorage} Remote
@ -57,10 +58,6 @@ class AbstractApp extends AbstractBoot {
return null;
}
getApplicationConfiguration(name, default_) {
return this.applicationConfiguration[name] || default_;
}
/**
* @param {string} link
* @returns {boolean}
@ -79,40 +76,16 @@ class AbstractApp extends AbstractBoot {
return true;
}
/**
* @param {string} title
*/
setWindowTitle(title) {
title = null == title ? '' : '' + title;
if (Settings.settingsGet('Title')) {
title += (title ? ' - ' : '') + Settings.settingsGet('Title');
}
document.title = title;
}
redirectToAdminPanel() {
setTimeout(() => {
location.href = rootAdmin();
}, 100);
}
clearClientSideToken() {
if (RainLoop.hash.clear) {
RainLoop.hash.clear();
}
setTimeout(() => location.href = rootAdmin(), 100);
}
/**
* @param {string} token
*/
setClientSideToken(token) {
if (RainLoop.hash.set) {
RainLoop.hash.set(token);
Settings.settingsSet('AuthAccountHash', token);
populateAuthSuffix();
}
rl.hash.set();
Settings.set('AuthAccountHash', token);
}
/**
@ -121,11 +94,11 @@ class AbstractApp extends AbstractBoot {
* @param {boolean=} close = false
*/
loginAndLogoutReload(admin = false, logout = false, close = false) {
const inIframe = !!Settings.appSettingsGet('inIframe'),
const inIframe = !!Settings.app('inIframe'),
logoutLink = admin ? rootAdmin() : rootUser();
if (logout) {
this.clearClientSideToken();
rl.hash.clear();
}
if (logout && close && window.close) {
@ -155,19 +128,15 @@ class AbstractApp extends AbstractBoot {
}
}
historyBack() {
history.back();
}
bootstart() {
const mobile = Settings.appSettingsGet('mobile');
const mobile = Settings.app('mobile');
ko.components.register('SaveTrigger', require('Component/SaveTrigger').default);
ko.components.register('Input', require('Component/Input').default);
ko.components.register('Select', require('Component/Select').default);
ko.components.register('TextArea', require('Component/TextArea').default);
if (Settings.appSettingsGet('materialDesign') && !bMobileDevice) {
if (Settings.app('materialDesign') && !bMobileDevice) {
ko.components.register('Checkbox', require('Component/MaterialDesign/Checkbox').default);
ko.components.register('CheckboxSimple', require('Component/Checkbox').default);
} else {

View file

@ -3,8 +3,6 @@ import ko from 'ko';
import { root } from 'Common/Links';
import { StorageResultType } from 'Common/Enums';
import * as Settings from 'Storage/Settings';
import AppStore from 'Stores/Admin/App';
import CapaStore from 'Stores/Admin/Capa';
import DomainStore from 'Stores/Admin/Domain';
@ -113,7 +111,7 @@ class AdminApp extends AbstractApp {
hideLoading();
if (!Settings.appSettingsGet('allowAdminPanel')) {
if (!rl.settings.app('allowAdminPanel')) {
routeOff();
setHash(root(), true);
routeOff();
@ -122,7 +120,7 @@ class AdminApp extends AbstractApp {
location.href = '/'
, 1);
} else {
if (Settings.settingsGet('Auth')) {
if (rl.settings.get('Auth')) {
startScreens([SettingsAdminScreen]);
} else {
startScreens([LoginAdminScreen]);

View file

@ -56,7 +56,6 @@ import MessageStore from 'Stores/User/Message';
import QuotaStore from 'Stores/User/Quota';
import * as Local from 'Storage/Client';
import * as Settings from 'Storage/Settings';
import Remote from 'Remote/User/Ajax';
import Promises from 'Promises/User/Ajax';
@ -75,7 +74,7 @@ import { hideLoading, routeOff, routeOn, setHash, startScreens, showScreenPopup
import { AbstractApp } from 'App/Abstract';
const doc = document;
const doc = document, Settings = rl.settings;
class AppUser extends AbstractApp {
constructor() {
@ -94,25 +93,25 @@ class AppUser extends AbstractApp {
setInterval(() => {
const currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) {
if (RainLoop.hash.check()) {
if (rl.hash.check()) {
this.reload();
}
Remote.jsVersion((sResult, oData) => {
if (StorageResultType.Success === sResult && oData && !oData.Result) {
this.reload();
}
}, Settings.appSettingsGet('version'));
}, Settings.app('version'));
}
lastTime = currentTime;
}, interval);
if (RainLoop.hash.check()) {
if (rl.hash.check()) {
this.reload();
}
if (Settings.settingsGet('UserBackgroundHash')) {
if (Settings.get('UserBackgroundHash')) {
setTimeout(() => {
const img = userBackground(Settings.settingsGet('UserBackgroundHash'));
const img = userBackground(Settings.get('UserBackgroundHash'));
if (img) {
$htmlCL.add('UserBackground');
doc.body.style.backgroundImage = "url("+img+")";
@ -126,7 +125,7 @@ class AppUser extends AbstractApp {
}
reload() {
if (parent && !!Settings.appSettingsGet('inIframe')) {
if (parent && !!Settings.app('inIframe')) {
parent.location.reload();
} else {
location.reload();
@ -489,7 +488,7 @@ class AppUser extends AbstractApp {
if (StorageResultType.Success === sResult && oData.Result) {
const counts = {},
sAccountEmail = AccountStore.email();
let parentEmail = Settings.settingsGet('ParentEmail') || sAccountEmail;
let parentEmail = Settings.get('ParentEmail') || sAccountEmail;
if (Array.isArray(oData.Result.Accounts)) {
AccountStore.accounts().forEach(oAccount => {
@ -901,7 +900,7 @@ class AppUser extends AbstractApp {
this.loginAndLogoutReload(
false,
true,
0 < (Settings.settingsGet('ParentEmail')||{length:0}).length
0 < (Settings.get('ParentEmail')||{length:0}).length
);
});
}
@ -932,27 +931,27 @@ class AppUser extends AbstractApp {
AccountStore.populate();
ContactStore.populate();
let contactsSyncInterval = pInt(Settings.settingsGet('ContactsSyncInterval'));
let contactsSyncInterval = pInt(Settings.get('ContactsSyncInterval'));
const startupUrl = pString(Settings.settingsGet('StartupUrl'));
const startupUrl = pString(Settings.get('StartupUrl'));
if (window.progressJs) {
progressJs.set(90);
}
this.setWindowTitle('');
if (Settings.settingsGet('Auth')) {
rl.setWindowTitle();
if (Settings.get('Auth')) {
$htmlCL.add('rl-user-auth');
if (
Settings.capa(Capa.TwoFactor) &&
Settings.capa(Capa.TwoFactorForce) &&
Settings.settingsGet('RequireTwoFactor')
Settings.get('RequireTwoFactor')
) {
this.bootend();
this.bootstartTwoFactorScreen();
} else {
this.setWindowTitle(i18n('TITLES/LOADING'));
rl.setWindowTitle(i18n('TITLES/LOADING'));
// require.ensure([], function() { // require code splitting
@ -1041,7 +1040,7 @@ class AppUser extends AbstractApp {
addEventListener('rl.auto-logout', () => this.logout());
if (
!!Settings.settingsGet('AccountSignMe') &&
!!Settings.get('AccountSignMe') &&
navigator.registerProtocolHandler &&
Settings.capa(Capa.Composer)
) {
@ -1050,12 +1049,12 @@ class AppUser extends AbstractApp {
navigator.registerProtocolHandler(
'mailto',
location.protocol + '//' + location.host + location.pathname + '?mailto&to=%s',
'' + (Settings.settingsGet('Title') || 'RainLoop')
'' + (Settings.get('Title') || 'RainLoop')
);
} catch (e) {} // eslint-disable-line no-empty
if (Settings.settingsGet('MailToEmail')) {
mailToHelper(Settings.settingsGet('MailToEmail'), require('View/Popup/Compose'));
if (Settings.get('MailToEmail')) {
mailToHelper(Settings.get('MailToEmail'), require('View/Popup/Compose'));
}
}, 500);
}