From 1769d18c6d75b668196457384751bff9f2b95188 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sat, 13 May 2023 12:50:39 -0700 Subject: [PATCH] Close btn working --- index.html | 2 +- src/main.js | 14 ++++++++++++-- src/renderer.js | 8 +++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 5209eb1..0c009cb 100755 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
- +
diff --git a/src/main.js b/src/main.js index b4d19f7..41d0070 100755 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, Menu } = require('electron'); +const { app, BrowserWindow, Menu, ipcMain } = require('electron'); const path = require('path'); // Handle creating/removing shortcuts on Windows when installing/uninstalling. @@ -37,10 +37,20 @@ const createWindow = () => { } }; +// Set up close window handler for our custom close button. +const closeWindow = (event) => { + const webContents = event.sender; + const window = BrowserWindow.fromWebContents(webContents); + window?.close(); +} + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow); +app.on('ready', () => { + ipcMain.on('CLOSE_WINDOW', closeWindow); + createWindow(); +}); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits diff --git a/src/renderer.js b/src/renderer.js index 6a1cb81..d23e52c 100755 --- a/src/renderer.js +++ b/src/renderer.js @@ -32,7 +32,7 @@ import './icons/flaticon.css' import './assets/ldom.min' -const { app } = require('electron') +const { app, ipcRenderer } = require('electron') import { Safari } from './models/Safari' import { UI } from './models/UI' import { Body } from './models/Body' @@ -60,6 +60,12 @@ if (!journal) { safari.watchJournalDir() journal.watch() +/* -------------------------------------------------------------------- close window handler ---- */ + +$('#closeBtn').on('click', () => { + ipcRenderer.send('CLOSE_WINDOW') +}) + /* ------------------------------------------------------------------------- build body list ---- */ journal.once('BUILD_BODY_LIST', () => {