Skip to content

Commit f59fdb5

Browse files
authored
Fix focusedWaveWindow (also fixes bug w/ save session as....) (#2987)
1 parent 1a1cd85 commit f59fdb5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

emain/emain-ipc.ts

Lines changed: 17 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,12 +130,18 @@ 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) {
144+
readStream.destroy();
139145
return;
140146
}
141147
const mimeToExtension: { [key: string]: string } = {
@@ -164,6 +170,7 @@ function saveImageFileWithNativeDialog(defaultFileName: string, mimeType: string
164170
})
165171
.then((file) => {
166172
if (file.canceled) {
173+
readStream.destroy();
167174
return;
168175
}
169176
const writeStream = fs.createWriteStream(file.filePath);
@@ -213,7 +220,12 @@ export function initIpcHandlers() {
213220
const resultP = getUrlInSession(event.sender.session, payload.src);
214221
resultP
215222
.then((result) => {
216-
saveImageFileWithNativeDialog(result.fileName, result.mimeType, result.stream);
223+
saveImageFileWithNativeDialog(
224+
event.sender.hostWebContents,
225+
result.fileName,
226+
result.mimeType,
227+
result.stream
228+
);
217229
})
218230
.catch((e) => {
219231
console.log("error getting image", e);
@@ -477,7 +489,7 @@ export function initIpcHandlers() {
477489
});
478490

479491
electron.ipcMain.handle("save-text-file", async (event, fileName: string, content: string) => {
480-
const ww = focusedWaveWindow;
492+
const ww = electron.BrowserWindow.fromWebContents(event.sender);
481493
if (ww == null) {
482494
return false;
483495
}

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)