Files
GDevelop/GDJS/Runtime/Electron/main.js
T
Florian Rival 252eeb86b1 Upgrade the underlying runtime running the desktop app, and exported desktop games, to Electron 18 (#3806) (#3854)
* This brings improved performance and compatibility for the desktop app with Windows, macOS and Linux.
* In particular, tilemap performance should be greatly improved both in the scene editor, the preview and exported games on Linux.
* This should also improve performance of both the editor and games on macOS when running on Apple Silicon (M1 cpus).
* Thanks to @nilaymajorwar for the ground work on this upgrade.

Only show the rest in developer changelog:

* More work is needed to isolate the Electron "renderer" process from the "main" process (both for the editor and for games), by using `contextBridge` and preload scripts (https://www.electronjs.org/docs/latest/tutorial/process-model). Your help is welcome to progressively do this migration.

Co-authored-by: Nilay Majorwar <nilaymajorwar@gmail.com>
2022-05-08 17:24:49 +02:00

66 lines
2.1 KiB
JavaScript

/**
* This is the file handling the startup and lifetime of the game
* running in Electron Runtime.
*/
// Modules to control application life and create native browser window
const { app, BrowserWindow, shell, Menu } = require("electron");
// Initialize `@electron/remote` module
require('@electron/remote/main').initialize();
// 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 mainWindow = null;
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800 /*GDJS_WINDOW_WIDTH*/,
height: 600 /*GDJS_WINDOW_HEIGHT*/,
useContentSize: true,
title: "GDJS_GAME_NAME",
backgroundColor: '#000000',
webPreferences: {
// Allow Node.js API access in renderer process, as long
// as we've not removed dependency on it and on "@electron/remote".
nodeIntegration: true,
contextIsolation: false,
}
});
// Enable `@electron/remote` module for renderer process
require('@electron/remote/main').enable(mainWindow.webContents);
// Open external link in the OS default browser
mainWindow.webContents.setWindowOpenHandler(details => {
shell.openExternal(details.url);
return { action: 'deny' };
});
// and load the index.html of the app.
mainWindow.loadFile("app/index.html");
Menu.setApplicationMenu(null);
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on("closed", function() {
// 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.
mainWindow = 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", function() {
app.quit();
});