From c1aae76d6e7947078745bbf82249e67e0c9f17a8 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Wed, 16 Dec 2020 21:15:41 +0100 Subject: [PATCH] Customize web app port --- clapper_src/daemon.js | 6 ++++-- clapper_src/mainDaemon.js | 2 +- clapper_src/playerBase.js | 4 +--- clapper_src/prefs.js | 6 ++++-- clapper_src/webApp.js | 17 ++--------------- data/com.github.rafostar.Clapper.gschema.xml | 4 ++++ 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/clapper_src/daemon.js b/clapper_src/daemon.js index ce13a8e3..ed33ea55 100644 --- a/clapper_src/daemon.js +++ b/clapper_src/daemon.js @@ -6,8 +6,10 @@ let { debug } = Debug; var Daemon = GObject.registerClass( class ClapperDaemon extends Gio.SubprocessLauncher { - _init() + _init(port) { + port = port || 8080; + /* FIXME: show output when debugging is on */ const flags = Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.STDERR_SILENCE; @@ -17,7 +19,7 @@ class ClapperDaemon extends Gio.SubprocessLauncher this.errMsg = 'exited with error or was forced to close'; this.loop = GLib.MainLoop.new(null, false); - this.broadwayd = this.spawnv(['gtk4-broadwayd', '--port=8086']); + this.broadwayd = this.spawnv(['gtk4-broadwayd', '--port=' + port]); this.broadwayd.wait_async(null, this._onBroadwaydClosed.bind(this)); this.setenv('GDK_BACKEND', 'broadway', true); diff --git a/clapper_src/mainDaemon.js b/clapper_src/mainDaemon.js index 93302a4e..1f5b096b 100644 --- a/clapper_src/mainDaemon.js +++ b/clapper_src/mainDaemon.js @@ -2,5 +2,5 @@ const { Daemon } = imports.clapper_src.daemon; function main() { - new Daemon(); + new Daemon(ARGV[0]); } diff --git a/clapper_src/playerBase.js b/clapper_src/playerBase.js index 35ccf851..f66a80fc 100644 --- a/clapper_src/playerBase.js +++ b/clapper_src/playerBase.js @@ -296,10 +296,8 @@ class ClapperPlayerBase extends GstPlayer.Player if(!this.webapp) this.webapp = new WebApp(); - this.webapp.startDaemonApp(); + this.webapp.startDaemonApp(settings.get_int('webapp-port')); } - else - this.webapp.stopDaemonApp(); } else if(this.webserver) { /* remote app will close when connection is lost diff --git a/clapper_src/prefs.js b/clapper_src/prefs.js index 5f1e09ec..267322cf 100644 --- a/clapper_src/prefs.js +++ b/clapper_src/prefs.js @@ -119,8 +119,10 @@ class ClapperNetworkPage extends PrefsBase.Grid let webServer = this.addCheckButton('Control player remotely', 'webserver-enabled'); let serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port'); webServer.bind_property('active', serverPort, 'visible', GObject.BindingFlags.SYNC_CREATE); - //let webApp = this.addCheckButton('Run built-in web application', 'webapp-enabled'); - //webServer.bind_property('active', webApp, 'visible', GObject.BindingFlags.SYNC_CREATE); + let webApp = this.addCheckButton('Start built-in web application', 'webapp-enabled'); + webServer.bind_property('active', webApp, 'visible', GObject.BindingFlags.SYNC_CREATE); + let webAppPort = this.addSpinButton('Web application port', 1024, 65535, 'webapp-port'); + webServer.bind_property('active', webAppPort, 'visible', GObject.BindingFlags.SYNC_CREATE); } }); diff --git a/clapper_src/webApp.js b/clapper_src/webApp.js index ff8ef116..68f3e728 100644 --- a/clapper_src/webApp.js +++ b/clapper_src/webApp.js @@ -15,31 +15,19 @@ class ClapperWebApp extends Gio.SubprocessLauncher super._init({ flags }); this.daemonApp = null; - this.isDaemonClosing = false; } - startDaemonApp() + startDaemonApp(port) { if(this.daemonApp) return; - this.daemonApp = this.spawnv([Misc.appId + '.Daemon']); + this.daemonApp = this.spawnv([Misc.appId + '.Daemon', String(port)]); this.daemonApp.wait_async(null, this._onDaemonClosed.bind(this)); debug('daemon app started'); } - stopDaemonApp() - { - if(!this.daemonApp || this.isDaemonClosing) - return; - - this.isDaemonClosing = true; - this.daemonApp.force_exit(); - - debug('send stop signal to daemon app'); - } - _onDaemonClosed(proc, result) { let hadError; @@ -52,7 +40,6 @@ class ClapperWebApp extends Gio.SubprocessLauncher } this.daemonApp = null; - this.isDaemonClosing = false; if(hadError) debug('daemon app exited with error or was forced to close'); diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml index 24a346db..f0789201 100644 --- a/data/com.github.rafostar.Clapper.gschema.xml +++ b/data/com.github.rafostar.Clapper.gschema.xml @@ -62,6 +62,10 @@ false Run built-in broadway based web application + + 8086 + Port for running broadwayd service +