clan_vm_manager: Fix GLib.idle_add rexecuting the VM push multiple times because of missing GLib.SOURCE_REMOVE
This commit is contained in:
parent
d079bc85a8
commit
5f1191148e
@ -136,14 +136,17 @@ class GKVStore(GObject.GObject, Gio.ListModel, Generic[K, V]):
|
|||||||
# O(1) operation if the key does not exist, O(n) if it does
|
# O(1) operation if the key does not exist, O(n) if it does
|
||||||
def __setitem__(self, key: K, value: V) -> None:
|
def __setitem__(self, key: K, value: V) -> None:
|
||||||
# If the key already exists, remove it O(n)
|
# If the key already exists, remove it O(n)
|
||||||
|
# TODO: We have to check if updating an existing key is working correctly
|
||||||
if key in self._items:
|
if key in self._items:
|
||||||
log.warning("Updating an existing key in GKVStore is O(n)")
|
log.warning("Updating an existing key in GKVStore is O(n)")
|
||||||
del self[key]
|
position = self.keys().index(key)
|
||||||
|
self._items[key] = value
|
||||||
|
self.items_changed(position, 0, 1)
|
||||||
|
else:
|
||||||
# Add the new key-value pair
|
# Add the new key-value pair
|
||||||
|
position = max(len(self._items) - 1, 0)
|
||||||
self._items[key] = value
|
self._items[key] = value
|
||||||
self._items.move_to_end(key)
|
self._items.move_to_end(key)
|
||||||
position = len(self._items) - 1
|
|
||||||
self.items_changed(position, 0, 1)
|
self.items_changed(position, 0, 1)
|
||||||
|
|
||||||
# O(n) operation
|
# O(n) operation
|
||||||
|
@ -35,7 +35,7 @@ class JoinValue(GObject.Object):
|
|||||||
|
|
||||||
def __join(self) -> None:
|
def __join(self) -> None:
|
||||||
add_history(self.url, all_machines=False)
|
add_history(self.url, all_machines=False)
|
||||||
GLib.idle_add(lambda: self.emit("join_finished", self))
|
GLib.idle_add(self.emit, "join_finished", self)
|
||||||
|
|
||||||
def join(self) -> None:
|
def join(self) -> None:
|
||||||
threading.Thread(target=self.__join).start()
|
threading.Thread(target=self.__join).start()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -19,6 +19,8 @@ from gi.repository import Adw, Gio, GLib, Gtk
|
|||||||
|
|
||||||
from ..trayicon import TrayIcon
|
from ..trayicon import TrayIcon
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(Adw.ApplicationWindow):
|
class MainWindow(Adw.ApplicationWindow):
|
||||||
def __init__(self, config: ClanConfig) -> None:
|
def __init__(self, config: ClanConfig) -> None:
|
||||||
@ -59,6 +61,10 @@ class MainWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
self.connect("destroy", self.on_destroy)
|
self.connect("destroy", self.on_destroy)
|
||||||
|
|
||||||
|
def push_vm(self, vm: VM) -> bool:
|
||||||
|
VMs.use().push(vm)
|
||||||
|
return GLib.SOURCE_REMOVE
|
||||||
|
|
||||||
def _populate_vms(self) -> None:
|
def _populate_vms(self) -> None:
|
||||||
# Execute `clan flakes add <path>` to democlan for this to work
|
# Execute `clan flakes add <path>` to democlan for this to work
|
||||||
# TODO: Make list_history a generator function
|
# TODO: Make list_history a generator function
|
||||||
@ -72,7 +78,7 @@ class MainWindow(Adw.ApplicationWindow):
|
|||||||
icon=Path(icon),
|
icon=Path(icon),
|
||||||
data=entry,
|
data=entry,
|
||||||
)
|
)
|
||||||
GLib.idle_add(lambda: VMs.use().push(vm))
|
GLib.idle_add(self.push_vm, vm)
|
||||||
|
|
||||||
def on_destroy(self, *_args: Any) -> None:
|
def on_destroy(self, *_args: Any) -> None:
|
||||||
self.tray_icon.destroy()
|
self.tray_icon.destroy()
|
||||||
|
Loading…
Reference in New Issue
Block a user