From 018a750fbc0ef32474c7236c04d68f6960570f3b Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sat, 12 Dec 2020 21:56:35 +0100 Subject: [PATCH 1/4] Add web app for broadway backend --- clapper_src/webapp.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 clapper_src/webapp.js diff --git a/clapper_src/webapp.js b/clapper_src/webapp.js new file mode 100644 index 00000000..3c43933b --- /dev/null +++ b/clapper_src/webapp.js @@ -0,0 +1,36 @@ +const { Gio, GObject } = imports.gi; +const Debug = imports.clapper_src.debug; +const Misc = imports.clapper_src.misc; + +let { debug } = Debug; + +var WebApp = GObject.registerClass( +class ClapperWebApp extends Gio.SubprocessLauncher +{ + _init() + { + const flags = Gio.SubprocessFlags.STDOUT_SILENCE + | Gio.SubprocessFlags.STDERR_SILENCE; + + super._init(flags); + } + + startRemoteApp() + { + this.setenv('GDK_BACKEND', 'broadway', true); + this.setenv('BROADWAY_DISPLAY', '6', true); + + this.remoteApp = this.spawnv(Misc.appId); + this.remoteApp.wait_async(null, this._onRemoteClosed.bind(this)); + + debug('remote app started'); + } + + _onRemoteClosed(remoteApp, res) + { + debug('remote app closed'); + + this.setenv('GDK_BACKEND', '', true); + this.setenv('BROADWAY_DISPLAY', '', true); + } +}); From ea67e1e62014d2f753e0e1aee4feaa62a178a4fc Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Mon, 14 Dec 2020 11:19:12 +0100 Subject: [PATCH 2/4] Flatpak: compile GTK4 with broadway backend --- pkgs/flatpak/lib/gtk4.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/flatpak/lib/gtk4.json b/pkgs/flatpak/lib/gtk4.json index 5f2a38eb..4a8da02a 100644 --- a/pkgs/flatpak/lib/gtk4.json +++ b/pkgs/flatpak/lib/gtk4.json @@ -3,6 +3,7 @@ "buildsystem": "meson", "config-opts": [ "--wrap-mode=nofallback", + "-Dbroadway-backend=true", "-Dwin32-backend=false", "-Dmacos-backend=false", "-Dmedia-ffmpeg=disabled", @@ -10,7 +11,8 @@ "-Dprint-cloudprint=disabled", "-Dintrospection=enabled", "-Ddemos=false", - "-Dbuild-examples=false" + "-Dbuild-examples=false", + "-Dbuild-tests=false" ], "sources": [ { From 062a30761386652b6d7f2d4f887d28bf8b14dd6e Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:51:25 +0100 Subject: [PATCH 3/4] Add stop method for web app --- clapper_src/webapp.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/clapper_src/webapp.js b/clapper_src/webapp.js index 3c43933b..f5dca76f 100644 --- a/clapper_src/webapp.js +++ b/clapper_src/webapp.js @@ -12,25 +12,52 @@ class ClapperWebApp extends Gio.SubprocessLauncher const flags = Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.STDERR_SILENCE; - super._init(flags); + super._init({ flags }); + + this.remoteApp = null; + this.isRemoteClosing = false; + + this.setenv('GDK_BACKEND', 'broadway', true); } startRemoteApp() { - this.setenv('GDK_BACKEND', 'broadway', true); - this.setenv('BROADWAY_DISPLAY', '6', true); + if(this.remoteApp) + return; - this.remoteApp = this.spawnv(Misc.appId); + this.remoteApp = this.spawnv([Misc.appId + 'Remote']); this.remoteApp.wait_async(null, this._onRemoteClosed.bind(this)); debug('remote app started'); } - _onRemoteClosed(remoteApp, res) + stopRemoteApp() { - debug('remote app closed'); + if(!this.remoteApp || this.isRemoteClosing) + return; - this.setenv('GDK_BACKEND', '', true); - this.setenv('BROADWAY_DISPLAY', '', true); + this.isRemoteClosing = true; + this.remoteApp.force_exit(); + + debug('send stop signal to remote app'); + } + + _onRemoteClosed(proc, result) + { + let hadError; + + try { + hadError = proc.wait_finish(result); + } + catch(err) { + debug(err); + } + + this.remoteApp = null; + + if(hadError) + debug('remote app exited with error'); + + debug('remote app closed'); } }); From b756c15e46f3d5ef7e0f9d7d9eb7fdb7417739d5 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:59:05 +0100 Subject: [PATCH 4/4] Fix non-updated closing state --- clapper_src/webapp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/clapper_src/webapp.js b/clapper_src/webapp.js index f5dca76f..e5bd1168 100644 --- a/clapper_src/webapp.js +++ b/clapper_src/webapp.js @@ -54,6 +54,7 @@ class ClapperWebApp extends Gio.SubprocessLauncher } this.remoteApp = null; + this.isRemoteClosing = false; if(hadError) debug('remote app exited with error');