Skip to content

Commit 7bf4fa1

Browse files
loitlyrobyww
authored andcommitted
FIREFLY-859: Firefly viewer unable to support multiple instances of different apps (#1135)
1 parent 8d312fe commit 7bf4fa1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/firefly/js/api/ApiViewer.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const ViewerType= new Enum([
3636

3737
let defaultViewerFile='';
3838
let defaultViewerType=ViewerType.TriView;
39+
const activeViewers = {}; // a map of active viewer windows keyed by channel
3940

4041
/**
4142
* @returns {{getViewer: function, getExternalViewer: function}}
@@ -79,7 +80,7 @@ export function getViewer(channel, file=defaultViewerFile, scriptUrl) {
7980
return getViewer && getViewer(channel, file);
8081
} else {
8182
// return currently loaded app's Viewer
82-
channel = makeViewerChannel(channel || getWsChannel());
83+
channel = makeViewerChannel(channel || getWsChannel(), file);
8384
const dispatch= (action) => dispatchRemoteAction(channel,action);
8485
const reinitViewer= () => dispatch({ type: REINIT_APP, payload: {}});
8586

@@ -297,20 +298,21 @@ function buildChartPart(channel,file,dispatch) {
297298
}
298299

299300
const doViewerOperation= (() => {
300-
let viewerWindow;
301301
return (channel,file,initMsg, f) => {
302302
const cnt = getConnectionCount(channel);
303303
if (cnt > 0) {
304-
viewerWindow ? viewerWindow.focus() : dispatchRemoteAction(channel, {type:GRAB_WINDOW_FOCUS});
304+
activeViewers[channel] ? activeViewers[channel]?.focus() : dispatchRemoteAction(channel, {type:GRAB_WINDOW_FOCUS});
305305
f?.();
306306
} else {
307307
dispatchAddActionWatcher({
308308
callback:windowReadyWatcher, actions:[WS_CONN_UPDATED, NOTIFY_REMOTE_APP_READY], params:{channel,f}
309309
});
310310
const url= `${modifyURLToFull(file,getRootURL())}?${WSCH}=${channel}`;
311-
viewerWindow = window.open(url, channel);
312-
set(viewerWindow, 'firefly.options.RequireWebSocketUptime', true);
313-
initMsg && set(viewerWindow, 'firefly.options.initLoadingMessage', initMsg);
311+
const win = window.open(url, channel);
312+
activeViewers[channel] = win;
313+
win.onclose = () => Reflect.deleteProperty(activeViewers, channel);
314+
set(win, 'firefly.options.RequireWebSocketUptime', true);
315+
initMsg && set(win, 'firefly.options.initLoadingMessage', initMsg);
314316
}
315317
};
316318
})();

src/firefly/js/core/AppDataCntlr.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const GRAB_WINDOW_FOCUS = `${APP_DATA_PATH}.grabFocus`;
4141

4242
/** the extension to add to a channel string to make a viewer channel */
4343
const CHANNEL_VIEWER_EXTENSION = '__viewer';
44+
const channel_matcher = new RegExp(`(.+)${CHANNEL_VIEWER_EXTENSION}(?:-(.+))?`)
4445

4546
/** @type {SearchInfo} */
4647
const searchInfo = {};
@@ -151,8 +152,7 @@ export function dispatchUpdateAppData(appData) {
151152
export function dispatchNotifyRemoteAppReady() {
152153
const channel= getWsChannel();
153154
if (!channel) return;
154-
const sourceChannel= channel.endsWith(CHANNEL_VIEWER_EXTENSION) ?
155-
channel.substr(0,channel.lastIndexOf(CHANNEL_VIEWER_EXTENSION)) : channel;
155+
const [, sourceChannel, app] = channel.match(channel_matcher) || [,channel];
156156
dispatchRemoteAction(sourceChannel,{ type : NOTIFY_REMOTE_APP_READY, payload: {ready:true, viewerChannel:channel}});
157157
}
158158

@@ -177,8 +177,9 @@ export function dispatchOnAppReady(callback) {
177177
* @param {String} channel
178178
* @return {string}
179179
*/
180-
export function makeViewerChannel(channel) {
181-
return channel + CHANNEL_VIEWER_EXTENSION;
180+
export function makeViewerChannel(channel, file) {
181+
file = file ? '-' + file.replaceAll('.', '_') : '';
182+
return channel + CHANNEL_VIEWER_EXTENSION + file;
182183
}
183184

184185
export function isAppReady() {

0 commit comments

Comments
 (0)