Repository navigation
Expand file tree
/
Copy pathstate.py
More file actions
65 lines (55 loc) · 1.91 KB
/
Copy pathstate.py
File metadata and controls
65 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from history import (
load_history,
load_git_remote_cache,
load_ignored_workspaces,
load_recent_hosts,
load_vpn_path,
load_config_editor,
load_workspace_metadata,
)
from ssh_client import (
SSHClient,
load_ssh_hosts,
)
from bridge import frontend
class AppState:
def __init__(self):
self.history = load_history()
self.git_remote_cache = load_git_remote_cache()
self.workspace_metadata = load_workspace_metadata()
self.ignored_workspaces = load_ignored_workspaces()
self.recent_hosts = load_recent_hosts()
self.ssh_hosts = load_ssh_hosts()
self.vpn_path = load_vpn_path()
self.config_editor = load_config_editor()
self.ssh = SSHClient(
schedule=self._schedule,
on_output=self._on_output,
on_feed=self._on_feed,
on_connected=self._on_connected,
on_disconnected=self._on_disconnected,
on_cwd=self._on_cwd,
on_session_state=self._on_session_state,
)
def _schedule(self, fn):
# SSH callbacks can arrive from worker threads. The frontend bridge
# handles marshaling updates into the pywebview window safely.
try:
fn()
except Exception as e:
print(f"Error in schedule: {e}")
def _on_output(self, text, tag):
frontend.call("term_append", text, tag)
def _on_feed(self, chunk):
frontend.feed(chunk)
def _on_connected(self):
self._on_session_state("connected")
frontend.call("on_ssh_connected", self.ssh.current_host or "")
def _on_disconnected(self):
self._on_session_state("disconnected")
frontend.call("on_ssh_disconnected")
def _on_session_state(self, state: str):
frontend.call("ssh_session_state", state)
def _on_cwd(self, path):
frontend.call("update_cwd", path)
app_state = AppState()