diff --git a/README.md b/README.md index 2d9a780..9db7c13 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,16 @@ Grab it from the Chrome Store: https://chrome.google.com/webstore/detail/hoverpa 1. Go to ``chrome://extensions`` 2. Tick the Developer Mode 3. Load the hoverpad repository folder. + +## Desktop app + +Using [Electron](http://electron.atom.io/), you can run the hoverpad as an +application on your desktop. + +First install electron: + + npm install -g electron + +Then run the application: + + electron electron.js diff --git a/electron.js b/electron.js new file mode 100644 index 0000000..91883c3 --- /dev/null +++ b/electron.js @@ -0,0 +1,39 @@ +'use strict' +const electron = require('electron') + +const app = electron.app // this is our app +const BrowserWindow = electron.BrowserWindow // This is a Module that creates windows + +let mainWindow // saves a global reference to mainWindow so it doesn't get garbage collected + +app.on('ready', createWindow) // called when electron has initialized + +// This will create our app window, no surprise there +function createWindow () { + mainWindow = new BrowserWindow({ + width: 1024, + height: 768 + }) + + // display the index.html file + mainWindow.loadURL(`file://${ __dirname }/index.html`) + + // open dev tools by default so we can see any console errors + //mainWindow.webContents.openDevTools() + + mainWindow.on('closed', function () { + mainWindow = null + }) +} + +/* Mac Specific things */ + +// when you close all the windows on a non-mac OS it quits the app +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { app.quit() } +}) + +// if there is no mainWindow it creates one (like when you click the dock icon) +app.on('activate', () => { + if (mainWindow === null) { createWindow() } +}) diff --git a/package.json b/package.json index 5cb3307..12c1db7 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "debug": "elm-live Main.elm --output=hoverpad.js --open -- --debug", "live": "elm-live Main.elm --output=hoverpad.js --open", "fx-web-ext": "web-ext build", + "electron": "electron electron.js", "publish-to-gh-pages": "mkdir -p dist && cp -r index.html *.js *.css icons dist && gh-pages --dist ./dist" }, "repository": { @@ -23,6 +24,7 @@ "elm": "^0.18.0", "elm-live": "^2.6.1", "web-ext": "^1.7.0", - "gh-pages": "^0.11.0" + "gh-pages": "^0.11.0", + "electron": "1.4.15" } } diff --git a/ports.js b/ports.js index 29c1f98..bc3bff9 100644 --- a/ports.js +++ b/ports.js @@ -1,6 +1,13 @@ const KEY_PREFIX = "hoverpad"; var credentials; -var app = Elm.Main.fullscreen(); +var app; +if (typeof(Elm) === "undefined") { + // This happens if we're in the context of Electron. + const Elm = require('./hoverpad.js'); + app = Elm.Main.fullscreen(); +} else { + app = Elm.Main.fullscreen(); +} function placeCaretAtEnd(el) { return function() {