mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
fix object desctory when oneClick window close
This commit is contained in:
@@ -7,6 +7,7 @@ import { app, BrowserWindow } from "electron";
|
||||
import { rm, unlink } from "fs/promises";
|
||||
import { IpcResponse } from "shared/models/ipc";
|
||||
import log from "electron-log";
|
||||
import { AppWindow } from "shared/models/window-manager/app-window.model";
|
||||
|
||||
export class UtilsService{
|
||||
|
||||
@@ -14,7 +15,7 @@ export class UtilsService{
|
||||
|
||||
private assetsPath: string = '';
|
||||
|
||||
private mainWindow: BrowserWindow;
|
||||
private windows: Map<AppWindow, BrowserWindow> = new Map<AppWindow, BrowserWindow>();
|
||||
|
||||
private constructor(){}
|
||||
|
||||
@@ -30,8 +31,8 @@ export class UtilsService{
|
||||
public getAssestsJsonsPath(): string { return this.getAssetsPath("jsons"); }
|
||||
public getTempPath(): string{ return path.join(app.getPath("temp"), app.getName()) }
|
||||
|
||||
public setMainWindow(win: BrowserWindow){ this.mainWindow = win; }
|
||||
public getMainWindow(){ return this.mainWindow; }
|
||||
public setMainWindows(windows: Map<AppWindow, BrowserWindow>){ this.windows = windows; }
|
||||
public getMainWindows(win: AppWindow){ return this.windows.get(win); }
|
||||
|
||||
public pathExist(path: string): boolean{ return existsSync(path); }
|
||||
|
||||
@@ -95,7 +96,7 @@ export class UtilsService{
|
||||
|
||||
public ipcSend<T = any>(channel: string, response: IpcResponse<T>): void{
|
||||
try {
|
||||
this.mainWindow.webContents.send(channel, response);
|
||||
Array.from(this.windows.values()).forEach(window => window.webContents.send(channel, response));
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
|
||||
@@ -53,15 +53,11 @@ export class WindowManagerService{
|
||||
});
|
||||
|
||||
this.windows.set(windowType, window);
|
||||
this.utilsService.setMainWindow(window);
|
||||
this.utilsService.setMainWindows(this.windows);
|
||||
|
||||
return promise.then(() => window);
|
||||
}
|
||||
|
||||
public closeWindow(window: AppWindow){
|
||||
this.windows.get(window).close();
|
||||
}
|
||||
|
||||
public closeAllWindows(except?: AppWindow){
|
||||
this.windows.forEach((window, key) => {
|
||||
if(key === except){ return; }
|
||||
@@ -69,4 +65,10 @@ export class WindowManagerService{
|
||||
})
|
||||
}
|
||||
|
||||
public close(...win: AppWindow[]){
|
||||
win.forEach(window => {
|
||||
this.windows.get(window)?.close();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user