From d8af65f2fbf6c1222a8742d570b662f99e878db9 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 5 Nov 2024 18:56:11 +0100 Subject: [PATCH] - Add command line switches: "--help", "--url" & "--user". --- ReleaseNotes.txt | 8 +++ main.js | 145 ++++++++++++++++++++++++++++++++++++++++------- package.json | 2 +- 3 files changed, 134 insertions(+), 21 deletions(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index db09b33..02c95ba 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,11 @@ +------------------------------------------------------------------------------------------------------------------------------------ +GuaClient V 1.1.0 - A. GIBERT - 2024/11/05 +------------------------------------------------------------------------------------------------------------------------------------ + +- Add command line switches: "--help", "--url" & "--user". + + + ------------------------------------------------------------------------------------------------------------------------------------ GuaClient V 1.0.0 - A. GIBERT - 2024/11/05 ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/main.js b/main.js index 34d1998..d1543fc 100644 --- a/main.js +++ b/main.js @@ -25,46 +25,151 @@ const electron = require('electron'); const { app, BrowserWindow } = electron; const prompt = require('electron-prompt') +const process = require('process'); + let mainWindow; +let target_url = "https://www.rx3.net/tdsots/admin/guacamole/"; +let target_user = ""; + + + app.on('login', (event, webContents, request, authInfo, callback) => { event.preventDefault(); // popup a dialog to let the user enter a username/password // ... - prompt( - { - title: 'Authentication', - label: 'Enter Login:', - inputAttrs: { type: 'text'}, - type: 'input' - }).then((username) => + if( target_user != "") { prompt( { - title: 'Authentication', - label: 'Enter Password:', + title: 'Authentication', + label: 'Enter Password:', inputAttrs: { type: 'password'}, - type: 'input' - }).then((password) => + type: 'input' + }).then(( password) => + { + callback( target_user, password); + }).catch( console.error); + } + else + { + prompt( { - callback( username, password); - }).catch(console.error); - }).catch(console.error); + title: 'Authentication', + label: 'Enter Login:', + inputAttrs: { type: 'text'}, + type: 'input' + }).then(( username) => + { + + prompt( + { + title: 'Authentication', + label: 'Enter Password:', + inputAttrs: { type: 'password'}, + type: 'input' + }).then(( password) => + { + callback( username, password); + }).catch( console.error); + }).catch( console.error); + } }); app.on('ready', () => { - mainWindow = new BrowserWindow({ + mainWindow = new BrowserWindow( + { width: 1000, height: 700 }); - mainWindow.setTitle('Rx3 Guacamole'); - mainWindow.loadURL('https://www.rx3.net/tdsots/admin/guacamole/'); + + let exit = false; + + for( let i = 2, next = ""; i < process.argv.length; i++) + { + if( next == "") + { + switch( process.argv[ i]) + { + case "--url": + { + next = "URL"; + break; + } - mainWindow.on('closed', () => { - mainWindow = null; - }); + case "--user": + { + next = "USER"; + break; + } + + case "--user": + { + next = "USER"; + break; + } + + case "--help": + { + console.log( "usage: guaclient [--url ] [--user ]"); + console.log( "Defaults: URL: [" + target_url + "] ["+ target_user + "]"); + exit = true; + break; + } + + default: + { + console.log( "Unknown arg: [" + process.argv[i] + "]"); + } + } + } + else + { + switch( next) + { + case "URL": + { + target_url = process.argv[ i]; + break; + } + + case "USER": + { + target_user = process.argv[ i]; + break; + } + + default: + { + console.log( "Erreur interne: [" + next + "]"); + break; + } + } + + next = ""; + } + } + + + if( !exit) + { + console.log( "Connecting [" + target_url + "] with user: [" + target_user + "]"); + + mainWindow.setTitle('Rx3 Guacamole'); + + mainWindow.loadURL( target_url); + + mainWindow.on('closed', () => + { + mainWindow = null; + }); + } + else + { + app.quit(); + } }); diff --git a/package.json b/package.json index 1ab9b38..4055baf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "guaclient", - "version": "1.0.0", + "version": "1.1.0", "description": "Rx3 Guacamole Clinet", "main": "main.js", "scripts": {