Improve AppUser.bootstart

This commit is contained in:
djmaze 2021-09-23 14:24:06 +02:00
parent 3c8cdcbb07
commit 9158fcd0eb
6 changed files with 81 additions and 118 deletions

View file

@ -183,33 +183,6 @@ class AppUser extends AbstractApp {
Remote.messageList(null, {Folder: getFolderInboxName()}, true); Remote.messageList(null, {Folder: getFolderInboxName()}, true);
} }
/**
* @param {Function} fResultFunc
* @returns {boolean}
*/
contactsSync(fResultFunc) {
if (
ContactUserStore.importing() ||
ContactUserStore.syncing() ||
!ContactUserStore.enableSync() ||
!ContactUserStore.allowSync()
) {
return false;
}
ContactUserStore.syncing(true);
Remote.contactsSync((sResult, oData) => {
ContactUserStore.syncing(false);
if (fResultFunc) {
fResultFunc(sResult, oData);
}
});
return true;
}
messagesMoveTrigger() { messagesMoveTrigger() {
const sTrashFolder = FolderUserStore.trashFolder(), const sTrashFolder = FolderUserStore.trashFolder(),
sSpamFolder = FolderUserStore.spamFolder(); sSpamFolder = FolderUserStore.spamFolder();
@ -824,7 +797,7 @@ class AppUser extends AbstractApp {
} }
logout() { logout() {
Remote.logout(() => rl.logoutReload((SettingsGet('ParentEmail')||{length:0}).length)); Remote.logout(() => rl.logoutReload(!!SettingsGet('ParentEmail')));
} }
bootstart() { bootstart() {
@ -838,57 +811,20 @@ class AppUser extends AbstractApp {
} }
}, {capture: true}); }, {capture: true});
NotificationUserStore.populate();
AccountUserStore.populate();
ContactUserStore.populate();
let contactsSyncInterval = pInt(SettingsGet('ContactsSyncInterval'));
const startupUrl = pString(SettingsGet('StartupUrl'));
rl.setWindowTitle();
if (SettingsGet('Auth')) { if (SettingsGet('Auth')) {
rl.setWindowTitle(i18n('GLOBAL/LOADING')); rl.setWindowTitle(i18n('GLOBAL/LOADING'));
NotificationUserStore.enableSoundNotification(!!SettingsGet('SoundNotification'));
NotificationUserStore.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
AccountUserStore.email(SettingsGet('Email'));
AccountUserStore.parentEmail(SettingsGet('ParentEmail'));
this.foldersReload(value => { this.foldersReload(value => {
try { try {
if (value) { if (value) {
if (startupUrl) { value = pString(SettingsGet('StartupUrl'));
rl.route.setHash(root(startupUrl), true); value && rl.route.setHash(root(value), true);
}
if (window.crypto && crypto.getRandomValues && Settings.capa(Capa.OpenPGP)) {
const openpgpCallback = () => {
if (!window.openpgp) {
return false;
}
PgpUserStore.openpgp = openpgp;
if (window.Worker) {
try {
PgpUserStore.openpgp.initWorker({ path: openPgpWorkerJs() });
} catch (e) {
console.error(e);
}
}
PgpUserStore.openpgpKeyring = new openpgp.Keyring();
PgpUserStore.capaOpenPGP(true);
this.reloadOpenPgpKeys();
return true;
};
if (!openpgpCallback()) {
const script = createElement('script', {src:openPgpJs()});
script.onload = openpgpCallback;
script.onerror = () => console.error(script.src);
doc.head.append(script);
}
} else {
PgpUserStore.capaOpenPGP(false);
}
startScreens([ startScreens([
MailBoxUserScreen, MailBoxUserScreen,
@ -907,14 +843,9 @@ class AppUser extends AbstractApp {
}, refreshFolders); }, refreshFolders);
// Every 15 minutes // Every 15 minutes
setInterval(this.quota, 900000); setInterval(()=>this.quota() | this.foldersReload(), 900000);
// Every 20 minutes
setInterval(this.foldersReload, 1200000);
setTimeout(this.contactsSync, 10000); ContactUserStore.init();
contactsSyncInterval = 5 <= contactsSyncInterval ? contactsSyncInterval : 20;
contactsSyncInterval = 320 >= contactsSyncInterval ? contactsSyncInterval : 320;
setInterval(this.contactsSync, contactsSyncInterval * 60000 + 5000);
this.accountsAndIdentities(true); this.accountsAndIdentities(true);
@ -923,15 +854,15 @@ class AppUser extends AbstractApp {
if (getFolderInboxName() !== cF) { if (getFolderInboxName() !== cF) {
this.folderInformation(cF); this.folderInformation(cF);
} }
this.quota();
this.folderInformationMultiply(true); this.folderInformationMultiply(true);
}, 1000); }, 1000);
setTimeout(this.quota, 5000);
setTimeout(() => Remote.appDelayStart(()=>0), 35000); setTimeout(() => Remote.appDelayStart(()=>0), 35000);
// When auto-login is active // When auto-login is active
if ( if (
!!SettingsGet('AccountSignMe') && SettingsGet('AccountSignMe') &&
navigator.registerProtocolHandler navigator.registerProtocolHandler
) { ) {
setTimeout(() => { setTimeout(() => {
@ -943,9 +874,8 @@ class AppUser extends AbstractApp {
); );
} catch (e) {} // eslint-disable-line no-empty } catch (e) {} // eslint-disable-line no-empty
if (SettingsGet('MailToEmail')) { value = SettingsGet('MailToEmail');
mailToHelper(SettingsGet('MailToEmail')); value && mailToHelper(value);
}
}, 500); }, 500);
} }
@ -955,6 +885,27 @@ class AppUser extends AbstractApp {
SettingsUserStore.delayLogout(); SettingsUserStore.delayLogout();
setTimeout(() => this.initVerticalLayoutResizer(), 1); setTimeout(() => this.initVerticalLayoutResizer(), 1);
setInterval(this.reloadTime(), 60000);
if (window.crypto && crypto.getRandomValues && Settings.capa(Capa.OpenPGP)) {
const script = createElement('script', {src:openPgpJs()});
script.onload = () => {
PgpUserStore.openpgp = openpgp;
if (window.Worker) {
try {
PgpUserStore.openpgp.initWorker({ path: openPgpWorkerJs() });
} catch (e) {
console.error(e);
}
}
PgpUserStore.openpgpKeyring = new openpgp.Keyring();
PgpUserStore.capaOpenPGP(true);
this.reloadOpenPgpKeys();
};
script.onerror = () => console.error(script.src);
doc.head.append(script);
}
} else { } else {
this.logout(); this.logout();
} }
@ -967,14 +918,12 @@ class AppUser extends AbstractApp {
startScreens([LoginUserScreen]); startScreens([LoginUserScreen]);
this.hideLoading(); this.hideLoading();
} }
setInterval(this.reloadTime(), 60000);
} }
reloadTime() reloadTime()
{ {
setTimeout(() => setTimeout(() =>
doc.querySelectorAll('[data-bind*="moment:"]').forEach(element => timeToNode(element)) doc.querySelectorAll('time').forEach(element => timeToNode(element))
, 1) , 1)
} }

View file

@ -34,18 +34,19 @@ export function timestampToString(timeStampInUTC, formatStr) {
export function timeToNode(element, time) { export function timeToNode(element, time) {
try { try {
time = time || (Date.parse(element.dateTime) / 1000);
if (time) { if (time) {
element.dateTime = (new Date(time * 1000)).format('Y-m-d\\TH:i:s'); element.dateTime = (new Date(time * 1000)).format('Y-m-d\\TH:i:s');
} else {
time = Date.parse(element.dateTime) / 1000;
}
let key = element.dataset.momentFormat; let key = element.dataset.momentFormat;
if (key) { if (key) {
element.textContent = timestampToString(time, key); element.textContent = timestampToString(time, key);
} }
if ((key = element.dataset.momentFormatTitle)) { if ((key = element.dataset.momentFormatTitle)) {
element.title = timestampToString(time, key); element.title = timestampToString(time, key);
}
} }
} catch (e) { } catch (e) {
// prevent knockout crashes // prevent knockout crashes

View file

@ -1,5 +1,4 @@
import ko from 'ko'; import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { addObservablesTo } from 'Common/Utils'; import { addObservablesTo } from 'Common/Utils';
export const AccountUserStore = { export const AccountUserStore = {
@ -18,11 +17,6 @@ export const AccountUserStore = {
// }); // });
// return result; // return result;
// }), // }),
populate: () => {
AccountUserStore.email(SettingsGet('Email'));
AccountUserStore.parentEmail(SettingsGet('ParentEmail'));
}
}; };
addObservablesTo(AccountUserStore, { addObservablesTo(AccountUserStore, {

View file

@ -1,6 +1,7 @@
import ko from 'ko'; import ko from 'ko';
import { SettingsGet } from 'Common/Globals'; import { SettingsGet } from 'Common/Globals';
import { addObservablesTo } from 'Common/Utils'; import { pInt, addObservablesTo } from 'Common/Utils';
import Remote from 'Remote/User/Fetch';
export const ContactUserStore = ko.observableArray(); export const ContactUserStore = ko.observableArray();
@ -9,18 +10,42 @@ ContactUserStore.importing = ko.observable(false).extend({ debounce: 200 });
ContactUserStore.syncing = ko.observable(false).extend({ debounce: 200 }); ContactUserStore.syncing = ko.observable(false).extend({ debounce: 200 });
addObservablesTo(ContactUserStore, { addObservablesTo(ContactUserStore, {
allowSync: false, allowSync: false, // Admin setting
enableSync: false, enableSync: false,
syncUrl: '', syncUrl: '',
syncUser: '', syncUser: '',
syncPass: '' syncPass: ''
}); });
ContactUserStore.populate = function() { /**
this.allowSync(!!SettingsGet('ContactsSyncIsAllowed')); * @param {Function} fResultFunc
this.enableSync(!!SettingsGet('EnableContactsSync')); * @returns {void}
*/
this.syncUrl(SettingsGet('ContactsSyncUrl')); ContactUserStore.sync = fResultFunc => {
this.syncUser(SettingsGet('ContactsSyncUser')); if (ContactUserStore.enableSync()
this.syncPass(SettingsGet('ContactsSyncPassword')); && !ContactUserStore.importing()
&& !ContactUserStore.syncing()
) {
ContactUserStore.syncing(true);
Remote.contactsSync((sResult, oData) => {
ContactUserStore.syncing(false);
fResultFunc && fResultFunc(sResult, oData);
});
}
};
ContactUserStore.init = () => {
let value = !!SettingsGet('ContactsSyncIsAllowed');
ContactUserStore.allowSync(value);
if (value) {
ContactUserStore.enableSync(!!SettingsGet('EnableContactsSync'));
ContactUserStore.syncUrl(SettingsGet('ContactsSyncUrl'));
ContactUserStore.syncUser(SettingsGet('ContactsSyncUser'));
ContactUserStore.syncPass(SettingsGet('ContactsSyncPassword'));
setTimeout(ContactUserStore.sync, 10000);
value = pInt(SettingsGet('ContactsSyncInterval'));
value = 5 <= value ? value : 20;
value = 320 >= value ? value : 320;
setInterval(ContactUserStore.sync, value * 60000 + 5000);
}
}; };

View file

@ -1,7 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { SMAudio } from 'Common/Audio'; import { SMAudio } from 'Common/Audio';
import { SettingsGet } from 'Common/Globals';
import * as Links from 'Common/Links'; import * as Links from 'Common/Links';
/** /**
@ -101,9 +100,4 @@ export const NotificationUserStore = new class {
} }
} }
} }
populate() {
this.enableSoundNotification(!!SettingsGet('SoundNotification'));
this.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
}
}; };

View file

@ -251,7 +251,7 @@ class ContactsPopupView extends AbstractViewPopup {
} }
syncCommand() { syncCommand() {
rl.app.contactsSync(iError => { ContactUserStore.sync(iError => {
iError && alert(getNotification(iError)); iError && alert(getNotification(iError));
this.reloadContactList(true); this.reloadContactList(true);