Skip to content

Commit

Permalink
webui: allow to kill blivet-gui with Cancel button
Browse files Browse the repository at this point in the history
Can be useful if blivet gui window is hidden / lost by accident.
  • Loading branch information
rvykydal committed Aug 31, 2023
1 parent c2cb74c commit 3db5a23
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions ui/webui/src/components/storage/InstallationMethod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,33 @@ const ModifyStorageButton = ({ isBootIso, onModifyStorage }) => {
);
};

const startBlivet = (onStart, onFinished, errorHandler) => {
const startBlivet = (onStart, onFinished, errorHandler, blivetProcessRef) => {
console.log("Spawning Blivet.");
cockpit.spawn(["blivet-gui"], { err: "message" })
.then(() => {
blivetProcessRef.current = cockpit.spawn(["blivet-gui"], { err: "message" })
.then((process) => {
console.log("Blivet exited.");
blivetProcessRef.current = null;
return onFinished();
})
.catch(errorHandler);
.catch((message) => { blivetProcessRef.current ? errorHandler(message) : console.log("Blivet exited with error", message) });
onStart();
};

const stopBlivet = (onClose, onStopped, errorHandler, blivetProcessRef) => {
if (blivetProcessRef.current) {
console.log("Stopping Blivet");
blivetProcessRef.current = null;
cockpit.spawn(["killall", "blivet-gui"], { err: "message" })
.then(() => {
console.log("Blivet stopped.");
return onStopped();
})
.catch(errorHandler);
} else {
onClose();
}
};

const StorageModifiedModal = ({ onClose, onRescan }) => {
return (
<Modal
Expand Down Expand Up @@ -516,6 +532,8 @@ const ModifyStorageModal = ({ onClose, onToolFinished, errorHandler }) => {
const [toolIsRunning, setToolIsRunning] = useState(false);
const onStart = () => setToolIsRunning(true);
const onFinished = () => { setToolIsRunning(false); onToolFinished() };
const onStopped = onFinished;
const blivetProcessRef = useRef();
return (
<Modal
id="modify-storage-modal"
Expand All @@ -530,7 +548,8 @@ const ModifyStorageModal = ({ onClose, onToolFinished, errorHandler }) => {
onClick={() => startBlivet(
onStart,
onFinished,
errorHandler
errorHandler,
blivetProcessRef
)}
icon={toolIsRunning ? null : <ExternalLinkAltIcon />}
isLoading={toolIsRunning}
Expand All @@ -541,10 +560,14 @@ const ModifyStorageModal = ({ onClose, onToolFinished, errorHandler }) => {
</Button>
<Button
variant="link"
onClick={() => onClose()}
onClick={() => stopBlivet(
onClose,
onStopped,
errorHandler,
blivetProcessRef
)}
id="modify-storage-modal-cancel-btn"
key="cancel"
isDisabled={toolIsRunning}
>
{_("Cancel")}
</Button>
Expand Down

0 comments on commit 3db5a23

Please sign in to comment.