Skip to content

Commit 185bf62

Browse files
committed
fix focusedWaveWindow assignment
1 parent 61d8445 commit 185bf62

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

emain/emain-ipc.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { callWithOriginalXdgCurrentDesktopAsync, unamePlatform } from "./emain-p
2424
import { getWaveTabViewByWebContentsId } from "./emain-tabview";
2525
import { handleCtrlShiftState } from "./emain-util";
2626
import { getWaveVersion } from "./emain-wavesrv";
27-
import { createNewWaveWindow, focusedWaveWindow, getWaveWindowByWebContentsId } from "./emain-window";
27+
import { createNewWaveWindow, getWaveWindowByWebContentsId } from "./emain-window";
2828
import { ElectronWshClient } from "./emain-wsh";
2929

3030
const electronApp = electron.app;
@@ -130,11 +130,16 @@ function getUrlInSession(session: Electron.Session, url: string): Promise<UrlInS
130130
});
131131
}
132132

133-
function saveImageFileWithNativeDialog(defaultFileName: string, mimeType: string, readStream: Readable) {
133+
function saveImageFileWithNativeDialog(
134+
sender: electron.WebContents,
135+
defaultFileName: string,
136+
mimeType: string,
137+
readStream: Readable
138+
) {
134139
if (defaultFileName == null || defaultFileName == "") {
135140
defaultFileName = "image";
136141
}
137-
const ww = focusedWaveWindow;
142+
const ww = electron.BrowserWindow.fromWebContents(sender);
138143
if (ww == null) {
139144
return;
140145
}
@@ -213,7 +218,12 @@ export function initIpcHandlers() {
213218
const resultP = getUrlInSession(event.sender.session, payload.src);
214219
resultP
215220
.then((result) => {
216-
saveImageFileWithNativeDialog(result.fileName, result.mimeType, result.stream);
221+
saveImageFileWithNativeDialog(
222+
event.sender.hostWebContents,
223+
result.fileName,
224+
result.mimeType,
225+
result.stream
226+
);
217227
})
218228
.catch((e) => {
219229
console.log("error getting image", e);
@@ -477,7 +487,7 @@ export function initIpcHandlers() {
477487
});
478488

479489
electron.ipcMain.handle("save-text-file", async (event, fileName: string, content: string) => {
480-
const ww = electron.BrowserWindow.fromWebContents(event.sender) ?? focusedWaveWindow;
490+
const ww = electron.BrowserWindow.fromWebContents(event.sender);
481491
if (ww == null) {
482492
return false;
483493
}

emain/emain-window.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export class WaveBrowserWindow extends BaseWindow {
273273
if (getGlobalIsRelaunching()) {
274274
return;
275275
}
276+
focusedWaveWindow = this; // eslint-disable-line @typescript-eslint/no-this-alias
276277
console.log("focus win", this.waveWindowId);
277278
fireAndForget(() => ClientService.FocusWindow(this.waveWindowId));
278279
setWasInFg(true);

0 commit comments

Comments
 (0)