Skip to content

Instantly share code, notes, and snippets.

@MrStahlfelge
Last active July 28, 2019 09:21
Show Gist options
  • Select an option

  • Save MrStahlfelge/01838a23ba719fefbde1dcc249b9fe9d to your computer and use it in GitHub Desktop.

Select an option

Save MrStahlfelge/01838a23ba719fefbde1dcc249b9fe9d to your computer and use it in GitHub Desktop.
libGDX Electron template #1
const {app, BrowserWindow, Menu} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow () {
// Create the browser window.
Menu.setApplicationMenu(null)
win = new BrowserWindow({
width: 800,
height: 600,
//minWidth/minHeight are supported as well
// hide title bar on MacOS, don't do anything on Windows and Unix
titleBarStyle: 'hidden',
// this would hide the titlebar on all OS
//frame: false,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadFile('index.html')
// use this for superdev mode, and opening the DevTools.
//win.loadURL('http://localhost:8080/html')
//win.webContents.openDevTools()
// open new windows in default OS browser
win.webContents.on('new-window', function(event, url){
var shell = require('electron').shell;
event.preventDefault();
shell.openExternal(url);
});
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS 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', () => {
// On macOS 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 (win === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
{
"name": "template",
"version": "0.0.1",
"description": "libGDX Electron template file",
"main": "main.js",
"author": "MrStahlfelge",
"license": "ISC",
"devDependencies": {
"electron": "^5.0.6"
},
"scripts": {
"start": "electron .",
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
"package-win": "electron-packager . --overwrite --asar --platform=win32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Electron Template App\"",
"package-linux": "electron-packager . --overwrite --asar --platform=linux --arch=x64 --icon=assets/icons/png/1024x1024.png --prune=true --out=release-builds"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment