diff --git a/emain/emain-ipc.ts b/emain/emain-ipc.ts index 72498f15c1..1d1ec2108a 100644 --- a/emain/emain-ipc.ts +++ b/emain/emain-ipc.ts @@ -24,7 +24,7 @@ import { callWithOriginalXdgCurrentDesktopAsync, unamePlatform } from "./emain-p import { getWaveTabViewByWebContentsId } from "./emain-tabview"; import { handleCtrlShiftState } from "./emain-util"; import { getWaveVersion } from "./emain-wavesrv"; -import { createNewWaveWindow, focusedWaveWindow, getWaveWindowByWebContentsId } from "./emain-window"; +import { createNewWaveWindow, getWaveWindowByWebContentsId } from "./emain-window"; import { ElectronWshClient } from "./emain-wsh"; const electronApp = electron.app; @@ -130,12 +130,18 @@ function getUrlInSession(session: Electron.Session, url: string): Promise { if (file.canceled) { + readStream.destroy(); return; } const writeStream = fs.createWriteStream(file.filePath); @@ -213,7 +220,12 @@ export function initIpcHandlers() { const resultP = getUrlInSession(event.sender.session, payload.src); resultP .then((result) => { - saveImageFileWithNativeDialog(result.fileName, result.mimeType, result.stream); + saveImageFileWithNativeDialog( + event.sender.hostWebContents, + result.fileName, + result.mimeType, + result.stream + ); }) .catch((e) => { console.log("error getting image", e); @@ -477,7 +489,7 @@ export function initIpcHandlers() { }); electron.ipcMain.handle("save-text-file", async (event, fileName: string, content: string) => { - const ww = focusedWaveWindow; + const ww = electron.BrowserWindow.fromWebContents(event.sender); if (ww == null) { return false; } diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 07c0c08a6c..2c34d3a39c 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -273,6 +273,7 @@ export class WaveBrowserWindow extends BaseWindow { if (getGlobalIsRelaunching()) { return; } + focusedWaveWindow = this; // eslint-disable-line @typescript-eslint/no-this-alias console.log("focus win", this.waveWindowId); fireAndForget(() => ClientService.FocusWindow(this.waveWindowId)); setWasInFg(true);