Skip to content

Commit

Permalink
raise variable browser window, if already created, otherwise create a…
Browse files Browse the repository at this point in the history
… new window. For #1775.
  • Loading branch information
highperformancecoder committed Dec 27, 2024
1 parent e275c95 commit a92a86a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions gui-js/apps/minsky-electron/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class App {
context: App.mainWindow,
systemWindowId: WindowManager.getSystemWindowId(this.mainWindow),
menu: null,
url: "",
};

WindowManager.activeWindows.set(App.mainWindow.id, mainWindowDetails);
Expand Down
25 changes: 21 additions & 4 deletions gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ export class WindowManager {
return initialURL;
}

/// if window already exists attached to \a url, then raise it
/// @return window if it exists, null otherwise
static raiseWindow(url: string): BrowserWindow {
let window=null;
for (let i of this.activeWindows)
if (i[1].url==url) {
window=i[1].context;
break;
}
if (window) window.show();
return window;
}

static createPopupWindowWithRouting(
payload: CreateWindowPayload,
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down Expand Up @@ -167,8 +180,6 @@ export class WindowManager {
slashes: true,
});

console.log(payload.url);
console.log(filePath);
window.loadURL(filePath);
return window;
}
Expand All @@ -177,8 +188,14 @@ export class WindowManager {
payload: CreateWindowPayload,
onCloseCallback?: (ev : Electron.Event) => void
) {
const { width, height, minWidth, minHeight, title, modal = true, backgroundColor=StoreManager.store.get('backgroundColor'), alwaysOnTop } = payload;
const { width, height, minWidth, minHeight, title, modal = true, backgroundColor=StoreManager.store.get('backgroundColor'), alwaysOnTop, url } = payload;

// do not duplicate window if requested and window already exists
if (payload.raiseIfPresent) {
const childWindow=this.raiseWindow(url);
if (childWindow) return childWindow;
}

const childWindow = new BrowserWindow({
width,
height,
Expand Down Expand Up @@ -225,6 +242,7 @@ export class WindowManager {
context: childWindow,
systemWindowId: windowId,
menu: null,
url,
};

if (payload.uid) {
Expand Down Expand Up @@ -264,7 +282,6 @@ export class WindowManager {
static onAppLayoutChanged(payload: AppLayoutPayload) {

this.topOffset = Math.round(payload.offset.top);
console.log("topOffset=",this.topOffset);
this.leftOffset = Math.round(payload.offset.left);
this.scaleFactor = screen.getPrimaryDisplay().scaleFactor;
if (Functions.isWindows())
Expand Down
3 changes: 2 additions & 1 deletion gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export interface ActiveWindow {
isMainWindow: boolean;
context: BrowserWindow;
systemWindowId: bigint;
menu : Menu
menu: Menu;
url: string;
}
1 change: 1 addition & 0 deletions gui-js/libs/shared/src/lib/interfaces/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface CreateWindowPayload {
minWidth?: number;
minHeight?: number;
alwaysOnTop?: boolean;
raiseIfPresent?: boolean; ///< if true, then raise an existing window instead of creating a duplicate
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ export class VariableComponent {
});
}
}
openVariablePane() {
this.electronService.send(events.CREATE_MENU_POPUP, {
title: 'Variables',
url: "#/headless/variable-pane",
width: 400,
height: 450,
alwaysOnTop: true,
modal: false,
});
openVariablePane() {
this.electronService.send(events.CREATE_MENU_POPUP, {
title: 'Variables',
url: "#/headless/variable-pane",
width: 400,
height: 450,
alwaysOnTop: true,
modal: false,
raiseIfPresent: true,
});
}
}

0 comments on commit a92a86a

Please sign in to comment.