123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
"use strict";
modulum('NavigationService', ['InitService'],
function(context, cls) {
context.NavigationService = context.oo.StaticClass( {
__name: "NavigationService",
_eventListener: null,
_handlerRegistered: false,
_newRootApplicationEvent: "gbc.NavigationService.newRootApplication",
init: function() {
this._eventListener = new cls.EventListener();
window.requestAnimationFrame(() => {
gbc.HostService.onCurrentWindowChange(this._registerHandler.bind(this));
});
},
_registerHandler: function() {
if (this._handlerRegistered) {
return;
}
this._handlerRegistered = true;
var navigationManager = gbc.SessionService.getCurrent().getNavigationManager();
navigationManager.when(context.constants.VMSessionNavigationManagerEvents
.addSessionSidebarApplicationStackItem,
(event) => {
let application = event.data[0];
this._eventListener.emit(this._newRootApplicationEvent, application);
});
},
newRootApplication: function(applicationId) {
let application = gbc.SessionService.getCurrent().getCurrentApplication();
application.protocolInterface.runApplication(application, applicationId);
},
onNewRootApplication: function(callback) {
return this._eventListener.when(this._newRootApplicationEvent, function(event) {
callback(event.data[0]);
});
},
getRootApplicationList: function() {
var res = new Set();
var navigationManager = gbc.SessionService.getCurrent().getNavigationManager();
var appList = navigationManager.getApplications();
appList.forEach((app) => {
res.add(navigationManager.getRootWaitingApplication(app));
});
return Array.from(res);
},
getCurrentRootApplication: function() {
var session = gbc.SessionService.getCurrent();
var navigationManager = session.getNavigationManager();
return navigationManager.getRootWaitingApplication(session.getCurrentApplication());
},
setForegroundApplication: function(application) {
application.getSession().getNavigationManager().goBackToLastActiveWindow(application);
},
closeApplication: function() {
gbc.SessionService.getCurrent().getCurrentApplication().close();
},
setApplicationListVisible: function(visible) {
gbc.HostLeftSidebarService.setApplicationListVisible(visible);
}
});
context.InitService.register(context.NavigationService);
});