From 76b1f4b3210179b60e4709cc02e65b0313cb6f7e Mon Sep 17 00:00:00 2001 From: Malcolm Lalkaka Date: Mon, 10 Jun 2019 18:54:49 -0700 Subject: [PATCH 1/2] Fix and greatly simplify the example app Perhaps there's something I'm misunderstanding here, but from what I tell, the example app in this repo has been abandoned, and doesn't actually work anymore. There are synax errors that cause it to fail at runtime, due to the use of `import` in index.html. Furthermore, there is a preload.js script that contains the same code that is in the index.html file, but that preload.js file isn't being specified when creating the `BrowserWindow` in main.js. This change fixes these issues, and in doing so, it greatly simplifies the example app. --- example/index.html | 47 ++-------------------------------------------- example/main.js | 6 +++++- example/preload.js | 24 ++++++++++++++--------- 3 files changed, 22 insertions(+), 55 deletions(-) diff --git a/example/index.html b/example/index.html index b7b6ca2..d1bfbe9 100644 --- a/example/index.html +++ b/example/index.html @@ -1,52 +1,9 @@ - -
- - - > - -
-

Type some text!

-

Unknown language

- -
+
+
- - diff --git a/example/main.js b/example/main.js index 91bef63..a01894b 100644 --- a/example/main.js +++ b/example/main.js @@ -1,5 +1,6 @@ const {app, BrowserWindow } = require('electron'); const electronDebug = require('electron-debug'); +const path = require('path'); let mainWindow = null; electronDebug({enabled: true, showDevTools: true}); @@ -11,7 +12,10 @@ app.on('window-all-closed', () => { app.on('ready', () => { mainWindow = new BrowserWindow({ width: 580, - height: 365 + height: 365, + webPreferences: { + preload: path.join(__dirname, 'preload.js') + } }); mainWindow.loadURL(`file://${__dirname}/index.html`); diff --git a/example/preload.js b/example/preload.js index f8e73d5..9540202 100644 --- a/example/preload.js +++ b/example/preload.js @@ -1,14 +1,20 @@ -window.ItWorked = true; - -const SpellCheckHandler = require('../lib/spell-check-handler').default; -const ContextMenuListener = require('../lib/context-menu-listener').default; -const ContextMenuBuilder = require('../lib/context-menu-builder').default; +const SpellCheckHandler = require("../src/spell-check-handler"); +const ContextMenuListener = require("../src/context-menu-listener"); +const ContextMenuBuilder = require("../src/context-menu-builder"); window.spellCheckHandler = new SpellCheckHandler(); -setTimeout(() => window.spellCheckHandler.attachToInput(), 1000); +window.spellCheckHandler.attachToInput(); -window.spellCheckHandler.provideHintText('This is probably the language that you want to check in'); +window.spellCheckHandler.provideHintText( + "This is probably the language that you want to check in" +); window.spellCheckHandler.autoUnloadDictionariesOnBlur(); -window.contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true); -window.contextMenuListener = new ContextMenuListener((info) => { window.contextMenuBuilder.showPopupMenu(info); }); +window.contextMenuBuilder = new ContextMenuBuilder( + window.spellCheckHandler, + null, + true +); +window.contextMenuListener = new ContextMenuListener(info => { + window.contextMenuBuilder.showPopupMenu(info); +}); From 174ac0f8823b781df39f3ec526661b3200ac6394 Mon Sep 17 00:00:00 2001 From: Malcolm Lalkaka Date: Tue, 11 Jun 2019 15:14:47 -0700 Subject: [PATCH 2/2] Call attachToInput from setTimeout We need to wait for document.body to become available before calling `attachToInput`. Calling from `setTimeout` accomplishes that. --- example/preload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/preload.js b/example/preload.js index 9540202..5b59390 100644 --- a/example/preload.js +++ b/example/preload.js @@ -3,7 +3,7 @@ const ContextMenuListener = require("../src/context-menu-listener"); const ContextMenuBuilder = require("../src/context-menu-builder"); window.spellCheckHandler = new SpellCheckHandler(); -window.spellCheckHandler.attachToInput(); +setTimeout(() => window.spellCheckHandler.attachToInput(), 1000); window.spellCheckHandler.provideHintText( "This is probably the language that you want to check in"