clan_cli: Simplify ClanURI

This commit is contained in:
Qubasa
2024-03-07 19:04:48 +07:00
parent e640e0d7c3
commit bda7701861
9 changed files with 123 additions and 47 deletions

View File

@@ -62,8 +62,8 @@ class JoinList:
cls._instance = cls.__new__(cls)
cls.list_store = Gio.ListStore.new(JoinValue)
# Rerendering the join list every time an item changes in the clan_store
ClanStore.use().register_on_deep_change(cls._instance._rerender_join_list)
return cls._instance
def _rerender_join_list(
@@ -83,7 +83,9 @@ class JoinList:
"""
value = JoinValue(uri)
if value.url.get_id() in [item.url.get_id() for item in self.list_store]:
if value.url.machine.get_id() in [
item.url.machine.get_id() for item in self.list_store
]:
log.info(f"Join request already exists: {value.url}. Ignoring.")
return

View File

@@ -57,7 +57,7 @@ class ClanStore:
store: "GKVStore", position: int, removed: int, added: int
) -> None:
if added > 0:
store.register_on_change(on_vmstore_change)
store.values()[position].register_on_change(on_vmstore_change)
callback(store, position, removed, added)
self.clan_store.register_on_change(on_clanstore_change)
@@ -111,10 +111,11 @@ class ClanStore:
del self.clan_store[vm.data.flake.flake_url][vm.data.flake.flake_attr]
def get_vm(self, uri: ClanURI) -> None | VMObject:
clan = self.clan_store.get(uri.get_internal())
if clan is None:
vm_store = self.clan_store.get(str(uri.url))
if vm_store is None:
return None
return clan.get(uri.params.flake_attr, None)
machine = vm_store.get(uri.machine.name, None)
return machine
def get_running_vms(self) -> list[VMObject]:
return [