Skip to content

Commit ac0b28f

Browse files
committed
add loop feature on update_status function that wait until status changes
1 parent 48bd81e commit ac0b28f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

xampp-indicator.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def start_stop_xampp(self, widget):
198198
else:
199199
widget.set_label('Starting...')
200200
self.start_service()
201-
# Update Status after 10 seconds
202-
GLib.timeout_add_seconds(10, self.update_status, widget)
201+
# Update Status after 5 seconds
202+
GLib.timeout_add_seconds(5, self.update_status, widget, None, None, True)
203203

204204
def restart_xampp(self, widget):
205205
# Disable Start/Stop & Services Menu Items
@@ -236,8 +236,9 @@ def toggle_service(self, widget, service):
236236
# Update Status after 10 seconds
237237
GLib.timeout_add_seconds(10, self.update_status, widget, label, service)
238238

239-
def update_status(self, widget, widget_label = None, service = None):
239+
def update_status(self, widget, widget_label = None, service = None, loop = False):
240240
# Update Xampp Status
241+
old_status = self.status
241242
self.status = self.get_xampp_status()
242243
if service is not None:
243244
# Update Widget
@@ -272,8 +273,18 @@ def update_status(self, widget, widget_label = None, service = None):
272273
self.startStopItem.set_label('Start')
273274
self.startStopItem.set_sensitive(True)
274275
self.restartItem.set_sensitive(False)
276+
# Check if status changed
277+
if not loop or self.status_changed(old_status):
278+
return False # Do not loop
279+
else:
280+
return True # Loop
281+
282+
def status_changed(self, old_status):
283+
for service in self.services:
284+
if self.status[service] != old_status[service]:
285+
return True
275286

276-
return False # Do not loop
287+
return False
277288

278289
def start_service(self, service_name = ''):
279290
subprocess.Popen(self.pkexec_args + [self.xampp_bin, 'start' + service_name])

0 commit comments

Comments
 (0)