UI: Fixed toggle button color on second time not changing
All checks were successful
checks-impure / test (pull_request) Successful in 1m23s
checks / test (pull_request) Successful in 2m16s

This commit is contained in:
Luis Hebendanz 2024-01-30 15:02:05 +07:00
parent 45e8917679
commit a3207f7011
2 changed files with 12 additions and 11 deletions

View File

@ -72,13 +72,12 @@ class VM(GObject.Object):
threading.Thread(target=self.__start).start()
if self._watcher_id == 0:
# Every 50ms check if the VM is still running
self._watcher_id = GLib.timeout_add(50, self._vm_watcher_task)
# Every 50ms check if the VM is still running
self._watcher_id = GLib.timeout_add(50, self._vm_watcher_task)
if self._watcher_id == 0:
log.error("Failed to add watcher")
raise ClanError("Failed to add watcher")
if self._watcher_id == 0:
log.error("Failed to add watcher")
raise ClanError("Failed to add watcher")
def _vm_watcher_task(self) -> bool:
if self.is_running() != self._last_liveness:
@ -88,6 +87,7 @@ class VM(GObject.Object):
# If the VM was running and now it is not, remove the watcher
if prev_liveness and not self.is_running():
print("===>Removing watcher")
return GLib.SOURCE_REMOVE
return GLib.SOURCE_CONTINUE

View File

@ -189,8 +189,9 @@ class ClanList(Gtk.Box):
def vm_status_changed(self, switch: Gtk.Switch, vm: VM, _vm: VM) -> None:
switch.set_active(vm.is_running())
switch.set_state(vm.is_running())
if not vm.is_running() and vm.process.proc.exitcode != 0:
print("VM exited with error. Exitcode:", vm.process.proc.exitcode)
# print(vm.read_log())
# self.show_error_dialog(vm.read_log())
print("====> Set switch to", vm.is_running())
exitc = vm.process.proc.exitcode
if not vm.is_running() and exitc != 0 and exitc != -15:
print("VM exited with error. Exitcode:", exitc)
print(vm.read_log())
self.show_error_dialog(vm.read_log())