From 9297bdd20c6430a176adf57c467ab97ea34b07d0 Mon Sep 17 00:00:00 2001 From: Stefan Sidlovsky Date: Sat, 28 Oct 2023 12:27:51 +0200 Subject: [PATCH] only one tree explorer window is opened from computation window (issue #13) --- fe/script/Computation.js | 11 ++++++++++- fe/script/Windows.js | 12 +++++++++++- fe/script/events/ComputationWindowEvent.js | 5 +++++ fe/script/events/TreeExplorerWindowEvent.js | 9 ++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/fe/script/Computation.js b/fe/script/Computation.js index 8e8eb52..f688002 100644 --- a/fe/script/Computation.js +++ b/fe/script/Computation.js @@ -1,8 +1,9 @@ let Computation = { - _windowSessionKey: undefined, + _windowSessionKey: undefined, // window session key is computation window label _lastComputation: undefined, _modelTitle: undefined, _windowTimestamp: undefined, + _treeExplorerWindowLabel: undefined, setWindowSessionKey(windowSessionKey) { this._windowSessionKey = windowSessionKey @@ -43,6 +44,14 @@ let Computation = { return this._lastComputation !== undefined; }, + getTreeExplorerWindowLabel() { + return this._treeExplorerWindowLabel + }, + + setTreeExplorerWindowLabel(label) { + this._treeExplorerWindowLabel = label + }, + update_computation_process() { ComputationEndpoints.update_computation_process() .then((computationInfoObject) => { diff --git a/fe/script/Windows.js b/fe/script/Windows.js index 5d7de18..2a64e43 100644 --- a/fe/script/Windows.js +++ b/fe/script/Windows.js @@ -161,7 +161,17 @@ let Windows = { openTreeExplorerWindow() { - let treeWindowLabel = "tree-window:" + Date.now() + let treeWindowLabel = Computation.getTreeExplorerWindowLabel() + + // If the window is already opened, just focus on it + if (treeWindowLabel !== undefined) { + const treeWindow = TAURI.window.WebviewWindow.getByLabel(treeWindowLabel) + treeWindow.setFocus() + return + } + + treeWindowLabel = "tree-window:" + Date.now() + Computation.setTreeExplorerWindowLabel(treeWindowLabel) let windowTitle = Computation.getModelTitle() + ", started: " + new Date(Computation.getWindowTimestamp()).toLocaleTimeString('en-GB') WindowsEndpoints.openTreeExplorerWindow(treeWindowLabel, windowTitle) diff --git a/fe/script/events/ComputationWindowEvent.js b/fe/script/events/ComputationWindowEvent.js index 0d8096f..b230e09 100644 --- a/fe/script/events/ComputationWindowEvent.js +++ b/fe/script/events/ComputationWindowEvent.js @@ -46,3 +46,8 @@ TAURI.window.getCurrent().listen("tauri://close-requested", async () => { Dialog.errorMessage(errorMessage) }) }) + +// Listen for event when tree explorer window is closed +TAURI.event.listen('tree-explorer-window-closed', () => { + Computation.setTreeExplorerWindowLabel(undefined) +}); diff --git a/fe/script/events/TreeExplorerWindowEvent.js b/fe/script/events/TreeExplorerWindowEvent.js index b635be6..7e5f42b 100644 --- a/fe/script/events/TreeExplorerWindowEvent.js +++ b/fe/script/events/TreeExplorerWindowEvent.js @@ -7,4 +7,11 @@ TAURI.event.listen('send-window-session-key', (event) => { console.log("got event") // Initialize the window showTree() -}); \ No newline at end of file +}); + +// Send message to computation window before closing this tree explorer window +TAURI.window.getCurrent().listen("tauri://close-requested", () => { + const computationWindow = TAURI.window.WebviewWindow.getByLabel(Computation.getWindowSessionKey()) + computationWindow.emit('tree-explorer-window-closed', {}) + TAURI.window.getCurrent().close() +})