-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathlib.rs
More file actions
257 lines (241 loc) · 9.4 KB
/
Copy pathlib.rs
File metadata and controls
257 lines (241 loc) · 9.4 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
pub mod modules;
use modules::{agent, fs, git, history, lsp, net, pty, secrets, shell, workspace};
use std::sync::Mutex;
use tauri::{Emitter, Manager, State, WebviewUrl, WebviewWindowBuilder};
#[cfg(target_os = "macos")]
use tauri::{PhysicalPosition, WindowEvent};
use tauri_plugin_window_state::StateFlags;
/// Drained on first read so HMR / re-mounts can't replay the launch dir.
#[derive(Default)]
struct LaunchDir(Mutex<Option<String>>);
#[tauri::command]
fn get_launch_dir(state: State<'_, LaunchDir>) -> Option<String> {
state.0.lock().expect("LaunchDir mutex poisoned").take()
}
fn parse_launch_dir() -> Option<String> {
for arg in std::env::args().skip(1) {
if arg.starts_with('-') {
continue;
}
let Ok(canon) = std::fs::canonicalize(&arg) else {
continue;
};
if !canon.is_dir() {
continue;
}
return Some(crate::modules::fs::to_canon(&canon));
}
None
}
#[tauri::command]
async fn open_settings_window(app: tauri::AppHandle, tab: Option<String>) -> Result<(), String> {
let url_path = match tab.as_deref() {
Some(t) if !t.is_empty() => format!("settings.html?tab={}", t),
_ => "settings.html".to_string(),
};
if let Some(window) = app.get_webview_window("settings") {
let _ = window.set_always_on_top(true);
let _ = window.show();
let _ = window.set_focus();
if let Some(t) = tab.as_deref().filter(|s| !s.is_empty()) {
// emit() serializes via JSON — no string-escape footgun, unlike
// eval() with format!(). Frontend listens via Tauri event API.
let _ = window.emit("terax:settings-tab", t);
}
return Ok(());
}
let builder = WebviewWindowBuilder::new(&app, "settings", WebviewUrl::App(url_path.into()))
.title("Settings")
.inner_size(900.0, 700.0)
.min_inner_size(820.0, 620.0)
.resizable(true)
.visible(false)
// Keep settings above the main app window so it doesn't get hidden
// when the user clicks back into the editor or terminal (#33).
.always_on_top(true);
// Tie lifecycle to the main window so settings minimizes/closes with it.
// macOS: skip parent() — child + always_on_top leaves the settings webview
// behind the main window except while the parent is being dragged (#33).
#[cfg(not(target_os = "macos"))]
let builder = if let Some(main) = app.get_webview_window("main") {
builder.parent(&main).map_err(|e| e.to_string())?
} else {
builder
};
#[cfg(target_os = "macos")]
let builder = builder
.title_bar_style(tauri::TitleBarStyle::Overlay)
.hidden_title(true);
// On Linux/Windows we render our own titlebar, so drop native chrome
// and make the window transparent.
#[cfg(any(target_os = "linux", target_os = "windows"))]
let builder = builder.decorations(false).transparent(true);
let window = builder.build().map_err(|e| e.to_string())?;
// Some Linux compositors (GNOME/Mutter with CSD-by-default) ignore the
// builder-time decorations flag — re-assert it after realize.
#[cfg(target_os = "linux")]
{
let _ = window.set_decorations(false);
}
#[cfg(target_os = "macos")]
if let Some(main) = app.get_webview_window("main") {
if let (Ok(main_pos), Ok(main_size), Ok(settings_size)) = (
main.outer_position(),
main.outer_size(),
window.outer_size(),
) {
let x = main_pos.x
+ ((main_size.width as i32).saturating_sub(settings_size.width as i32)) / 2;
let y = main_pos.y
+ ((main_size.height as i32).saturating_sub(settings_size.height as i32)) / 2;
let _ = window.set_position(PhysicalPosition::new(x, y));
} else {
let _ = window.center();
}
}
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let cli_dir = parse_launch_dir();
workspace::init_launch_cwd(cli_dir.as_deref());
tauri::Builder::default()
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_updater::Builder::new().build())
// Skip restoring VISIBLE — frontend calls window.show() after first
// paint so the user never sees a transparent window-shadow flash on
// Windows/Linux.
.plugin(
tauri_plugin_window_state::Builder::new()
.with_state_flags(StateFlags::all() & !StateFlags::VISIBLE)
.build(),
)
.plugin(tauri_plugin_autostart::Builder::new().build())
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_notification::init())
.plugin(
tauri_plugin_log::Builder::new()
.level(tauri_plugin_log::log::LevelFilter::Info)
.build(),
)
.plugin(tauri_plugin_opener::init())
.setup(|app| {
lsp::init(&app.handle());
// macOS skips parent() for the settings window, so tie its lifecycle
// to the main window here instead. Other platforms keep parent().
#[cfg(target_os = "macos")]
if let Some(main) = app.get_webview_window("main") {
let handle = app.handle().clone();
main.on_window_event(move |event| {
if matches!(
event,
WindowEvent::CloseRequested { .. } | WindowEvent::Destroyed
) {
if let Some(settings) = handle.get_webview_window("settings") {
let _ = settings.close();
}
}
});
}
Ok(())
})
.manage(pty::PtyState::default())
.manage(shell::ShellState::default())
.manage(lsp::LspState::default())
.manage(secrets::SecretsState::default())
.manage(fs::watch::FsWatchState::default())
.manage(history::HistoryState::default())
.manage(fs::grep::ContentSearchState::default())
.manage({
let registry = workspace::WorkspaceRegistry::default();
workspace::bootstrap_registry(®istry);
if let Some(ref launch_dir) = cli_dir {
let _ = registry.authorize(launch_dir);
}
registry
})
.manage(LaunchDir(Mutex::new(cli_dir)))
.invoke_handler(tauri::generate_handler![
pty::pty_open,
pty::pty_write,
pty::pty_resize,
pty::pty_close,
pty::pty_close_all,
pty::pty_has_foreground_process,
pty::pty_shell_name,
fs::tree::list_subdirs,
fs::tree::fs_read_dir,
fs::file::fs_read_file,
fs::file::fs_write_file,
fs::file::fs_stat,
fs::file::fs_canonicalize,
fs::mutate::fs_create_file,
fs::mutate::fs_create_dir,
fs::mutate::fs_rename,
fs::mutate::fs_delete,
fs::watch::fs_watch_add,
fs::watch::fs_watch_remove,
fs::search::fs_search,
fs::search::fs_list_files,
fs::grep::fs_grep,
fs::grep::fs_grep_interactive,
fs::grep::fs_glob,
git::commands::git_resolve_repo,
git::commands::git_panel_snapshot,
git::commands::git_status,
git::commands::git_diff,
git::commands::git_diff_content,
git::commands::git_stage,
git::commands::git_unstage,
git::commands::git_discard,
git::commands::git_commit,
git::commands::git_fetch,
git::commands::git_pull_ff_only,
git::commands::git_push,
git::commands::git_log,
git::commands::git_show_commit,
git::commands::git_commit_files,
git::commands::git_commit_file_diff,
git::commands::git_remote_url,
shell::shell_run_command,
shell::shell_session_open,
shell::shell_session_run,
shell::shell_session_close,
shell::shell_bg_spawn,
shell::shell_bg_logs,
shell::shell_bg_kill,
shell::shell_bg_list,
lsp::lsp_probe_binary,
lsp::lsp_install,
lsp::lsp_link_binary,
lsp::lsp_unlink_binary,
lsp::lsp_probe_wsl_binary,
lsp::lsp_resolve_root,
lsp::lsp_spawn,
lsp::lsp_send,
lsp::lsp_close,
workspace::wsl_list_distros,
workspace::wsl_default_distro,
workspace::wsl_home,
workspace::workspace_authorize,
workspace::workspace_current_dir,
get_launch_dir,
open_settings_window,
agent::agent_enable_claude_hooks,
agent::agent_claude_hooks_status,
secrets::secrets_get,
secrets::secrets_set,
secrets::secrets_delete,
secrets::secrets_get_all,
net::lm_ping,
net::ai_http_request,
net::ai_http_stream,
history::history_suggest,
history::history_commands,
history::history_record,
history::history_list,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}