Skip to content

Commit

Permalink
Update demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
tong committed May 24, 2024
1 parent ce75198 commit 1c0a69c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 76 deletions.
41 changes: 18 additions & 23 deletions demo/App.hx
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@

import js.Browser.console;
import js.Browser.document;
import js.Browser.window;
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); */
}
}
}
83 changes: 38 additions & 45 deletions demo/Main.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import electron.main.App;
import electron.main.BrowserWindow;
import js.Node.__dirname;
Expand All @@ -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();
});
}

}
14 changes: 7 additions & 7 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"start": "electron ."
},
"devDependencies": {
"electron": "v30.0.1"
"electron": "v30.0.8"
}
}

0 comments on commit 1c0a69c

Please sign in to comment.