Api: Take care of private app.js instances, make sure they're included in iteration.

Iterate over all app.js instances (public & private) using:
for (var app_obj of window.EgwApp) {...}
This commit is contained in:
nathangray
2020-04-21 15:36:17 -06:00
parent 16e3b2cd05
commit 444babdbc8
7 changed files with 101 additions and 13 deletions

View File

@@ -76,6 +76,8 @@ var EgwApp = /** @class */ (function () {
}
}
this.mailvelopeSyncHandlerObj = this.mailvelopeSyncHandler();
// Keep track of this instance
EgwApp._register_instance(this);
}
/**
* Clean up any created objects & references
@@ -88,6 +90,10 @@ var EgwApp = /** @class */ (function () {
delete this.sidebox;
if (!_app)
delete app[this.appname];
var index = -1;
if ((index = EgwApp._instances.indexOf(this)) >= 0) {
EgwApp._instances.splice(index, 1);
}
};
/**
* This function is called when the etemplate2 object is loaded
@@ -1668,6 +1674,34 @@ var EgwApp = /** @class */ (function () {
value: { content: { "share_link": _data.share_link } }
});
};
/**
* Keep a list of all EgwApp instances
*
* This is not just the globals available in window.app, it also includes private instances as well
*
* @private
* @param app_obj
*/
EgwApp._register_instance = function (app_obj) {
// Reject improper objects
if (!app_obj.appname)
return;
EgwApp._instances.push(app_obj);
};
/**
* Iterator over all app instances
*
* Use for(const app of EgwApp) {...} to iterate over all app objects.
*/
EgwApp[Symbol.iterator] = function () {
return EgwApp._instances[Symbol.iterator]();
};
/**
* In some cases (CRM) a private, disconnected app instance is created instead of
* using the global. We want to be able to access them for observer() & push(), so
* we track all instances.
*/
EgwApp._instances = [];
return EgwApp;
}());
exports.EgwApp = EgwApp;

View File

@@ -120,6 +120,13 @@ export abstract class EgwApp
mailvelopeSyncHandlerObj : any;
/**
* In some cases (CRM) a private, disconnected app instance is created instead of
* using the global. We want to be able to access them for observer() & push(), so
* we track all instances.
*/
static _instances: EgwApp[] = [];
/**
* Initialization and setup goes here, but the etemplate2 object
* is not yet ready.
@@ -152,6 +159,9 @@ export abstract class EgwApp
}
}
this.mailvelopeSyncHandlerObj = this.mailvelopeSyncHandler();
// Keep track of this instance
EgwApp._register_instance(this);
}
/**
@@ -165,6 +175,11 @@ export abstract class EgwApp
this.sidebox.off();
delete this.sidebox;
if (!_app) delete app[this.appname];
let index = -1;
if((index = EgwApp._instances.indexOf(this)) >= 0)
{
EgwApp._instances.splice(index,1);
}
}
/**
@@ -2084,4 +2099,30 @@ export abstract class EgwApp
value: {content:{ "share_link": _data.share_link }}
});
}
/**
* Keep a list of all EgwApp instances
*
* This is not just the globals available in window.app, it also includes private instances as well
*
* @private
* @param app_obj
*/
private static _register_instance(app_obj: EgwApp)
{
// Reject improper objects
if(!app_obj.appname) return;
EgwApp._instances.push(app_obj);
}
/**
* Iterator over all app instances
*
* Use for(const app of EgwApp) {...} to iterate over all app objects.
*/
static [Symbol.iterator]()
{
return EgwApp._instances[Symbol.iterator]();
}
}

View File

@@ -337,9 +337,8 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
// notify app observers: if observer for _app itself returns false, no regular refresh will take place
// app's own observer can replace current app_refresh functionality
var no_regular_refresh = false;
for(var app in _wnd.egw.window.app) // run observers in main window (eg. not iframe, which might be opener!)
for(var app_obj of _wnd.egw.window.EgwApp) // run observers in main window (eg. not iframe, which might be opener!)
{
var app_obj = _wnd.egw.window.app[app];
if (typeof app_obj.observer == 'function' &&
app_obj.observer(_msg, _app, _id, _type, _msg_type, _links) === false && app === _app)
{
@@ -425,9 +424,8 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
}
// notify app observers
for (var app in _wnd.egw.window.app) // run observers in main window (eg. not iframe, which might be opener!)
for (var app_obj of _wnd.egw.window.EgwApp) // run observers in main window (eg. not iframe, which might be opener!)
{
var app_obj = _wnd.egw.window.app[app];
if (typeof app_obj.push == 'function')
{
app_obj.push(pushData);