Created
September 23, 2018 15:12
-
-
Save laurentsenta/36fa6d913dffa1d3218d212e0067056f to your computer and use it in GitHub Desktop.
Electron + create-react-app setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, BrowserWindow} = require("electron") | |
const path = require("path") | |
const isDev = require("electron-is-dev") | |
let mainWindow // prevent main windows to be garbage collected | |
function createWindow() { | |
mainWindow = new BrowserWindow({ | |
frame: false, | |
width: 226, | |
height: 137, | |
skipTaskbar: true, | |
transparent: true, | |
icon: path.join(__dirname, "icons/64x64.png"), | |
}) | |
mainWindow.setAlwaysOnTop(true) | |
mainWindow.setVisibleOnAllWorkspaces(true) | |
if (isDev) { | |
// connect to create-react-app dev server | |
mainWindow.loadURL("http://localhost:3000") | |
} | |
else { | |
// use package build file | |
mainWindow.loadURL(`file://${path.join(__dirname, "../build/index.html")}`) | |
} | |
mainWindow.on("closed", function () { | |
mainWindow = null // release the main windows for garbage collection | |
}) | |
} | |
app.on("ready", createWindow) | |
// Quit when all windows are closed. | |
app.on("window-all-closed", function () { | |
// On OS X it is common for applications and their menu bar | |
// to stay active until the user quits explicitly with Cmd + Q | |
if (process.platform !== "darwin") { | |
app.quit() | |
} | |
}) | |
app.on("activate", function () { | |
// On OS X it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (mainWindow === null) { | |
createWindow() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment