minor v10 cleanup (waveReadyPromise, focusedWaveWindow) (#1456)

This commit is contained in:
Mike Sawka 2024-12-10 10:58:50 -08:00 committed by GitHub
parent c4fce5acc5
commit f1a590f51b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 13 deletions

View File

@ -23,7 +23,10 @@ export type WindowOpts = {
};
export const waveWindowMap = new Map<string, WaveBrowserWindow>(); // waveWindowId -> WaveBrowserWindow
export let focusedWaveWindow = null; // on blur we do not set this to null (but on destroy we do)
// on blur we do not set this to null (but on destroy we do), so this tracks the *last* focused window
// e.g. it persists when the app itself is not focused
export let focusedWaveWindow: WaveBrowserWindow = null;
let cachedClientId: string = null;
@ -62,7 +65,6 @@ function showCloseConfirmDialog(workspace: Workspace): boolean {
export class WaveBrowserWindow extends BaseWindow {
waveWindowId: string;
workspaceId: string;
waveReadyPromise: Promise<void>;
allLoadedTabViews: Map<string, WaveTabView>;
activeTabView: WaveTabView;
private canClose: boolean;
@ -211,12 +213,7 @@ export class WaveBrowserWindow extends BaseWindow {
setWasActive(true);
});
this.on("blur", () => {
if (this.isDestroyed()) {
return;
}
if (focusedWaveWindow == this) {
focusedWaveWindow = null;
}
// nothing for now
});
this.on("close", (e) => {
if (this.canClose) {
@ -470,6 +467,9 @@ export class WaveBrowserWindow extends BaseWindow {
private async processActionQueue() {
while (this.actionQueue.length > 0) {
try {
if (this.isDestroyed()) {
break;
}
const entry = this.actionQueue[0];
let tabId: string = null;
// have to use "===" here to get the typechecker to work :/
@ -725,7 +725,6 @@ export async function createNewWaveWindow() {
const existingWindowData = (await ObjectService.GetObject("window:" + existingWindowId)) as WaveWindow;
if (existingWindowData != null) {
const win = await createBrowserWindow(existingWindowData, fullConfig, { unamePlatform });
await win.waveReadyPromise;
win.show();
recreatedWindow = true;
}
@ -736,7 +735,6 @@ export async function createNewWaveWindow() {
}
console.log("creating new window");
const newBrowserWindow = await createBrowserWindow(null, fullConfig, { unamePlatform });
await newBrowserWindow.waveReadyPromise;
newBrowserWindow.show();
}
@ -768,7 +766,6 @@ export async function relaunchBrowserWindows() {
wins.push(win);
}
for (const win of wins) {
await win.waveReadyPromise;
console.log("show window", win.waveWindowId);
win.show();
}

View File

@ -94,7 +94,6 @@ function handleWSEvent(evtMsg: WSEventType) {
}
const fullConfig = await services.FileService.GetFullConfig();
const newWin = await createBrowserWindow(windowData, fullConfig, { unamePlatform });
await newWin.waveReadyPromise;
newWin.show();
} else if (evtMsg.eventtype == "electron:closewindow") {
console.log("electron:closewindow", evtMsg.data);
@ -378,6 +377,9 @@ function saveImageFileWithNativeDialog(defaultFileName: string, mimeType: string
defaultFileName = "image";
}
const ww = focusedWaveWindow;
if (ww == null) {
return;
}
const mimeToExtension: { [key: string]: string } = {
"image/png": "png",
"image/jpeg": "jpg",

View File

@ -164,8 +164,10 @@ export class Updater {
type: "info",
message: "There are currently no updates available.",
};
if (focusedWaveWindow) {
dialog.showMessageBox(focusedWaveWindow, dialogOpts);
}
}
// Only update the last check time if this is an automatic check. This ensures the interval remains consistent.
if (!userInput) this.lastUpdateCheck = now;