const electron = require("electron"); const { app, BrowserWindow, Menu, session, remote, dialog, nativeTheme } = electron; const path = require("path"); const fs = require("fs"); let _mainWin = null; let _opUrl = "http://127.0.0.1:8999"; ///application/op/00.main/main.html"; let _isDev = false; let _sessionLogin = false; const _appTitle = "용인시 ITS 통합운영단말"; // const isWindows = process.platform === "win32"; // let needsFocusFix = false; // let triggeringProgrammaticBlur = false; app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); app.allowRendererProcessReuse = true; process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true"; // app.commandLine.appendSwitch("--enable-transparent-visuals"); // app.commandLine.appendSwitch("enable-features", "CSSColorSchemeUARendering, ImpulseScrollAnimations, ParallelDownloading"); try { _isDev = process.env.NODE_ENV.trim() === "dev"; } catch (error) { console.log(error); } try { let configFile; if (_isDev == true) { configFile = path.join(__dirname, "extraResources", "config.json"); } else { configFile = path.join(path.dirname(__dirname), "extraResources", "config.json"); } const config = JSON.parse(fs.readFileSync(configFile, "utf8")); _opUrl = config.op; } catch (error) { console.log(error); } function minimizeWindow() { const win = BrowserWindow.getFocusedWindow(); if (win) { win.setFullScreen(false); } } function toggleWindow() { const win = BrowserWindow.getFocusedWindow(); if (win) { if (win.isFullScreen()) { win.setFullScreen(false); } else { win.setFullScreen(true); } } } function toggleDevTools() { const win = BrowserWindow.getFocusedWindow(); if (win) { win.toggleDevTools(); } } function clearCache() { // const win = remote.getFocusedWindow(); // if (win) { // win.webContents.session.clearCache(function () {}); // console.log("aaaaaaaaaaaaaaaaaaaaaaaaa"); // } session.defaultSession.clearCache(); //console.log("aaaaaaaaaaaaaaaaaaaaaaaaa"); } const createWindow = () => { app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); let preloadJs; if (_isDev) { preloadJs = path.join(__dirname, "preload.js"); } else { preloadJs = path.join(path.dirname(__dirname), "preload.js"); } Menu.setApplicationMenu(null); const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize; _mainWin = new BrowserWindow({ // titleBarStyle: "hidden", // titleBarOverlay: { // color: "#2f3241", // symbolColor: "#74b1be", // }, webPreferences: { webSecurity: false, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: true, enableRemoteModule: true, plugins: true, experimentalFeatures: true, defaultEncoding: "UTF-8", allowRunningInsecureContent: true, autoplayPolicy: "no-user-gesture-required", //"document-user-activation-required", //preload: preloadJs, }, title: "용인시 ITS 통합운영단말", center: true, backgroundColor: "#80FFFFFF", show: false, width: width, height: height, icon: "./assets/icons/png/main-logo.png", // icon: path.join(_dirPath, "assets/icons/png/main-logo.png"), }); _mainWin.once("ready-to-show", () => { _mainWin?.show(); }); _mainWin.on("close", (e) => { if (_sessionLogin) { const opt = { type: "question", //종류 buttons: ["Yes", "No"], //버튼 스타일 defaultId: 2, //고유 아이디 title: _appTitle, //제목 message: "프로그램을 종료하시겠습니까?.", detail: _appTitle, }; let res = dialog.showMessageBoxSync(null, opt); if (res === 0) { _mainWin.webContents.executeJavaScript("logout();"); } else { e.preventDefault(); } } }); _mainWin.on("closed", function () { _mainWin = null; }); _mainWin.on("page-title-updated", (e, title) => { session.defaultSession.cookies.get({}).then((cookies) => { cookies.forEach((cookie) => { if (cookie.name == "UUID") { _sessionLogin = true; } }); }); }); // _mainWin.on("blur", (event) => { // if (!triggeringProgrammaticBlur) { // needsFocusFix = true; // } // }); // _mainWin.on("focus", (event) => { // if (isWindows && needsFocusFix) { // needsFocusFix = false; // triggeringProgrammaticBlur = true; // setTimeout(function () { // _mainWin.blur(); // _mainWin.focus(); // setTimeout(function () { // triggeringProgrammaticBlur = false; // }, 100); // }, 100); // } // }); _mainWin.maximize(); // 최대 화면으로 시작 _mainWin.loadURL(_opUrl); //_mainWin.webContents.focus(); // ipcMain.handle("dark-mode:toggle", () => { // if (nativeTheme.shouldUseDarkColors) { // nativeTheme.themeSource = "light"; // } else { // nativeTheme.themeSource = "dark"; // } // return nativeTheme.shouldUseDarkColors; // }); // ipcMain.handle("dark-mode:system", () => { // nativeTheme.themeSource = "system"; // }); // if (nativeTheme.shouldUseDarkColors) { // nativeTheme.themeSource = "dark"; // } }; app.whenReady().then(() => { createWindow(); app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); let ret; ret = electron.globalShortcut.register("F11", function () { toggleWindow(); }); ret = electron.globalShortcut.register("CmdOrCtrl+Shift+I", function () { toggleDevTools(); }); ret = electron.globalShortcut.register("CmdOrCtrl+Shift+R", function () { clearCache(); }); ret = electron.globalShortcut.register("F12", function () { toggleDevTools(); }); }); app.on("window-all-closed", () => { //electron.globalShortcut.unregisterAll(); if (process.platform !== "darwin") { app.quit(); } });