clan_vm_manager: Fix dynamic join
This commit is contained in:
parent
6f80cee971
commit
c6a2db15a7
@ -4,7 +4,9 @@ from typing import Any, ClassVar
|
|||||||
|
|
||||||
import gi
|
import gi
|
||||||
from clan_cli.clan_uri import ClanURI
|
from clan_cli.clan_uri import ClanURI
|
||||||
from clan_cli.history.add import add_history
|
from clan_cli.history.add import HistoryEntry, add_history
|
||||||
|
|
||||||
|
from clan_vm_manager.models.use_vms import VMs
|
||||||
|
|
||||||
gi.require_version("Gtk", "4.0")
|
gi.require_version("Gtk", "4.0")
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
@ -21,6 +23,7 @@ class JoinValue(GObject.Object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
url: ClanURI
|
url: ClanURI
|
||||||
|
entry: HistoryEntry | None
|
||||||
|
|
||||||
def _join_finished(self) -> bool:
|
def _join_finished(self) -> bool:
|
||||||
self.emit("join_finished", self)
|
self.emit("join_finished", self)
|
||||||
@ -29,9 +32,11 @@ class JoinValue(GObject.Object):
|
|||||||
def __init__(self, url: ClanURI) -> None:
|
def __init__(self, url: ClanURI) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self.entry = None
|
||||||
|
|
||||||
def __join(self) -> None:
|
def __join(self) -> None:
|
||||||
add_history(self.url, all_machines=False)
|
new_entry = add_history(self.url)
|
||||||
|
self.entry = new_entry
|
||||||
GLib.idle_add(self._join_finished)
|
GLib.idle_add(self._join_finished)
|
||||||
|
|
||||||
def join(self) -> None:
|
def join(self) -> None:
|
||||||
@ -79,6 +84,7 @@ class JoinList:
|
|||||||
def _on_join_finished(self, _source: GObject.Object, value: JoinValue) -> None:
|
def _on_join_finished(self, _source: GObject.Object, value: JoinValue) -> None:
|
||||||
log.info(f"Join finished: {value.url}")
|
log.info(f"Join finished: {value.url}")
|
||||||
self.discard(value)
|
self.discard(value)
|
||||||
|
VMs.use().push_history_entry(value.entry)
|
||||||
|
|
||||||
def discard(self, value: JoinValue) -> None:
|
def discard(self, value: JoinValue) -> None:
|
||||||
(has, idx) = self.list_store.find(value)
|
(has, idx) = self.list_store.find(value)
|
||||||
|
@ -18,6 +18,8 @@ from clan_cli.errors import ClanError
|
|||||||
from clan_cli.history.add import HistoryEntry
|
from clan_cli.history.add import HistoryEntry
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
|
|
||||||
|
from clan_vm_manager import assets
|
||||||
|
|
||||||
from .executor import MPProcess, spawn
|
from .executor import MPProcess, spawn
|
||||||
from .gkvstore import GKVStore
|
from .gkvstore import GKVStore
|
||||||
|
|
||||||
@ -342,6 +344,22 @@ class VMs:
|
|||||||
def clan_store(self) -> GKVStore[str, VMStore]:
|
def clan_store(self) -> GKVStore[str, VMStore]:
|
||||||
return self._clan_store
|
return self._clan_store
|
||||||
|
|
||||||
|
def create_vm_task(self, vm: HistoryEntry) -> bool:
|
||||||
|
self.push_history_entry(vm)
|
||||||
|
return GLib.SOURCE_REMOVE
|
||||||
|
|
||||||
|
def push_history_entry(self, entry: HistoryEntry) -> None:
|
||||||
|
if entry.flake.icon is None:
|
||||||
|
icon = assets.loc / "placeholder.jpeg"
|
||||||
|
else:
|
||||||
|
icon = entry.flake.icon
|
||||||
|
|
||||||
|
vm = VM(
|
||||||
|
icon=Path(icon),
|
||||||
|
data=entry,
|
||||||
|
)
|
||||||
|
self.push(vm)
|
||||||
|
|
||||||
def push(self, vm: VM) -> None:
|
def push(self, vm: VM) -> None:
|
||||||
url = vm.data.flake.flake_url
|
url = vm.data.flake.flake_url
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ class ClanList(Gtk.Box):
|
|||||||
log.debug("Join request: %s", url)
|
log.debug("Join request: %s", url)
|
||||||
clan_uri = ClanURI.from_str(url)
|
clan_uri = ClanURI.from_str(url)
|
||||||
value = JoinValue(url=clan_uri)
|
value = JoinValue(url=clan_uri)
|
||||||
value.connect("join_finished", self.on_after_join)
|
|
||||||
JoinList.use().push(value)
|
JoinList.use().push(value)
|
||||||
|
value.connect("join_finished", self.on_after_join)
|
||||||
|
|
||||||
def on_after_join(self, source: JoinValue, item: JoinValue) -> None:
|
def on_after_join(self, source: JoinValue, item: JoinValue) -> None:
|
||||||
# If the join request list is empty disable the shadow artefact
|
# If the join request list is empty disable the shadow artefact
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
from clan_cli.history.list import list_history
|
from clan_cli.history.list import list_history
|
||||||
|
|
||||||
from clan_vm_manager import assets
|
|
||||||
from clan_vm_manager.models.interfaces import ClanConfig
|
from clan_vm_manager.models.interfaces import ClanConfig
|
||||||
from clan_vm_manager.models.use_views import Views
|
from clan_vm_manager.models.use_views import Views
|
||||||
from clan_vm_manager.models.use_vms import VM, VMs
|
from clan_vm_manager.models.use_vms import VMs
|
||||||
from clan_vm_manager.views.details import Details
|
from clan_vm_manager.views.details import Details
|
||||||
from clan_vm_manager.views.list import ClanList
|
from clan_vm_manager.views.list import ClanList
|
||||||
|
|
||||||
@ -61,24 +59,11 @@ 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
|
||||||
for entry in list_history():
|
for entry in list_history():
|
||||||
if entry.flake.icon is None:
|
GLib.idle_add(VMs.use().create_vm_task, entry)
|
||||||
icon = assets.loc / "placeholder.jpeg"
|
|
||||||
else:
|
|
||||||
icon = entry.flake.icon
|
|
||||||
|
|
||||||
vm = VM(
|
|
||||||
icon=Path(icon),
|
|
||||||
data=entry,
|
|
||||||
)
|
|
||||||
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