import { spawnSync } from "child_process"; import path from "path"; import { app, BrowserWindow } from "electron"; import { IpcResponse } from "shared/models/ipc"; import log from "electron-log"; import { AppWindow } from "shared/models/window-manager/app-window.model"; // TODO : REFACTOR export class UtilsService{ private static instance: UtilsService; private assetsPath: string = app.isPackaged ? path.join(process.resourcesPath, 'assets') : path.join(__dirname, '../../../assets'); private windows: Map = new Map(); private constructor(){} public static getInstance(){ if(!this.instance){ UtilsService.instance = new UtilsService(); } return UtilsService.instance; } public setAssetsPath(path: string): void{ this.assetsPath = path; } public getAssetsPath(pathToFile: string): string{ return path.join(this.assetsPath, pathToFile); } public getAssetsScriptsPath(): string { return this.getAssetsPath("scripts") } public getAssestsJsonsPath(): string { return this.getAssetsPath("jsons"); } public getTempPath(): string{ return path.join(app.getPath("temp"), app.getName()) } public setMainWindows(windows: Map){ this.windows = windows; } public getMainWindows(win: AppWindow){ return this.windows.get(win); } public taskRunning(task: string): boolean | null{ try{ const tasks = spawnSync('tasklist').stdout; return tasks.toString().includes(task); } catch(error){ log.error(error); return null; } } public ipcSend(channel: string, response: IpcResponse): void{ try { Array.from(this.windows.values()).forEach(window => window?.webContents?.send(channel, response)); } catch (error) { log.error(error); } } }