From 304dbb4c0078251f1b4758e673c35a320cc85385 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Mon, 22 Feb 2021 14:21:48 +0100
Subject: [PATCH] Toggle dev tools on 'F12'

---
 main.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/main.js b/main.js
index 36fce4e..46fc489 100644
--- a/main.js
+++ b/main.js
@@ -21,9 +21,11 @@ var client; /* Sub process for the express server */
 class Lektor {
     constructor() {
         this.closed = true;
+        this.attached = false;
         isRunning({ win: 'lektord.exe', linux: 'lektord', mac: 'lektord' }).then(v => {
             if (v && config.content.lektord.attach) {
                 logger.info('main', `Lektord is running! Attach to it`);
+                this.attached = true;
             } else if (v) {
                 logger.error('error', `Lektord is running and attach mode is disable, exit!`);
                 app.quit();
@@ -171,7 +173,11 @@ app.on('ready', () => {
     globalShortcut.register('F12', () => {
         var focused = BrowserWindow.getFocusedWindow();
         if (focused) {
-            focused.webContents.openDevTools();
+            if (!focused.isDevToolsOpened()) {
+                focused.webContents.openDevTools({ mode: 'detach' });
+            } else {
+                focused.webContents.closeDevTools();
+            }
         }
     });
 });
-- 
GitLab