diff --git a/app/assets/javascripts/app/services/componentManager.js b/app/assets/javascripts/app/services/componentManager.js index 7dcfc79e4..37c23eeb4 100644 --- a/app/assets/javascripts/app/services/componentManager.js +++ b/app/assets/javascripts/app/services/componentManager.js @@ -808,6 +808,8 @@ class ComponentManager { } }); this.postActiveThemeToComponent(component); + + this.desktopManager.notifyComponentActivation(component); } /* Performs func in timeout, but syncronously, if used `await waitTimeout` */ diff --git a/app/assets/javascripts/app/services/desktopManager.js b/app/assets/javascripts/app/services/desktopManager.js index 23612e64f..d437fa296 100644 --- a/app/assets/javascripts/app/services/desktopManager.js +++ b/app/assets/javascripts/app/services/desktopManager.js @@ -10,6 +10,7 @@ class DesktopManager { this.$rootScope = $rootScope; this.timeout = $timeout; this.updateObservers = []; + this.componentActivationObservers = []; this.isDesktop = isDesktopApplication(); @@ -106,7 +107,28 @@ class DesktopManager { for(var observer of this.updateObservers) { observer.callback(component); } - }) + }); + } + + desktop_registerComponentActivationObserver(callback) { + var observer = {id: Math.random, callback: callback}; + this.componentActivationObservers.push(observer); + return observer; + } + + desktop_deregisterComponentActivationObserver(observer) { + _.pull(this.componentActivationObservers, observer); + } + + /* Notify observers that a component has been registered/activated */ + async notifyComponentActivation(component) { + var serializedComponent = await this.convertComponentForTransmission(component); + + this.timeout(() => { + for(var observer of this.componentActivationObservers) { + observer.callback(serializedComponent); + } + }); } /* Used to resolve "sn://" */