j
This commit is contained in:
@@ -131,7 +131,7 @@ class ConfigModal(ModalScreen):
|
||||
yield Label("Categories", classes="config-label")
|
||||
with ListView(id="category-list"):
|
||||
yield ListItem(Label("Global Settings"), id="cat-globals")
|
||||
yield ListItem(Label("Networking"), id="cat-networking")
|
||||
yield ListItem(Label("Connectors"), id="cat-networking")
|
||||
yield ListItem(Label("Stores"), id="cat-stores")
|
||||
yield ListItem(Label("Providers"), id="cat-providers")
|
||||
|
||||
@@ -277,10 +277,10 @@ class ConfigModal(ModalScreen):
|
||||
container.mount(Static(f"Error listing ZeroTier networks: {exc}"))
|
||||
|
||||
container.mount(Rule())
|
||||
container.mount(Label("Networking Services", classes="config-label"))
|
||||
container.mount(Label("Connectors", classes="config-label"))
|
||||
net = self.config_data.get("networking", {})
|
||||
if not net:
|
||||
container.mount(Static("No networking services configured."))
|
||||
container.mount(Static("No connectors configured."))
|
||||
else:
|
||||
idx = 0
|
||||
for ntype, conf in net.items():
|
||||
@@ -290,8 +290,21 @@ class ConfigModal(ModalScreen):
|
||||
self._button_id_map[del_id] = ("del", "networking", ntype)
|
||||
idx += 1
|
||||
|
||||
label = ntype
|
||||
if ntype == "zerotier":
|
||||
serve = conf.get("serve", "Unknown")
|
||||
net_id = conf.get("network_id", "Unknown")
|
||||
net_name = net_id
|
||||
try:
|
||||
for ln in local_nets:
|
||||
if ln.id == net_id:
|
||||
net_name = ln.name
|
||||
break
|
||||
except Exception: pass
|
||||
label = f"{serve} ---> {net_name}"
|
||||
|
||||
row = Horizontal(
|
||||
Static(ntype, classes="item-label"),
|
||||
Static(label, classes="item-label"),
|
||||
Button("Edit", id=edit_id),
|
||||
Button("Delete", variant="error", id=del_id),
|
||||
classes="item-row"
|
||||
@@ -395,9 +408,23 @@ class ConfigModal(ModalScreen):
|
||||
# Fetch Networking schema
|
||||
if item_type == "networking":
|
||||
if item_name == "zerotier":
|
||||
from API import zerotier as zt
|
||||
local_net_choices = []
|
||||
try:
|
||||
for n in zt.list_networks():
|
||||
local_net_choices.append((f"{n.name} ({n.id})", n.id))
|
||||
except Exception: pass
|
||||
|
||||
local_store_choices = []
|
||||
for s_type, s_data in self.config_data.get("store", {}).items():
|
||||
for s_name in s_data.keys():
|
||||
local_store_choices.append(s_name)
|
||||
|
||||
schema = [
|
||||
{"key": "api_key", "label": "ZeroTier Central API Token", "default": "", "secret": True},
|
||||
{"key": "network_id", "label": "Network ID to Join", "default": ""},
|
||||
{"key": "network_id", "label": "Network to Share on", "choices": local_net_choices},
|
||||
{"key": "serve", "label": "Local Store to Share", "choices": local_store_choices},
|
||||
{"key": "port", "label": "Port", "default": "999"},
|
||||
{"key": "api_key", "label": "Access Key (API Key)", "default": "", "secret": True},
|
||||
]
|
||||
for f in schema:
|
||||
provider_schema_map[f["key"].upper()] = f
|
||||
@@ -440,10 +467,19 @@ class ConfigModal(ModalScreen):
|
||||
|
||||
if choices:
|
||||
# Select takes a list of (label, value) tuples
|
||||
select_options = [(str(c), str(c)) for c in choices]
|
||||
select_options = []
|
||||
choice_values = []
|
||||
for c in choices:
|
||||
if isinstance(c, tuple) and len(c) == 2:
|
||||
select_options.append((str(c[0]), str(c[1])))
|
||||
choice_values.append(str(c[1]))
|
||||
else:
|
||||
select_options.append((str(c), str(c)))
|
||||
choice_values.append(str(c))
|
||||
|
||||
# If current value not in choices, add it or stay blank
|
||||
current_val = str(v)
|
||||
if current_val not in [str(c) for c in choices]:
|
||||
if current_val not in choice_values:
|
||||
select_options.insert(0, (current_val, current_val))
|
||||
|
||||
sel = Select(select_options, value=current_val, id=inp_id)
|
||||
@@ -475,7 +511,19 @@ class ConfigModal(ModalScreen):
|
||||
self._input_id_map[inp_id] = key
|
||||
|
||||
if choices:
|
||||
select_options = [(str(c), str(c)) for c in choices]
|
||||
select_options = []
|
||||
choice_values = []
|
||||
for c in choices:
|
||||
if isinstance(c, tuple) and len(c) == 2:
|
||||
select_options.append((str(c[0]), str(c[1])))
|
||||
choice_values.append(str(c[1]))
|
||||
else:
|
||||
select_options.append((str(c), str(c)))
|
||||
choice_values.append(str(c))
|
||||
|
||||
if default_val not in choice_values:
|
||||
select_options.insert(0, (default_val, default_val))
|
||||
|
||||
sel = Select(select_options, value=default_val, id=inp_id)
|
||||
container.mount(sel)
|
||||
else:
|
||||
@@ -778,7 +826,12 @@ class ConfigModal(ModalScreen):
|
||||
peer_name = "Unnamed Peer"
|
||||
if isinstance(p.payload, dict):
|
||||
peer_name = p.payload.get("name") or p.payload.get("NAME") or peer_name
|
||||
peer_options.append(f"{p.address} ({peer_name})")
|
||||
|
||||
status_label = ""
|
||||
if p.status_code == 401:
|
||||
status_label = " [Locked/401]"
|
||||
|
||||
peer_options.append(f"{p.address} ({peer_name}){status_label}")
|
||||
|
||||
def on_peer_selected(peer_choice: str):
|
||||
if not peer_choice: return
|
||||
@@ -796,9 +849,12 @@ class ConfigModal(ModalScreen):
|
||||
"PORT": "999",
|
||||
"SERVICE": "remote"
|
||||
}
|
||||
if match and match.service_hint == "hydrus":
|
||||
new_config["SERVICE"] = "hydrus"
|
||||
new_config["PORT"] = "45869"
|
||||
if match:
|
||||
if match.service_hint == "hydrus":
|
||||
new_config["SERVICE"] = "hydrus"
|
||||
new_config["PORT"] = "45869"
|
||||
if match.status_code == 401:
|
||||
self.notify("This peer requires an API Key. Please enter it in the settings panel.", severity="warning")
|
||||
|
||||
store_cfg[new_name] = new_config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user