From e3ff92a394b3182f0e654a6a80a05c0102bb76e9 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Tue, 13 Jan 2015 19:17:37 +0100 Subject: Do not crash if cannot have privileges --- lib/AdminPanel/Module/Services.pm | 56 +++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/AdminPanel/Module/Services.pm b/lib/AdminPanel/Module/Services.pm index 4d099c5..9a35397 100644 --- a/lib/AdminPanel/Module/Services.pm +++ b/lib/AdminPanel/Module/Services.pm @@ -504,37 +504,65 @@ sub _servicePanel { $item = $serviceTbl->changedItem(); if ($item) { yui::YUI::app()->busyCursor(); - $self->sh_services->set_service($item->label(), $item->checked()); - # we can push/pop service, but this (slower) should return real situation + eval { + $self->sh_services->set_service($item->label(), $item->checked()); + }; + my $errors = $@; $self->loadServices(); yui::YUI::app()->normalCursor(); + + if ($errors) { + $self->sh_gui->warningMsgBox({ + title => $self->loc->N($item->checked() ? "Enabling %s" : "Disabling %s", $item->label()), + text => "$errors", + richtext => 1, + }); + $dialog->startMultipleChanges(); + $self->_fillServiceTable($serviceTbl); + $dialog->recalcLayout(); + $dialog->doneMultipleChanges(); + } } } } elsif ($widget == $startButton) { $item = $serviceTbl->selectedItem(); if ($item) { - yui::YUI::app()->busyCursor(); my $serviceName = $item->label(); - $self->sh_services->restart_or_start($serviceName); - # we can push/pop service, but this (slower) should return real situation - $self->_waitUnitStatus($serviceName, 1); -# $self->loadServices(); - $self->_serviceStatus($serviceTbl, $item); + yui::YUI::app()->busyCursor(); + eval { + $self->sh_services->restart_or_start($serviceName); + $self->_waitUnitStatus($serviceName, 1); + }; + my $errors = $@; yui::YUI::app()->normalCursor(); + $self->_serviceStatus($serviceTbl, $item); + + $self->sh_gui->warningMsgBox({ + title => $self->loc->N("Starting %s", $serviceName), + text => "$errors", + richtext => 1, + }) if $errors; } } elsif ($widget == $stopButton) { $item = $serviceTbl->selectedItem(); if ($item) { - yui::YUI::app()->busyCursor(); my $serviceName = $item->label(); - $self->sh_services->stopService($serviceName); - # we can push/pop service, but this (slower) should return real situation - $self->_waitUnitStatus($serviceName, 0); -# $self->loadServices(); - $self->_serviceStatus($serviceTbl, $item); + yui::YUI::app()->busyCursor(); + eval { + $self->sh_services->stopService($serviceName); + $self->_waitUnitStatus($serviceName, 0); + }; + my $errors = $@; yui::YUI::app()->normalCursor(); + $self->_serviceStatus($serviceTbl, $item); + + $self->sh_gui->warningMsgBox({ + title => $self->loc->N("Stopping %s", $serviceName), + text => "$errors", + richtext => 1, + }) if $errors; } } elsif ($widget == $refreshButton) { -- cgit v1.2.1