From 1c0a69ce5db357c8119e41a4dfbde0f7f5ade0d9 Mon Sep 17 00:00:00 2001 From: tong Date: Fri, 24 May 2024 16:59:01 +0200 Subject: [PATCH] Update demo app --- demo/App.hx | 41 +++++++++------------ demo/Main.hx | 83 +++++++++++++++++++----------------------- demo/package-lock.json | 14 +++---- demo/package.json | 2 +- 4 files changed, 64 insertions(+), 76 deletions(-) diff --git a/demo/App.hx b/demo/App.hx index 28fa1637..76554b61 100644 --- a/demo/App.hx +++ b/demo/App.hx @@ -1,4 +1,3 @@ - import js.Browser.console; import js.Browser.document; import js.Browser.window; @@ -6,30 +5,26 @@ import js.Node.process; import js.node.ChildProcess; class App { + static inline function setText(id:String, text:String) { + document.getElementById(id).textContent = text; + } - static inline function setText( id : String, text : String ) { - document.getElementById( id ).textContent = text; - } - - static function main() { + static function main() { + window.onload = () -> { + document.getElementById('logo-haxe').style.opacity = '1'; - window.onload = () -> { + setText('system-version', process.platform + ' ' + process.arch); + setText('node-version', 'node ' + process.version); + setText('electron-version', 'electron ' + process.versions['electron']); - document.getElementById( 'logo-haxe' ).style.opacity = '1'; - - setText( 'system-version', process.platform +' '+ process.arch ); - setText( 'node-version', 'node '+process.version ); - setText( 'electron-version', 'electron '+process.versions['electron'] ); - - ChildProcess.spawn( 'haxe', ['-version'] ).stdout.on( 'data', buf -> { - var version = buf.toString(); - setText( 'haxe-version', 'haxe $version' ); - }); - - /* var menu = new electron.remote.Menu(); - menu.append(new electron.remote.MenuItem({ label: 'XXX'})); - electron.remote.Menu.setApplicationMenu(menu); */ - } - } + ChildProcess.spawn('haxe', ['-version']).stdout.on('data', buf -> { + var version = buf.toString(); + setText('haxe-version', 'haxe $version'); + }); + /* var menu = new electron.remote.Menu(); + menu.append(new electron.remote.MenuItem({ label: 'XXX'})); + electron.remote.Menu.setApplicationMenu(menu); */ + } + } } diff --git a/demo/Main.hx b/demo/Main.hx index c9dd996b..1145f71f 100644 --- a/demo/Main.hx +++ b/demo/Main.hx @@ -1,4 +1,3 @@ - import electron.main.App; import electron.main.BrowserWindow; import js.Node.__dirname; @@ -7,70 +6,64 @@ import js.Node.process; using StringTools; class Main { - static function main() { + var timeout = -1; + var args = process.argv; + var lastArg = args[args.length - 1]; + if (lastArg.startsWith("--timeout=")) { + timeout = Std.parseInt(lastArg.split("=")[1]); + } - var timeout = -1; - var args = process.argv; - var lastArg = args[args.length-1]; - if(lastArg.startsWith("--timeout=")) { - timeout = Std.parseInt(lastArg.split("=")[1]); - } - - Sys.println( process.platform +' '+ process.arch ); - Sys.println( 'node '+process.version ); - Sys.println( 'electron '+process.versions['electron'] ); + Sys.println(process.platform + ' ' + process.arch); + Sys.println('node ' + process.version); + Sys.println('electron ' + process.versions['electron']); electron.main.App.whenReady().then(_ -> { - - var win = new BrowserWindow( { - width: 720, height: 480, + var win = new BrowserWindow({ webPreferences: { nodeIntegration: true, contextIsolation: false } - } ); - win.on( "closed", () -> { + }); + win.on("closed", () -> { win = null; }); - win.on( "move", () -> { - trace('Window move'); - }); - win.on( "resize", () -> { - trace('Window resize'); - }); - win.loadFile( 'app.html' ); - //win.webContents.openDevTools(); + win.on("move", () -> { + trace('Window move'); + }); + win.on("resize", () -> { + trace('Window resize'); + }); + win.loadFile('app.html'); + // win.webContents.openDevTools(); - var tray = new electron.main.Tray( '${__dirname}/icon-192.png' ); + var tray = new electron.main.Tray('${__dirname}/icon-192.png'); tray.setToolTip('Haxelectron'); // var dialog = new electron.main.Dialog(); // electron.main.Dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] }); - var menu : electron.main.Menu = electron.main.Menu.getApplicationMenu(); - menu.append(new electron.main.MenuItem( - { - label: 'Haxe', - submenu: [ - { label: 'Website', click: e -> win.loadURL('https://haxe.org') }, - { label: 'Github', click: e -> win.loadURL('https://github.com/HaxeFoundation') } - ] - } - )); + var menu:electron.main.Menu = electron.main.Menu.getApplicationMenu(); + menu.append(new electron.main.MenuItem({ + label: 'Haxe', + submenu: [ + {label: 'Website', click: e -> win.loadURL('https://haxe.org')}, + {label: 'Github', click: e -> win.loadURL('https://github.com/HaxeFoundation')} + ] + })); electron.main.Menu.setApplicationMenu(menu); - if(timeout > 0) { - trace('Auto closing application in $timeout seconds ...'); - haxe.Timer.delay( () -> { - win.close(); - }, timeout*1000 ); - } + if (timeout > 0) { + trace('Auto closing application in $timeout seconds ...'); + haxe.Timer.delay(() -> { + win.close(); + }, timeout * 1000); + } }); - electron.main.App.on( window_all_closed, e -> { - if( process.platform != 'darwin' ) electron.main.App.quit(); + electron.main.App.on(window_all_closed, e -> { + if (process.platform != 'darwin') + electron.main.App.quit(); }); } - } diff --git a/demo/package-lock.json b/demo/package-lock.json index 39f35e06..718266bb 100644 --- a/demo/package-lock.json +++ b/demo/package-lock.json @@ -9,7 +9,7 @@ "version": "0.3.0", "license": "MIT", "devDependencies": { - "electron": "v30.0.1" + "electron": "v30.0.8" } }, "node_modules/@electron/get": { @@ -245,9 +245,9 @@ "optional": true }, "node_modules/electron": { - "version": "30.0.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-30.0.1.tgz", - "integrity": "sha512-iwxkI/n2wBd29NH7TH0ZY8aWGzCoKpzJz+D10u7aGSJi1TV6d4MSM3rWyKvT/UkAHkTKOEgYfUyCa2vWQm8L0g==", + "version": "30.0.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-30.0.8.tgz", + "integrity": "sha512-ivzXJJ/9gdb4oOw+5SDuaZpSInz8C+Z021dKZfFLMltKbDa4sSqt5cRBiUg7J36Z2kdus+Jai0bdHWutYE9wAA==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -997,9 +997,9 @@ "optional": true }, "electron": { - "version": "30.0.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-30.0.1.tgz", - "integrity": "sha512-iwxkI/n2wBd29NH7TH0ZY8aWGzCoKpzJz+D10u7aGSJi1TV6d4MSM3rWyKvT/UkAHkTKOEgYfUyCa2vWQm8L0g==", + "version": "30.0.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-30.0.8.tgz", + "integrity": "sha512-ivzXJJ/9gdb4oOw+5SDuaZpSInz8C+Z021dKZfFLMltKbDa4sSqt5cRBiUg7J36Z2kdus+Jai0bdHWutYE9wAA==", "dev": true, "requires": { "@electron/get": "^2.0.0", diff --git a/demo/package.json b/demo/package.json index 1466d2d0..126ecefa 100644 --- a/demo/package.json +++ b/demo/package.json @@ -13,6 +13,6 @@ "start": "electron ." }, "devDependencies": { - "electron": "v30.0.1" + "electron": "v30.0.8" } }