Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions emain/emain-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,12 +130,18 @@ function getUrlInSession(session: Electron.Session, url: string): Promise<UrlInS
});
}

function saveImageFileWithNativeDialog(defaultFileName: string, mimeType: string, readStream: Readable) {
function saveImageFileWithNativeDialog(
sender: electron.WebContents,
defaultFileName: string,
mimeType: string,
readStream: Readable
) {
if (defaultFileName == null || defaultFileName == "") {
defaultFileName = "image";
}
const ww = focusedWaveWindow;
const ww = electron.BrowserWindow.fromWebContents(sender);
if (ww == null) {
readStream.destroy();
return;
}
const mimeToExtension: { [key: string]: string } = {
Expand Down Expand Up @@ -164,6 +170,7 @@ function saveImageFileWithNativeDialog(defaultFileName: string, mimeType: string
})
.then((file) => {
if (file.canceled) {
readStream.destroy();
return;
}
const writeStream = fs.createWriteStream(file.filePath);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions emain/emain-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading