From 55a3ded5cdb46750a82be8763bd57294b4350b5d Mon Sep 17 00:00:00 2001 From: Ruby Allison Rose Date: Tue, 1 Dec 2020 00:08:54 -0800 Subject: [PATCH] feat: Users can now toggle the header on and off. I'm too tired from work right now, but you should really consider turning node-integration off. I understand the nuiscance of it, but it would be added security for users. I'm not a pentester, but I know hardening is good in most projects. --- app/config.js | 1 + app/index.js | 3 ++- app/menu.js | 12 +++++++++++- app/renderer/main.js | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/config.js b/app/config.js index c60f4f3..f82600f 100644 --- a/app/config.js +++ b/app/config.js @@ -9,6 +9,7 @@ module.exports = new Config({ shortcut: { toggleApp: null }, + showHeader: true, mode: 'dark' } }) diff --git a/app/index.js b/app/index.js index 89fcf51..4ef5d67 100644 --- a/app/index.js +++ b/app/index.js @@ -60,7 +60,8 @@ function createMainWindow() { }, webPreferences: { nodeIntegration: true, - webviewTag: true + webviewTag: true, + // preload: "renderer/preload-index.js" } }) diff --git a/app/menu.js b/app/menu.js index a682e3b..1014e82 100644 --- a/app/menu.js +++ b/app/menu.js @@ -3,7 +3,8 @@ const { shell, globalShortcut, BrowserWindow, - dialog + dialog, + ipcMain: ipc } = require('electron') const axios = require('axios') const semverCompare = require('semver-compare') @@ -48,6 +49,15 @@ function createMenu(opts) { shell.openItem(configDir('custom.js')) } }, + { + label: 'Toggle Header Bar', + click() { + const [win] = BrowserWindow.getAllWindows(); + const showHeader = !config.get("showHeader"); + win.webContents.send("toggle-header", showHeader); + config.set("showHeader", showHeader); + } + }, { label: `${ toggleAppAcceleratorRegistered ? 'Disable' : 'Enable' diff --git a/app/renderer/main.js b/app/renderer/main.js index 8d822ed..4ebf32e 100644 --- a/app/renderer/main.js +++ b/app/renderer/main.js @@ -23,10 +23,16 @@ function ensureCustomFiles() { } } +ipc.on('toggle-header', (event, state) => { + const headerBar = document.getElementsByTagName("header")[0]; + headerBar.style.display = state ? "" : "none"; +}); + function createHeader() { const header = document.createElement('header') header.className = 'header' header.innerHTML = '

Loading DevDocs...

' + header.style.display = config.get("showHeader") ? "" : "none"; header.addEventListener('dblclick', () => { win.maximize() })