From 7135af995d2c87476175a23edcf9faa1aab5920b Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 27 Nov 2023 01:51:23 +0100 Subject: [PATCH] Extend example extension code with more details --- dev/Knoin/Knoin.js | 2 +- plugins/README.md | 22 ++++- plugins/example/example.js | 99 +++++++++++++++++-- plugins/example/index.php | 3 + plugins/two-factor-auth/index.php | 6 +- .../two-factor-auth/js/TwoFactorAuthLogin.js | 2 +- 6 files changed, 122 insertions(+), 12 deletions(-) diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index 3e87b0976..2dfff9917 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -160,7 +160,7 @@ const */ screenOnRoute = (screenName, subPart) => { screenName = screenName || defaultScreenName; - if (screenName && fireEvent('sm-show-screen', screenName, 1)) { + if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) { // Close all popups for (let vm of visiblePopups) { (false === vm.onClose()) || vm.close(); diff --git a/plugins/README.md b/plugins/README.md index e594453a0..4395119da 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -408,14 +408,34 @@ and called in JavaScript using rl.pluginRemoteRequest(). ### mailbox.inbox-unread-count ### mailbox.message-list.selector.go-up ### mailbox.message-list.selector.go-down + ### mailbox.message.show + Use to show a specific message. +``` JavaScript + dispatchEvent( + new CustomEvent( + 'mailbox.message.show', + { + detail: { + folder: 'INBOX', + uid: 1 + }, + cancelable: false + } + ) + ); +``` + ## audio ### audio.start ### audio.stop ### audio.api.stop ## Misc -### idle ### rl-layout + event.detail value is one of: + 0. NoPreview + 1. SidePreview + 2. BottomPreview ### rl-view-model.create event.detail = the ViewModel class diff --git a/plugins/example/example.js b/plugins/example/example.js index b1e323970..77368e0d1 100644 --- a/plugins/example/example.js +++ b/plugins/example/example.js @@ -1,22 +1,108 @@ (rl => { - addEventListener('rl-view-model', e => { + + /** + * Happens immediately after the ViewModel constructor + * event.detail contains the ViewModel class + */ + addEventListener('rl-view-model.create', event => { console.dir({ - 'rl-view-model': e.detail + 'rl-view-model.create': event.detail }); }); /** - * e.detail value is one of: + * Happens after the full build (vm.onBuild()) and contains viewModelDom + * event.detail contains the ViewModel class + */ + addEventListener('rl-view-model', event => { + console.dir({ + 'rl-view-model': event.detail + }); + }); + + /** + * event.detail value is one of: * 0 = NoPreview * 1 = SidePreview * 2 = BottomPreview */ - addEventListener('rl-layout', e => { + addEventListener('rl-layout', event => { console.dir({ - 'rl-layout': e.detail + 'rl-layout': event.detail }); }); + /** + * event.detail contains the FormData + * cancelable using event.preventDefault() + */ + addEventListener('sm-admin-login', event => { + console.dir({ + 'sm-admin-login': event.detail + }); + }); + + /** + * event.detail contains { error: int, data: {JSON response} } + */ + addEventListener('sm-admin-login-response', event => { + console.dir({ + 'sm-admin-login-response': event.detail + }); + }); + + /** + * event.detail contains the FormData + * cancelable using event.preventDefault() + */ + addEventListener('sm-user-login', event => { + console.dir({ + 'sm-user-login': event.detail + }); + }); + + /** + * event.detail contains { error: int, data: {JSON response} } + */ + addEventListener('sm-user-login-response', event => { + console.dir({ + 'sm-user-login-response': event.detail + }); + }); + + /** + * event.detail contains the screenname + * cancelable using event.preventDefault() + * Options are: + * - login (user or admin login screen) + * - mailbox (user folders and messages, also like: mailbox/INBOX/test, mailbox/Sent) + * - settings (user settings like: settings/accounts, settings/general, settings/filters) + * - one of the admin sections (like: settings, domains, branding) + */ + addEventListener('sm-show-screen', event => { + console.dir({ + 'sm-show-screen': event.detail + }); + }); + + /** + * Use to show a specific message. + */ +/* + dispatchEvent( + new CustomEvent( + 'mailbox.message.show', + { + detail: { + folder: 'INBOX', + uid: 1 + }, + cancelable: false + } + ) + ); +*/ + class ExamplePopupView extends rl.pluginPopupView { constructor() { super('Example'); @@ -50,6 +136,7 @@ afterHide() {} } - ExamplePopupView.showModal(['param1', 'param2']); + /** Show the modal popup */ +// ExamplePopupView.showModal(['param1', 'param2']); })(window.rl); diff --git a/plugins/example/index.php b/plugins/example/index.php index 2b6cb1512..55ccb0dcc 100644 --- a/plugins/example/index.php +++ b/plugins/example/index.php @@ -37,6 +37,9 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin $this->UseLangs(true); // start use langs folder + $this->addJs('example.js'); // add js file + $this->addJs('example.js', true); // add js file + // User Settings tab $this->addJs('js/ExampleUserSettings.js'); // add js file $this->addJsonHook('JsonGetExampleUserData', 'JsonGetExampleUserData'); diff --git a/plugins/two-factor-auth/index.php b/plugins/two-factor-auth/index.php index f5637c056..4feefd479 100644 --- a/plugins/two-factor-auth/index.php +++ b/plugins/two-factor-auth/index.php @@ -8,9 +8,9 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin { const NAME = 'Two Factor Authentication', - VERSION = '2.16.6', - RELEASE = '2023-10-24', - REQUIRED = '2.15.2', + VERSION = '2.17.0', + RELEASE = '2023-11-27', + REQUIRED = '2.30.0', CATEGORY = 'Login', DESCRIPTION = 'Provides support for TOTP 2FA'; diff --git a/plugins/two-factor-auth/js/TwoFactorAuthLogin.js b/plugins/two-factor-auth/js/TwoFactorAuthLogin.js index e78f8fb3a..aa71747c2 100644 --- a/plugins/two-factor-auth/js/TwoFactorAuthLogin.js +++ b/plugins/two-factor-auth/js/TwoFactorAuthLogin.js @@ -27,7 +27,7 @@ // https://github.com/the-djmaze/snappymail/issues/349 addEventListener('sm-show-screen', e => { - if ('settings' !== e.detail && rl.settings.get('SetupTwoFactor')) { + if (!e.detail.startsWith('settings') && rl.settings.get('SetupTwoFactor')) { e.preventDefault(); forceTOTP(); }