Customize web app port

This commit is contained in:
Rafostar
2020-12-16 21:15:41 +01:00
parent 84762de76a
commit c1aae76d6e
6 changed files with 16 additions and 23 deletions

View File

@@ -6,8 +6,10 @@ let { debug } = Debug;
var Daemon = GObject.registerClass( var Daemon = GObject.registerClass(
class ClapperDaemon extends Gio.SubprocessLauncher class ClapperDaemon extends Gio.SubprocessLauncher
{ {
_init() _init(port)
{ {
port = port || 8080;
/* FIXME: show output when debugging is on */ /* FIXME: show output when debugging is on */
const flags = Gio.SubprocessFlags.STDOUT_SILENCE const flags = Gio.SubprocessFlags.STDOUT_SILENCE
| Gio.SubprocessFlags.STDERR_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.errMsg = 'exited with error or was forced to close';
this.loop = GLib.MainLoop.new(null, false); 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.broadwayd.wait_async(null, this._onBroadwaydClosed.bind(this));
this.setenv('GDK_BACKEND', 'broadway', true); this.setenv('GDK_BACKEND', 'broadway', true);

View File

@@ -2,5 +2,5 @@ const { Daemon } = imports.clapper_src.daemon;
function main() function main()
{ {
new Daemon(); new Daemon(ARGV[0]);
} }

View File

@@ -296,10 +296,8 @@ class ClapperPlayerBase extends GstPlayer.Player
if(!this.webapp) if(!this.webapp)
this.webapp = new WebApp(); this.webapp = new WebApp();
this.webapp.startDaemonApp(); this.webapp.startDaemonApp(settings.get_int('webapp-port'));
} }
else
this.webapp.stopDaemonApp();
} }
else if(this.webserver) { else if(this.webserver) {
/* remote app will close when connection is lost /* remote app will close when connection is lost

View File

@@ -119,8 +119,10 @@ class ClapperNetworkPage extends PrefsBase.Grid
let webServer = this.addCheckButton('Control player remotely', 'webserver-enabled'); let webServer = this.addCheckButton('Control player remotely', 'webserver-enabled');
let serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port'); let serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port');
webServer.bind_property('active', serverPort, 'visible', GObject.BindingFlags.SYNC_CREATE); webServer.bind_property('active', serverPort, 'visible', GObject.BindingFlags.SYNC_CREATE);
//let webApp = this.addCheckButton('Run built-in web application', 'webapp-enabled'); let webApp = this.addCheckButton('Start built-in web application', 'webapp-enabled');
//webServer.bind_property('active', webApp, 'visible', GObject.BindingFlags.SYNC_CREATE); 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);
} }
}); });

View File

@@ -15,31 +15,19 @@ class ClapperWebApp extends Gio.SubprocessLauncher
super._init({ flags }); super._init({ flags });
this.daemonApp = null; this.daemonApp = null;
this.isDaemonClosing = false;
} }
startDaemonApp() startDaemonApp(port)
{ {
if(this.daemonApp) if(this.daemonApp)
return; 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)); this.daemonApp.wait_async(null, this._onDaemonClosed.bind(this));
debug('daemon app started'); 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) _onDaemonClosed(proc, result)
{ {
let hadError; let hadError;
@@ -52,7 +40,6 @@ class ClapperWebApp extends Gio.SubprocessLauncher
} }
this.daemonApp = null; this.daemonApp = null;
this.isDaemonClosing = false;
if(hadError) if(hadError)
debug('daemon app exited with error or was forced to close'); debug('daemon app exited with error or was forced to close');

View File

@@ -62,6 +62,10 @@
<default>false</default> <default>false</default>
<summary>Run built-in broadway based web application</summary> <summary>Run built-in broadway based web application</summary>
</key> </key>
<key name="webapp-port" type="i">
<default>8086</default>
<summary>Port for running broadwayd service</summary>
</key>
<!-- Tweaks --> <!-- Tweaks -->
<key name="dark-theme" type="b"> <key name="dark-theme" type="b">