@@ -41,6 +41,7 @@ export const TunedPerformanceProfile = () => {
41
41
const [ btnText , setBtnText ] = useState ( ) ;
42
42
const [ state , setState ] = useState ( ) ;
43
43
const [ status , setStatus ] = useState ( ) ;
44
+ const [ openDialog , setOpenDialog ] = useState ( false ) ;
44
45
45
46
const tunedService = useObject ( ( ) => service . proxy ( "tuned.service" ) ,
46
47
null ,
@@ -105,11 +106,32 @@ export const TunedPerformanceProfile = () => {
105
106
updateButton ( ) ;
106
107
} , [ updateButton ] ) ;
107
108
108
- const showDialog = ( ) => {
109
- Dialogs . show ( < TunedDialog updateButton = { updateButton }
110
- poll = { poll }
111
- tunedDbus = { tuned } tunedService = { tunedService } /> ) ;
112
- } ;
109
+ const startTuned = useCallback ( ( ) => {
110
+ tunedService . start ( )
111
+ . then ( ( ) => setOpenDialog ( true ) ) ;
112
+ } , [ tunedService , setOpenDialog ] ) ;
113
+
114
+ const showDialog = useCallback ( ( ) => {
115
+ if ( tunedService . state !== "running" ) {
116
+ if ( ! openDialog ) {
117
+ Dialogs . show ( < StartTunedDialog startTuned = { startTuned } /> ) ;
118
+ }
119
+ } else {
120
+ setOpenDialog ( false ) ;
121
+ if ( Dialogs . isActive ( ) ) {
122
+ Dialogs . close ( ) ;
123
+ }
124
+ Dialogs . show ( < TunedDialog updateButton = { updateButton }
125
+ poll = { poll }
126
+ tunedDbus = { tuned } tunedService = { tunedService } /> ) ;
127
+ }
128
+ } , [ updateButton , poll , startTuned , tuned , tunedService , openDialog , setOpenDialog , Dialogs ] ) ;
129
+
130
+ useEffect ( ( ) => {
131
+ if ( openDialog ) {
132
+ showDialog ( ) ;
133
+ }
134
+ } , [ openDialog , showDialog ] ) ;
113
135
114
136
return (
115
137
< Tooltip id = "tuned-status-tooltip" content = { status } >
@@ -124,6 +146,39 @@ export const TunedPerformanceProfile = () => {
124
146
) ;
125
147
} ;
126
148
149
+ const StartTunedDialog = ( {
150
+ startTuned,
151
+ } ) => {
152
+ const [ loading , setLoading ] = useState ( false ) ;
153
+ const Dialogs = useDialogs ( ) ;
154
+
155
+ const startService = ( ) => {
156
+ setLoading ( true ) ;
157
+ startTuned ( ) ;
158
+ } ;
159
+
160
+ return (
161
+ < Modal position = "top" variant = "medium"
162
+ className = "ct-m-stretch-body"
163
+ isOpen
164
+ onClose = { Dialogs . close }
165
+ title = { _ ( "Tuned is not running" ) }
166
+ footer = {
167
+ < >
168
+ < Button variant = 'primary' onClick = { startService } >
169
+ { _ ( "Start service" ) }
170
+ </ Button >
171
+ < Button variant = 'link' onClick = { Dialogs . close } >
172
+ { _ ( "Cancel" ) }
173
+ </ Button >
174
+ </ >
175
+ }
176
+ >
177
+ { loading && < EmptyStatePanel loading /> }
178
+ </ Modal >
179
+ ) ;
180
+ } ;
181
+
127
182
const TunedDialog = ( {
128
183
updateButton,
129
184
poll,
@@ -244,7 +299,7 @@ const TunedDialog = ({
244
299
const tunedProfiles = ( ) => {
245
300
return tunedDbus . call ( '/Tuned' , 'com.redhat.tuned.control' , 'profiles2' , [ ] )
246
301
. then ( ( result ) => result [ 0 ] )
247
- . catch ( ex => {
302
+ . catch ( ( ) => {
248
303
return tunedDbus . call ( '/Tuned' , 'com.redhat.tuned.control' , 'profiles' , [ ] )
249
304
. then ( ( result ) => result [ 0 ] ) ;
250
305
} ) ;
@@ -266,8 +321,7 @@ const TunedDialog = ({
266
321
. catch ( setError ) ;
267
322
} ;
268
323
269
- tunedService . start ( )
270
- . then ( updateButton )
324
+ updateButton ( )
271
325
. then ( withTuned )
272
326
. catch ( setError )
273
327
. finally ( ( ) => setLoading ( false ) ) ;
0 commit comments