veeso / tui-realm

👑 tui-rs framework to build stateful applications with a React/Elm inspired approach

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] - subscription for global hotkey

tramhao opened this issue · comments

I have ESC and Q subscripted as global hotkey to exit the program. However, when I show the help dialogue, I also use ESC to exit it. Here comes the problem, the background subscription will be activated as well.

I read the document about this, and seems like I need to set subclause::not, but I cannot use focus to distinguish the foreground table and background phantom. What should be done? Thanks so much.

Hi,

No, I think, a better approach would be to check whether the conflicting component is already mounted with app.mounted(id) in the update() and based on the return value, perform or not what you need to do.

I do it as below:

Msg::QuitPopupShow => {
                    if self.app.mounted(&Id::HelpPopup) {
                        println!("help mounted");
                        return None;
                    }
                    println!("help not mounted");
                    self.mount_quit_popup();
                    None
                }

But everytime it'll print help not mounted. Maybe it's destroyed earlier than subscription? Thanks.

That's corret, I was wrong. When the sub msg is processed, the component has already been umounted by the previous message. I need to make a new release to solve this issue.

I'm releasing a new version this evening, but basically:

  • I've implemented a new method lock_subs() to stop event propagation to subs. Then you can call unlock_subs() to restore propagation.
  • I've added to SubClause the Id of the component to check for HasAttr and HasState.
  • I've added a new SubClause which is isMounted(Id) which checks whether target component is mounted.

tuirealm 1.2.0 has been released and fixes this issue.

It works!
I lock_subs() when mount any popup and unlock them when no popup mounted. Nice and clean.