diff --git a/src/client/assets/js/menubar.js b/src/client/assets/js/menubar.js deleted file mode 100644 index fb580ba..0000000 --- a/src/client/assets/js/menubar.js +++ /dev/null @@ -1,21 +0,0 @@ -const { remote } = require('electron') - -function getCurrentWindow() { - return remote.getCurrentWindow() -} - -function minimizeWindow(browserWindow = getCurrentWindow()) { - if (browserWindow.minimizable) { - browserWindow.minimize() - } -} - -function closeWindow(browserWindow = getCurrentWindow()) { - browserWindow.close() -} - -module.exports = { - getCurrentWindow, - minimizeWindow, - closeWindow, -} \ No newline at end of file diff --git a/src/client/assets/js/script.js b/src/client/assets/js/script.js index 6e5a209..a97b5e7 100644 --- a/src/client/assets/js/script.js +++ b/src/client/assets/js/script.js @@ -1,21 +1,11 @@ 'use strict'; const {ipcRenderer} = require('electron'); -const { - getCurrentWindow, - minimizeWindow, - closeWindow, - } = require("./assets/js/menubar.js"); window.addEventListener("DOMContentLoaded", () => { - window.getCurrentWindow = getCurrentWindow - window.minimizeWindow = minimizeWindow - window.closeWindow = closeWindow const minimizeButton = document.getElementById("minimize-btn") const closeButton = document.getElementById("close-btn") - minimizeButton.addEventListener("click", e => window.minimizeWindow()) + minimizeButton.addEventListener("click", e => ipcRenderer.send('minimizeWindow')) - // maxUnmaxButton.addEventListener("click", e => window.maxUnmaxWindow()) - - closeButton.addEventListener("click", e => window.closeWindow()) + closeButton.addEventListener("click", e => ipcRenderer.send('closeWindow')) }) diff --git a/src/server/main.js b/src/server/main.js index 3010ac8..f75857a 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -39,6 +39,14 @@ function createWindow () { win.loadFile('src/client/login.html') } +const { + setWindow, + minimizeWindow, + closeWindow + } = require("./menubar.js"); + + setWindow(win) + app.whenReady().then(() => { createWindow() }) @@ -49,6 +57,14 @@ app.on('window-all-closed', () => { } }) +ipcMain.on('minimizeWindow', () => { + minimizeWindow(win) +}) + +ipcMain.on('closeWindow', () => { + closeWindow(win) +}) + app.on('activate', () => { if (win === null){ createWindow() diff --git a/src/server/menubar.js b/src/server/menubar.js new file mode 100644 index 0000000..c782648 --- /dev/null +++ b/src/server/menubar.js @@ -0,0 +1,21 @@ +let win; + +function setWindow(browserWindow) { + win = browserWindow; +} + +function minimizeWindow(browserWindow = win) { + if(browserWindow.minimizable) { + browserWindow.minimize() + } +} + +function closeWindow(browserWindow = win) { + browserWindow.close() +} + +module.exports = { + setWindow, + minimizeWindow, + closeWindow +} \ No newline at end of file