Skip to content

Commit

Permalink
webui: Launch storage utility via url-handler instead of cockpit.spawn
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
halfline committed Sep 5, 2023
1 parent f6d30ec commit bea7d30
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 3 deletions.
5 changes: 4 additions & 1 deletion anaconda.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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 = *~

Expand Down
21 changes: 21 additions & 0 deletions data/url-handlers/Makefile.am
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

desktopdir = $(datadir)/applications
dist_desktop_DATA = anaconda-storage.desktop

MAINTAINERCLEANFILES = Makefile.in
6 changes: 6 additions & 0 deletions data/url-handlers/anaconda-storage.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=Anaconda Storage
Exec=blivet-gui
Type=Application
MimeType=x-scheme-handler/anaconda-storage;
NoDisplay=true
3 changes: 3 additions & 0 deletions ui/webui/firefox-theme/default/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

3 changes: 3 additions & 0 deletions ui/webui/firefox-theme/live/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

8 changes: 7 additions & 1 deletion ui/webui/src/components/storage/InstallationMethod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ const ModifyStorageButton = ({ isBootIso }) => {
}

return (
<Button variant="link" icon={<WrenchIcon />} onClick={() => cockpit.spawn(["blivet-gui"])}>
<Button variant="link" icon={<WrenchIcon />}
onClick={() => {
const onBeforeUnload = window.onbeforeunload;
window.onbeforeunload = null;
window.location.href = "anaconda-storage:";
window.onbeforeunload = onBeforeUnload;
}}>
{_("Modify storage")}
</Button>
);
Expand Down

0 comments on commit bea7d30

Please sign in to comment.