For the visibility I'd use a (non-persistent) object and a boolean, this way you can use the default visibility of Mx.
For updating this boolean and calling this function I would either use the HTML snippet (for an easy function call) or build a small custom widget. See: https://docs.mendix.com/howto6/scaffold-a-widget-with-the-yeoman-widget-generator
You can use the subscribe method in the client api to subscribe to an attribute change:
I hope this helps