How to retrieve App from js in plugins?

Hi,

[sorry I’m a javascript noob]

I’ve written a small plugin to add a new hotkey which toggle feeds sorting by title. It was working fine until the recents changes. I’ve pushed it here for reference:

https://git.tt-rss.org/ggrandou/tt-rss/commit/dd9ec39f7bb2e7a8e4ac92270fc784ee901d8885

I’ve tried to update init.js using no_title_counter plugin as an example without any luck:

require(['dojo/_base/kernel', 'dojo/ready', 'fox/AppBase'], function (dojo, ready) {
	ready(function() {
		console.log("> plugin toggle_sort_titles init.js");
		App.hotkey_actions["feed_toggle_title"] = function() {
			console.log("trigger feed_toggle_title");
		};
	});
});

console log:

> plugin toggle_sort_titles init.js
hostname.fqdn:115:106
TypeError: App is undefined
Stack trace:
[...]

By the way the no_title_counter plugin is failing to for the very same reason too :wink:

I really should start learning javascript…

Thanks.

see here:

https://git.tt-rss.org/fox/tt-rss/commit/a400a8ffc1a5c8a5c4ecb2c0d153881f5b55d232

Waoo that was fast :slight_smile:

It works perfectly except that it looks like that only one callback could be registered for HOOK_INIT_COMPLETE. My function stops to be called as soon as I enable no_title_counter plugin at the same time.

That’s better with this:

--- a/js/PluginHost.js
+++ b/js/PluginHost.js
@@ -24,8 +24,9 @@ PluginHost = {
                //console.warn('PluginHost::run ' + name);
 
                if (typeof(this.hooks[name]) != 'undefined')
-                       for (let i = 0; i < this.hooks[name].length; i++)
-                               if (!this.hooks[name][i](args)) break;
+                       for (let i = 0; i < this.hooks[name].length; i++) {
+                               this.hooks[name][i](args);
+                       }
        }
 };

I’ve made a pull request for the PluginHost fix: https://git.tt-rss.org/fox/tt-rss/pulls/94

And for reference, I’ve updated my branch with the working hotkey plugin: https://git.tt-rss.org/ggrandou/tt-rss/commit/f9d6ac88527444770b7bcaba2c35f62acf9d65da