From 6316dbce815a90d0cb0ba1c8b6a3ba9714113258 Mon Sep 17 00:00:00 2001 From: Kontroll <72424960+KontrollFreek@users.noreply.github.com> Date: Sun, 1 Jan 2023 14:23:17 -0800 Subject: [PATCH 1/2] Minimize and Maximize Buttons (Probably) --- index.js | 178 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 93 insertions(+), 85 deletions(-) diff --git a/index.js b/index.js index 3602c03..de86fab 100644 --- a/index.js +++ b/index.js @@ -1,86 +1,94 @@ -const { app, BrowserWindow, Menu, ipcMain, dialog } = require('electron'); -const { autoUpdater } = require('electron-updater'); -const RPC = new require('./modules/rpc'); -let discordRpc = new RPC('827268290417131540', { - verb: "idle", // edit | new | idle -}); -let winMain; - -function createWindow() { - app.allowRendererProcessReuse = false; - - const win = new BrowserWindow({ - width: 1280, - height: 720, - webPreferences: { - nodeIntegration: true - }, - icon: './icon.ico' - }); - - win.loadFile('./editor/dist/index.html'); - win.maximize(); - Menu.setApplicationMenu(null); - winMain = win; - winMain.on('close', e => { - closeEvent(winMain, e); - }); -} - -let eventSent = false; -let t = setTimeout(() => {}, 1); -function closeEvent(winMain, e) { - if(!eventSent) { - winMain.webContents.send('close'); - e.preventDefault(); - eventSent = true; - clearTimeout(t); - t = setTimeout(() => { - eventSent = false; - }, 1000); - } -} - -app.whenReady().then(createWindow); - -app.on('window-all-closed', () => { - if (process.platform != 'darwin') app.quit(); -}); -app.on('browser-window-focus', () => { - winMain = BrowserWindow.getFocusedWindow(); - winMain.on('close', e => { - closeEvent(winMain, e); - }); -}) -app.on('activate', () => { - if(BrowserWindow.getAllWindows().length == 0) createWindow(); -}); - -ipcMain.handle('openDevTools', (e) => { - winMain.webContents.toggleDevTools(); -}); -ipcMain.handle('toggleFullscreen', (e) => { - winMain.setFullScreen(!winMain.fullScreen); -}); -ipcMain.handle('checkUpdates', () => { - //check for updates - autoUpdater.checkForUpdatesAndNotify(); -}); -ipcMain.handle('restartApp', () => { - autoUpdater.quitAndInstall(); -}); -ipcMain.handle('updateRPC', (e, obj) => { - discordRpc.opts = obj; -}); -ipcMain.on('pickFiles', (e, obj) => { - let r = dialog.showOpenDialogSync(winMain, obj[0]); - e.returnValue = r ? r[0] : null; -}); - -autoUpdater.on('update-availible', () => { - winMain.webContents.send('updates'); -}); - -autoUpdater.on('update-downloaded', () => { - winMain.webContents.send('updates_done'); +const { app, BrowserWindow, Menu, ipcMain, dialog } = require('electron'); +const { autoUpdater } = require('electron-updater'); +const RPC = new require('./modules/rpc'); +let discordRpc = new RPC('827268290417131540', { + verb: "idle", // edit | new | idle +}); +let winMain; + +function createWindow() { + app.allowRendererProcessReuse = false; + + const win = new BrowserWindow({ + width: 1280, + height: 720, + webPreferences: { + nodeIntegration: true + }, + icon: './icon.ico' + }); + + win.loadFile('./editor/dist/index.html'); + win.maximize(); + Menu.setApplicationMenu(null); + winMain = win; + winMain.on('close', e => { + closeEvent(winMain, e); + }); + + ipcMain.on('min', () => { + win.minimize() + }) + + ipcMain.on('max', () => { + win.isMaximized() ? win.unmaximize() : win.maximize() + }) +} + +let eventSent = false; +let t = setTimeout(() => {}, 1); +function closeEvent(winMain, e) { + if(!eventSent) { + winMain.webContents.send('close'); + e.preventDefault(); + eventSent = true; + clearTimeout(t); + t = setTimeout(() => { + eventSent = false; + }, 1000); + } +} + +app.whenReady().then(createWindow); + +app.on('window-all-closed', () => { + if (process.platform != 'darwin') app.quit(); +}); +app.on('browser-window-focus', () => { + winMain = BrowserWindow.getFocusedWindow(); + winMain.on('close', e => { + closeEvent(winMain, e); + }); +}) +app.on('activate', () => { + if(BrowserWindow.getAllWindows().length == 0) createWindow(); +}); + +ipcMain.handle('openDevTools', (e) => { + winMain.webContents.toggleDevTools(); +}); +ipcMain.handle('toggleFullscreen', (e) => { + winMain.setFullScreen(!winMain.fullScreen); +}); +ipcMain.handle('checkUpdates', () => { + //check for updates + autoUpdater.checkForUpdatesAndNotify(); +}); +ipcMain.handle('restartApp', () => { + autoUpdater.quitAndInstall(); +}); +ipcMain.handle('updateRPC', (e, obj) => { + discordRpc.opts = obj; +}); +ipcMain.on('pickFiles', (e, obj) => { + let r = dialog.showOpenDialogSync(winMain, obj[0]); + e.returnValue = r ? r[0] : null; +}); + +autoUpdater.on('update-availible', () => { + winMain.webContents.send('updates'); +}); + +autoUpdater.on('update-downloaded', () => { + winMain.webContents.send('updates_done'); }); \ No newline at end of file From cc5ff22c9c6d31934ec71c87009145bb3f573e29 Mon Sep 17 00:00:00 2001 From: Kontroll <72424960+KontrollFreek@users.noreply.github.com> Date: Sun, 1 Jan 2023 17:32:59 -0500 Subject: [PATCH 2/2] Remove frame for supposedly working buttons --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index de86fab..84c730b 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ function createWindow() { const win = new BrowserWindow({ width: 1280, height: 720, + frame: false, webPreferences: { nodeIntegration: true }, @@ -91,4 +92,4 @@ autoUpdater.on('update-availible', () => { autoUpdater.on('update-downloaded', () => { winMain.webContents.send('updates_done'); -}); \ No newline at end of file +});