kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.36k stars 128 forks source link

Bindings stop working after a while #272

Closed xluk9 closed 3 years ago

xluk9 commented 3 years ago

Hello, new to Phoenix. I've been trying to implement the raise-or-run functionality on my own and it works for a couple of times. Basically, Phoenix for whatever reason, after a couple of times, stops working for any key binding.

Simplified code

const APP_MOD = [ 'cmd', 'control', 'alt', 'shift' ];
const WMS_MOD = [ 'cmd', 'control', 'alt' ];

new Key('t', APP_MOD, function () {
    App.get("iTerm2").focus()
});

new Key('m', WMS_MOD, function () {
    Phoenix.log("Entered in M");
    // App.get("mpv").focus()
    // App.all().forEach( a => Phoenix.log(a.name()))
});

There are no error messages in the Console.app. I was trying with WMS_MOD + m and I see Entered in M a couple of times and then all key bindings stop working. I cannot see any more output in the Console.app. The only way to fix is Reload. How can I debug this ?

kasper commented 3 years ago

@kandiu Hi! See https://github.com/kasper/phoenix/blob/master/docs/API.md#managing-handlers. You need to keep a reference to the handler when initialising them manually, i.e. const key = new Key(…). Otherwise it will be released. Alternatively use, Key.on(…) and Phoenix will do it for you. Hope this helps!

xluk9 commented 3 years ago

@kasper Hi! Thank you for the fast reply. It was indeed that the problem, I somehow missed it while reading the documentation. Thank you!

kasper commented 3 years ago

@kandiu Great, good to hear! Let me know if the documentation can be improved.