From bea7d3089e8767beffe0f5e637c45a44838485d4 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sun, 20 Aug 2023 09:56:59 -0400 Subject: [PATCH] webui: Launch storage utility via url-handler instead of cockpit.spawn cockpit.spawn isn't a good command to run UI tools because it doesn't know the user event that lead to it getting called. UI applications need to be run with that sort of context in their environment or compositors won't start them in the foreground. This is so if a user is typing, a slow starting program doesn't steal focus inadvertently when it finally starts. Firefox has a mechanism for launching applications with the appropriate context, however: Url Handlers. This commit registers a url handler "anaconda-storage:" and changes the Web UI to use it instead of cockpit.spawn. --- anaconda.spec.in | 5 ++++- configure.ac | 1 + data/Makefile.am | 2 +- data/url-handlers/Makefile.am | 21 +++++++++++++++++++ data/url-handlers/anaconda-storage.desktop | 6 ++++++ ui/webui/firefox-theme/default/user.js | 3 +++ ui/webui/firefox-theme/live/user.js | 3 +++ .../components/storage/InstallationMethod.jsx | 8 ++++++- 8 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 data/url-handlers/Makefile.am create mode 100644 data/url-handlers/anaconda-storage.desktop diff --git a/anaconda.spec.in b/anaconda.spec.in index bc2c0cf8ed7..1801d1e376f 100644 --- a/anaconda.spec.in +++ b/anaconda.spec.in @@ -351,6 +351,8 @@ mkdir %{buildroot}%{_datadir}/anaconda/addons # Create an empty directory for post-scripts mkdir %{buildroot}%{_datadir}/anaconda/post-scripts +desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{buildroot}%{_datadir}/applications/anaconda-storage.desktop + %if %{with live} # required for live installations desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{buildroot}%{_datadir}/applications/liveinst.desktop @@ -421,7 +423,7 @@ rm -rf \ %{_bindir}/liveinst %{_datadir}/polkit-1/actions/* %{_libexecdir}/liveinst-setup.sh -%{_datadir}/applications/*.desktop +%{_datadir}/applications/liveinst.desktop %{_datadir}/anaconda/gnome %{_sysconfdir}/xdg/autostart/*.desktop @@ -448,6 +450,7 @@ rm -rf \ %dir %{_datadir}/anaconda/firefox-theme/live/chrome %{_datadir}/anaconda/firefox-theme/live/user.js %{_datadir}/anaconda/firefox-theme/live/chrome/userChrome.css +%{_datadir}/applications/anaconda-storage.desktop %{_libexecdir}/webui-desktop %files gui diff --git a/configure.ac b/configure.ac index 4ba03d36ea1..2006838a405 100644 --- a/configure.ac +++ b/configure.ac @@ -111,6 +111,7 @@ AC_CONFIG_FILES([Makefile data/liveinst/gnome/Makefile data/systemd/Makefile data/dbus/Makefile + data/url-handlers/Makefile data/window-manager/Makefile data/window-manager/config/Makefile po/Makefile diff --git a/data/Makefile.am b/data/Makefile.am index df3974fb760..230db9ad28e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -SUBDIRS = command-stubs liveinst systemd pixmaps window-manager dbus conf.d profile.d +SUBDIRS = command-stubs liveinst systemd pixmaps window-manager dbus conf.d profile.d url-handlers CLEANFILES = *~ diff --git a/data/url-handlers/Makefile.am b/data/url-handlers/Makefile.am new file mode 100644 index 00000000000..2fcde61f2c8 --- /dev/null +++ b/data/url-handlers/Makefile.am @@ -0,0 +1,21 @@ +# url-handlers/Makefile.am for anaconda +# +# Copyright (C) 2023 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +desktopdir = $(datadir)/applications +dist_desktop_DATA = anaconda-storage.desktop + +MAINTAINERCLEANFILES = Makefile.in diff --git a/data/url-handlers/anaconda-storage.desktop b/data/url-handlers/anaconda-storage.desktop new file mode 100644 index 00000000000..def6d87ad3c --- /dev/null +++ b/data/url-handlers/anaconda-storage.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=Anaconda Storage +Exec=blivet-gui +Type=Application +MimeType=x-scheme-handler/anaconda-storage; +NoDisplay=true diff --git a/ui/webui/firefox-theme/default/user.js b/ui/webui/firefox-theme/default/user.js index e995bc9e349..9b674604680 100644 --- a/ui/webui/firefox-theme/default/user.js +++ b/ui/webui/firefox-theme/default/user.js @@ -45,3 +45,6 @@ user_pref("datareporting.policy.dataSubmissionEnabled", false); user_pref("toolkit.telemetry.unified", false); user_pref("trailhead.firstrun.didSeeAboutWelcome", true); +// Allow anaconda-storage url handler +user_pref("network.protocol-handler.external.anaconda-storage", true); + diff --git a/ui/webui/firefox-theme/live/user.js b/ui/webui/firefox-theme/live/user.js index e995bc9e349..9b674604680 100644 --- a/ui/webui/firefox-theme/live/user.js +++ b/ui/webui/firefox-theme/live/user.js @@ -45,3 +45,6 @@ user_pref("datareporting.policy.dataSubmissionEnabled", false); user_pref("toolkit.telemetry.unified", false); user_pref("trailhead.firstrun.didSeeAboutWelcome", true); +// Allow anaconda-storage url handler +user_pref("network.protocol-handler.external.anaconda-storage", true); + diff --git a/ui/webui/src/components/storage/InstallationMethod.jsx b/ui/webui/src/components/storage/InstallationMethod.jsx index 42ec832b754..e2c15be3c84 100644 --- a/ui/webui/src/components/storage/InstallationMethod.jsx +++ b/ui/webui/src/components/storage/InstallationMethod.jsx @@ -423,7 +423,13 @@ const ModifyStorageButton = ({ isBootIso }) => { } return ( - );