If someone needs it, or for future reference, here’s the modified package.json
{
"name": "::meta.packageName::",
"version": "::meta.version::",
"main": "ElectronSetup.js",
"scripts": {
"start": "electron ElectronSetup.js"
},
"devDependencies": {
"electron": "^18.0.0",
"@electron/remote": "^2.0.8"
}
}
So npm install will pull the remote module as well.
And here’s the modified ElectronSetup.hx
package;
class ElectronSetup
{
public static var window:ElectronBrowserWindow;
static function main()
{
ElectronApp.commandLine.appendSwitch('ignore-gpu-blacklist', 'true');
var windows:Array<OpenFLWindow> = [
::foreach windows::
{
allowHighDPI: ::allowHighDPI::,
alwaysOnTop: ::alwaysOnTop::,
antialiasing: ::antialiasing::,
background: ::background::,
borderless: ::borderless::,
colorDepth: ::colorDepth::,
depthBuffer: ::depthBuffer::,
display: ::display::,
fullscreen: ::fullscreen::,
hardware: ::hardware::,
height: ::height::,
hidden: #if munit true #else ::hidden:: #end,
maximized: ::maximized::,
minimized: ::minimized::,
parameters: ::parameters::,
resizable: ::resizable::,
stencilBuffer: ::stencilBuffer::,
title: "::title::",
vsync: ::vsync::,
width: ::width::,
x: ::x::,
y: ::y::
},::end::
];
for (i in 0...windows.length)
{
var window:OpenFLWindow = windows[i];
var width:Int = window.width;
var height:Int = window.height;
if (width == 0) width = 800;
if (height == 0) height = 600;
var frame:Bool = window.borderless == false;
ElectronApp.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required');
ElectronApp.on('ready', function(e)
{
var config:Dynamic =
{
webPreferences:{
nodeIntegration:true,
contextIsolation: false
},
fullscreen: window.fullscreen,
frame: frame,
resizable: window.resizable,
alwaysOnTop: window.alwaysOnTop,
width: width,
height: height,
webgl: window.hardware
};
ElectronSetup.window = new ElectronBrowserWindow(config);
ElectronSetup.window.on('closed', function()
{
if (js.Node.process.platform != 'darwin')
{
ElectronApp.quit();
}
});
ElectronRemoteMain.initialize();
ElectronRemoteMain.enable(ElectronSetup.window.webContents);
ElectronSetup.window.loadURL('file://' + js.Node.__dirname + '/index.html');
#if (debug && !suppress_devtools)
ElectronSetup.window.webContents.openDevTools();
#end
});
}
}
}
typedef OpenFLWindow =
{
allowHighDPI:Bool,
alwaysOnTop:Bool,
antialiasing:Int,
background:UInt,
borderless:Bool,
colorDepth:Int,
depthBuffer:Bool,
display:Dynamic,
fullscreen:Bool,
hardware:Dynamic,
height:Int,
hidden:Bool,
maximized:Bool,
minimized:Bool,
parameters:Dynamic,
resizable:Bool,
stencilBuffer:Bool,
title:String,
vsync:Bool,
width:Int,
x:Int,
y:Int
}
// Externs to compile without requiring hxelectron
@:jsRequire("electron", "app") extern class ElectronApp
{
public static var commandLine:Dynamic;
public static function on(type:Dynamic, callback:Dynamic):Dynamic;
public static function quit():Void;
}
@:jsRequire("electron", "BrowserWindow") extern class ElectronBrowserWindow
{
public var webContents:Dynamic;
public function new(?options:Dynamic);
public function loadURL(url:String, ?options:Dynamic):Dynamic;
public function on(type:Dynamic, callback:Dynamic):Dynamic;
}
@:jsRequire("@electron/remote/main") extern class ElectronRemoteMain {
public static function initialize():Dynamic;
public static function enable(?webContents:Dynamic):Dynamic;
}
the new code is the ElectronRemoteMain extern at the bottom, and
ElectronRemoteMain.initialize();
ElectronRemoteMain.enable(ElectronSetup.window.webContents);
these 2 new lines in static main()