@@ -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,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 }
0 commit comments