mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Improve AppUser.bootstart
This commit is contained in:
parent
3c8cdcbb07
commit
9158fcd0eb
6 changed files with 81 additions and 118 deletions
125
dev/App/User.js
125
dev/App/User.js
|
|
@ -183,33 +183,6 @@ class AppUser extends AbstractApp {
|
|||
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() {
|
||||
const sTrashFolder = FolderUserStore.trashFolder(),
|
||||
sSpamFolder = FolderUserStore.spamFolder();
|
||||
|
|
@ -824,7 +797,7 @@ class AppUser extends AbstractApp {
|
|||
}
|
||||
|
||||
logout() {
|
||||
Remote.logout(() => rl.logoutReload((SettingsGet('ParentEmail')||{length:0}).length));
|
||||
Remote.logout(() => rl.logoutReload(!!SettingsGet('ParentEmail')));
|
||||
}
|
||||
|
||||
bootstart() {
|
||||
|
|
@ -838,57 +811,20 @@ class AppUser extends AbstractApp {
|
|||
}
|
||||
}, {capture: true});
|
||||
|
||||
NotificationUserStore.populate();
|
||||
AccountUserStore.populate();
|
||||
ContactUserStore.populate();
|
||||
|
||||
let contactsSyncInterval = pInt(SettingsGet('ContactsSyncInterval'));
|
||||
|
||||
const startupUrl = pString(SettingsGet('StartupUrl'));
|
||||
|
||||
rl.setWindowTitle();
|
||||
if (SettingsGet('Auth')) {
|
||||
rl.setWindowTitle(i18n('GLOBAL/LOADING'));
|
||||
|
||||
NotificationUserStore.enableSoundNotification(!!SettingsGet('SoundNotification'));
|
||||
NotificationUserStore.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
|
||||
|
||||
AccountUserStore.email(SettingsGet('Email'));
|
||||
AccountUserStore.parentEmail(SettingsGet('ParentEmail'));
|
||||
|
||||
this.foldersReload(value => {
|
||||
try {
|
||||
if (value) {
|
||||
if (startupUrl) {
|
||||
rl.route.setHash(root(startupUrl), 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);
|
||||
}
|
||||
value = pString(SettingsGet('StartupUrl'));
|
||||
value && rl.route.setHash(root(value), true);
|
||||
|
||||
startScreens([
|
||||
MailBoxUserScreen,
|
||||
|
|
@ -907,14 +843,9 @@ class AppUser extends AbstractApp {
|
|||
}, refreshFolders);
|
||||
|
||||
// Every 15 minutes
|
||||
setInterval(this.quota, 900000);
|
||||
// Every 20 minutes
|
||||
setInterval(this.foldersReload, 1200000);
|
||||
setInterval(()=>this.quota() | this.foldersReload(), 900000);
|
||||
|
||||
setTimeout(this.contactsSync, 10000);
|
||||
contactsSyncInterval = 5 <= contactsSyncInterval ? contactsSyncInterval : 20;
|
||||
contactsSyncInterval = 320 >= contactsSyncInterval ? contactsSyncInterval : 320;
|
||||
setInterval(this.contactsSync, contactsSyncInterval * 60000 + 5000);
|
||||
ContactUserStore.init();
|
||||
|
||||
this.accountsAndIdentities(true);
|
||||
|
||||
|
|
@ -923,15 +854,15 @@ class AppUser extends AbstractApp {
|
|||
if (getFolderInboxName() !== cF) {
|
||||
this.folderInformation(cF);
|
||||
}
|
||||
this.quota();
|
||||
this.folderInformationMultiply(true);
|
||||
}, 1000);
|
||||
|
||||
setTimeout(this.quota, 5000);
|
||||
setTimeout(() => Remote.appDelayStart(()=>0), 35000);
|
||||
|
||||
// When auto-login is active
|
||||
if (
|
||||
!!SettingsGet('AccountSignMe') &&
|
||||
SettingsGet('AccountSignMe') &&
|
||||
navigator.registerProtocolHandler
|
||||
) {
|
||||
setTimeout(() => {
|
||||
|
|
@ -943,9 +874,8 @@ class AppUser extends AbstractApp {
|
|||
);
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
if (SettingsGet('MailToEmail')) {
|
||||
mailToHelper(SettingsGet('MailToEmail'));
|
||||
}
|
||||
value = SettingsGet('MailToEmail');
|
||||
value && mailToHelper(value);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
|
|
@ -955,6 +885,27 @@ class AppUser extends AbstractApp {
|
|||
SettingsUserStore.delayLogout();
|
||||
|
||||
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 {
|
||||
this.logout();
|
||||
}
|
||||
|
|
@ -967,14 +918,12 @@ class AppUser extends AbstractApp {
|
|||
startScreens([LoginUserScreen]);
|
||||
this.hideLoading();
|
||||
}
|
||||
|
||||
setInterval(this.reloadTime(), 60000);
|
||||
}
|
||||
|
||||
reloadTime()
|
||||
{
|
||||
setTimeout(() =>
|
||||
doc.querySelectorAll('[data-bind*="moment:"]').forEach(element => timeToNode(element))
|
||||
doc.querySelectorAll('time').forEach(element => timeToNode(element))
|
||||
, 1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,18 +34,19 @@ export function timestampToString(timeStampInUTC, formatStr) {
|
|||
|
||||
export function timeToNode(element, time) {
|
||||
try {
|
||||
time = time || (Date.parse(element.dateTime) / 1000);
|
||||
if (time) {
|
||||
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;
|
||||
if (key) {
|
||||
element.textContent = timestampToString(time, key);
|
||||
}
|
||||
let key = element.dataset.momentFormat;
|
||||
if (key) {
|
||||
element.textContent = timestampToString(time, key);
|
||||
}
|
||||
|
||||
if ((key = element.dataset.momentFormatTitle)) {
|
||||
element.title = timestampToString(time, key);
|
||||
}
|
||||
if ((key = element.dataset.momentFormatTitle)) {
|
||||
element.title = timestampToString(time, key);
|
||||
}
|
||||
} catch (e) {
|
||||
// prevent knockout crashes
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import ko from 'ko';
|
||||
import { SettingsGet } from 'Common/Globals';
|
||||
import { addObservablesTo } from 'Common/Utils';
|
||||
|
||||
export const AccountUserStore = {
|
||||
|
|
@ -18,11 +17,6 @@ export const AccountUserStore = {
|
|||
// });
|
||||
// return result;
|
||||
// }),
|
||||
|
||||
populate: () => {
|
||||
AccountUserStore.email(SettingsGet('Email'));
|
||||
AccountUserStore.parentEmail(SettingsGet('ParentEmail'));
|
||||
}
|
||||
};
|
||||
|
||||
addObservablesTo(AccountUserStore, {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import ko from 'ko';
|
||||
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();
|
||||
|
||||
|
|
@ -9,18 +10,42 @@ ContactUserStore.importing = ko.observable(false).extend({ debounce: 200 });
|
|||
ContactUserStore.syncing = ko.observable(false).extend({ debounce: 200 });
|
||||
|
||||
addObservablesTo(ContactUserStore, {
|
||||
allowSync: false,
|
||||
allowSync: false, // Admin setting
|
||||
enableSync: false,
|
||||
syncUrl: '',
|
||||
syncUser: '',
|
||||
syncPass: ''
|
||||
});
|
||||
|
||||
ContactUserStore.populate = function() {
|
||||
this.allowSync(!!SettingsGet('ContactsSyncIsAllowed'));
|
||||
this.enableSync(!!SettingsGet('EnableContactsSync'));
|
||||
|
||||
this.syncUrl(SettingsGet('ContactsSyncUrl'));
|
||||
this.syncUser(SettingsGet('ContactsSyncUser'));
|
||||
this.syncPass(SettingsGet('ContactsSyncPassword'));
|
||||
/**
|
||||
* @param {Function} fResultFunc
|
||||
* @returns {void}
|
||||
*/
|
||||
ContactUserStore.sync = fResultFunc => {
|
||||
if (ContactUserStore.enableSync()
|
||||
&& !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);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { SMAudio } from 'Common/Audio';
|
||||
import { SettingsGet } from 'Common/Globals';
|
||||
import * as Links from 'Common/Links';
|
||||
|
||||
/**
|
||||
|
|
@ -101,9 +100,4 @@ export const NotificationUserStore = new class {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
populate() {
|
||||
this.enableSoundNotification(!!SettingsGet('SoundNotification'));
|
||||
this.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ class ContactsPopupView extends AbstractViewPopup {
|
|||
}
|
||||
|
||||
syncCommand() {
|
||||
rl.app.contactsSync(iError => {
|
||||
ContactUserStore.sync(iError => {
|
||||
iError && alert(getNotification(iError));
|
||||
|
||||
this.reloadContactList(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue