mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Added back base for simple plugins hooks
This commit is contained in:
parent
fe4dbc729c
commit
830fa5b753
4 changed files with 57 additions and 1 deletions
|
|
@ -1,9 +1,34 @@
|
||||||
import { settingsAddViewModel } from 'Screen/AbstractSettings';
|
import { settingsAddViewModel } from 'Screen/AbstractSettings';
|
||||||
import { SettingsGet } from 'Common/Globals';
|
import { SettingsGet } from 'Common/Globals';
|
||||||
|
import { isArray, isFunction } from 'Common/Utils';
|
||||||
|
|
||||||
const USER_VIEW_MODELS_HOOKS = [],
|
const SIMPLE_HOOKS = {},
|
||||||
|
USER_VIEW_MODELS_HOOKS = [],
|
||||||
ADMIN_VIEW_MODELS_HOOKS = [];
|
ADMIN_VIEW_MODELS_HOOKS = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
rl.addHook = (name, callback) => {
|
||||||
|
if (isFunction(callback)) {
|
||||||
|
if (!isArray(SIMPLE_HOOKS[name])) {
|
||||||
|
SIMPLE_HOOKS[name] = [];
|
||||||
|
}
|
||||||
|
SIMPLE_HOOKS[name].push(callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
* @param {Array=} args = []
|
||||||
|
*/
|
||||||
|
export function runHook(name, args = []) {
|
||||||
|
if (isArray(SIMPLE_HOOKS[name])) {
|
||||||
|
SIMPLE_HOOKS[name].forEach(callback => callback(...args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
* @param {string} action
|
* @param {string} action
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import ko from 'ko';
|
import ko from 'ko';
|
||||||
|
|
||||||
import { doc, $htmlCL } from 'Common/Globals';
|
import { doc, $htmlCL } from 'Common/Globals';
|
||||||
|
import { runHook } from 'Common/Plugins';
|
||||||
import { isNonEmptyArray, isFunction } from 'Common/Utils';
|
import { isNonEmptyArray, isFunction } from 'Common/Utils';
|
||||||
|
|
||||||
let currentScreen = null,
|
let currentScreen = null,
|
||||||
|
|
@ -172,6 +173,8 @@ export function showScreenPopup(ViewModelClassToShow, params = []) {
|
||||||
vm.modalVisibility(true);
|
vm.modalVisibility(true);
|
||||||
|
|
||||||
vm.onShow && vm.onShow(...params);
|
vm.onShow && vm.onShow(...params);
|
||||||
|
|
||||||
|
runHook('view-model-on-show', [vm.name, vm.__vm, params]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,6 +278,8 @@ function screenOnRoute(screenName, subPart) {
|
||||||
autofocus(ViewModelClass.__dom);
|
autofocus(ViewModelClass.__dom);
|
||||||
|
|
||||||
ViewModelClass.__vm.onShowWithDelay && setTimeout(()=>ViewModelClass.__vm.onShowWithDelay, 200);
|
ViewModelClass.__vm.onShowWithDelay && setTimeout(()=>ViewModelClass.__vm.onShowWithDelay, 200);
|
||||||
|
|
||||||
|
runHook('view-model-on-show', [ViewModelClass.name, ViewModelClass.__vm, params]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Notification } from 'Common/Enums';
|
||||||
import { Settings } from 'Common/Globals';
|
import { Settings } from 'Common/Globals';
|
||||||
import { isArray, pInt, pString } from 'Common/Utils';
|
import { isArray, pInt, pString } from 'Common/Utils';
|
||||||
import { serverRequest } from 'Common/Links';
|
import { serverRequest } from 'Common/Links';
|
||||||
|
import { runHook } from 'Common/Plugins';
|
||||||
|
|
||||||
let iJsonErrorCount = 0,
|
let iJsonErrorCount = 0,
|
||||||
iTokenErrorCount = 0;
|
iTokenErrorCount = 0;
|
||||||
|
|
@ -92,6 +93,8 @@ export class AbstractFetchRemote
|
||||||
abortActions.forEach(actionToAbort => abort(actionToAbort));
|
abortActions.forEach(actionToAbort => abort(actionToAbort));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runHook('json-default-request', [sAction, params, sGetAdd]);
|
||||||
|
|
||||||
fetchJSON(sAction, sGetAdd,
|
fetchJSON(sAction, sGetAdd,
|
||||||
params,
|
params,
|
||||||
undefined === iTimeout ? 30000 : pInt(iTimeout),
|
undefined === iTimeout ? 30000 : pInt(iTimeout),
|
||||||
|
|
@ -127,6 +130,14 @@ export class AbstractFetchRemote
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runHook('json-default-response', [
|
||||||
|
sAction,
|
||||||
|
iError,
|
||||||
|
data,
|
||||||
|
cached,
|
||||||
|
params
|
||||||
|
]);
|
||||||
|
|
||||||
fCallback && fCallback(
|
fCallback && fCallback(
|
||||||
iError,
|
iError,
|
||||||
data,
|
data,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Notification } from 'Common/Enums';
|
||||||
import { ClientSideKeyName } from 'Common/EnumsUser';
|
import { ClientSideKeyName } from 'Common/EnumsUser';
|
||||||
import { Settings, SettingsGet } from 'Common/Globals';
|
import { Settings, SettingsGet } from 'Common/Globals';
|
||||||
import { getNotification, reload as translatorReload, convertLangName } from 'Common/Translator';
|
import { getNotification, reload as translatorReload, convertLangName } from 'Common/Translator';
|
||||||
|
import { runHook } from 'Common/Plugins';
|
||||||
|
|
||||||
import { LanguageStore } from 'Stores/Language';
|
import { LanguageStore } from 'Stores/Language';
|
||||||
|
|
||||||
|
|
@ -127,6 +128,20 @@ class LoginUserView extends AbstractViewCenter {
|
||||||
this.emailError(!email);
|
this.emailError(!email);
|
||||||
this.passwordError(!pass);
|
this.passwordError(!pass);
|
||||||
this.additionalCodeError(totp && !code);
|
this.additionalCodeError(totp && !code);
|
||||||
|
|
||||||
|
let pluginResultCode = 0, pluginResultMessage = '';
|
||||||
|
Plugins.runHook('user-login-submit', [(iResultCode, sResultMessage) => {
|
||||||
|
pluginResultCode = iResultCode;
|
||||||
|
pluginResultMessage = sResultMessage;
|
||||||
|
}]);
|
||||||
|
if (0 < pluginResultCode) {
|
||||||
|
this.submitError(getNotification(pluginResultCode));
|
||||||
|
valid = false;
|
||||||
|
} else if (pluginResultMessage) {
|
||||||
|
this.submitError(pluginResultMessage);
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.formError(!valid);
|
this.formError(!valid);
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue