@@ -24,7 +24,7 @@ import { callWithOriginalXdgCurrentDesktopAsync, unamePlatform } from "./emain-p
2424import { getWaveTabViewByWebContentsId } from "./emain-tabview" ;
2525import { handleCtrlShiftState } from "./emain-util" ;
2626import { getWaveVersion } from "./emain-wavesrv" ;
27- import { createNewWaveWindow , focusedWaveWindow , getWaveWindowByWebContentsId } from "./emain-window" ;
27+ import { createNewWaveWindow , getWaveWindowByWebContentsId } from "./emain-window" ;
2828import { ElectronWshClient } from "./emain-wsh" ;
2929
3030const 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 }
0 commit comments