From de9ab3e5593a9ba94c51c8358df86d8ef51bab20 Mon Sep 17 00:00:00 2001 From: Alice Brooks Date: Thu, 11 Jul 2024 13:32:58 +0100 Subject: [PATCH] tuned: Rework logic to gracefully to handle the service starting Previously starting the service would lead to a server disconnected message, these changes allow us to instead fully wait until the service has started before showing the profile selection, meaning we no longer encounter that error --- pkg/systemd/overview-cards/tuned-dialog.jsx | 77 ++++++++++++++++++--- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/pkg/systemd/overview-cards/tuned-dialog.jsx b/pkg/systemd/overview-cards/tuned-dialog.jsx index fc019d6dbcfb..ced25a905e5e 100644 --- a/pkg/systemd/overview-cards/tuned-dialog.jsx +++ b/pkg/systemd/overview-cards/tuned-dialog.jsx @@ -41,6 +41,7 @@ export const TunedPerformanceProfile = () => { const [btnText, setBtnText] = useState(); const [state, setState] = useState(); const [status, setStatus] = useState(); + const [openDialog, setOpenDialog] = useState(false); const tunedService = useObject(() => service.proxy("tuned.service"), null, @@ -105,11 +106,32 @@ export const TunedPerformanceProfile = () => { updateButton(); }, [updateButton]); - const showDialog = () => { - Dialogs.show(); - }; + const startTuned = useCallback(() => { + tunedService.start() + .then(() => setOpenDialog(true)); + }, [tunedService, setOpenDialog]); + + const showDialog = useCallback(() => { + if (tunedService.state !== "running") { + if (!openDialog) { + Dialogs.show(); + } + } else { + setOpenDialog(false); + if (Dialogs.isActive()) { + Dialogs.close(); + } + Dialogs.show(); + } + }, [updateButton, poll, tuned, tunedService, openDialog, setOpenDialog, Dialogs]); + + useEffect(() => { + if (openDialog) { + showDialog(); + } + }, [openDialog, showDialog]); return ( @@ -124,6 +146,40 @@ export const TunedPerformanceProfile = () => { ); }; +const StartTunedDialog = ({ + startTuned, +}) => { + const [loading, setLoading] = useState(false); + const Dialogs = useDialogs(); + + const startService = () => { + setLoading(true); + startTuned(); + }; + + return ( + + + + + } + > + {loading && } + + ) + +} + const TunedDialog = ({ updateButton, poll, @@ -244,7 +300,7 @@ const TunedDialog = ({ const tunedProfiles = () => { return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles2', []) .then((result) => result[0]) - .catch(ex => { + .catch(() => { return tunedDbus.call('/Tuned', 'com.redhat.tuned.control', 'profiles', []) .then((result) => result[0]); }); @@ -266,11 +322,10 @@ const TunedDialog = ({ .catch(setError); }; - tunedService.start() - .then(updateButton) - .then(withTuned) - .catch(setError) - .finally(() => setLoading(false)); + updateButton() + .then(withTuned) + .catch(setError) + .finally(() => setLoading(false)); }, [updateButton, poll, tunedService, tunedDbus]); const help = (