Author Topic: login_after seems to not shift data to client  (Read 3773 times)

Offline Loguithat1955

  • Full Member
  • ***
  • Posts: 54
login_after seems to not shift data to client
« on: July 09, 2020, 03:41:09 PM »
Hi thogether. I want to create a new plugin which will be execute only one time, directly after the login and it should pass data to a client javascript to show a html5 notification. I have added here some example code. I didnt get errors. I can see at the server that the string "test if hookis executed" is added to the error.log file. So this part is executed. In the browser console i see "initiated", but i never see the data from the server with the line "data from plugin: somedata", which i expected. Do i miss something? the callback show_notifications seems to be never triggered...

plugin.php
Code: [Select]
class myplugin extends rcube_plugin
{   
    public function init() {
        $rcmail = rcmail::get_instance();
        $this->include_script('client.js');
        $this->add_hook('login_after', array($this, 'get_data'));
    }
   
    function get_data() {
        $rcmail = rcmail::get_instance();
        $data = "somedata";        error_log("test if hookis executed");        $rcmail->output->command('plugin.showNotification', $data);
    }}
client.js
Code: [Select]
function get_notifications(data) {
    console.log("data from plugin: "+data);
}

function test() {
    console.log("initiated");
}

if (window.rcmail)
{
    rcmail.addEventListener('plugin.showNotification', show_notifications);
    rcmail.addEventListener('init', test);
}

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: login_after seems to not shift data to client
« Reply #1 on: July 10, 2020, 01:16:40 AM »
The login_after hook happens right after login before the login redirects to the mail view. Because the redirect to the mail view happens after the hook is triggered there is no UI to output the command to.

I think you would want to set a flag in the session data and then output the command on the mail view if that flag is set. 

Offline Loguithat1955

  • Full Member
  • ***
  • Posts: 54
Re: login_after seems to not shift data to client
« Reply #2 on: July 10, 2020, 03:34:05 PM »
Many thx for this hint. I have bound it now to the refresh hook and set after the first request a cookie. Thats why it executes the request only one time, since it checks the cookie first. You can find the final plugin in the repository https://packagist.org/packages/offerel/syncmarks.There is also a companion Webextension for Firefox. With this and the backend, you can sync your bookmarks across some Firefox installations. You can also send now links to the backend, which triggers the notifications. The extension works also in Google Chrome, but i haven't created a Chrome extension, because i didn't want to spend the money for publishing a free Extension. However, you can side-load the extension in Chrome. You can also do Cross-Browser-Sync, if you want. If Mozilla releases the bookmark API also on mobil platform, it's also possible to use that on mobile. But currently mobile functionality is out of the scope.
Push links will only work with the PHP backend. You can also use WebDAV as backend, but since this is only JSON file based, supporting push isn't possible without a rewrite and using multiple files.