Skip to content

Commit

Permalink
only one tree explorer window is opened from computation window (issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Sidlovsky committed Oct 28, 2023
1 parent 2420293 commit 9297bdd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
11 changes: 10 additions & 1 deletion fe/script/Computation.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
12 changes: 11 additions & 1 deletion fe/script/Windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions fe/script/events/ComputationWindowEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
9 changes: 8 additions & 1 deletion fe/script/events/TreeExplorerWindowEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ TAURI.event.listen('send-window-session-key', (event) => {
console.log("got event")
// Initialize the window
showTree()
});
});

// 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()
})

0 comments on commit 9297bdd

Please sign in to comment.