-
-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathlib.rs
More file actions
329 lines (316 loc) · 11.9 KB
/
lib.rs
File metadata and controls
329 lines (316 loc) · 11.9 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#[cfg(desktop)]
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::Manager;
#[cfg(desktop)]
use tauri::RunEvent;
#[cfg(target_os = "macos")]
use tauri::WindowEvent;
mod backend;
mod codex;
mod daemon_binary;
mod dictation;
mod event_sink;
mod files;
mod git;
mod git_utils;
mod local_usage;
mod local_thread_usage;
#[cfg(desktop)]
mod menu;
#[cfg(not(desktop))]
#[path = "menu_mobile.rs"]
mod menu;
mod notifications;
mod prompts;
mod remote_backend;
mod rules;
mod settings;
mod shared;
mod state;
mod storage;
mod tailscale;
#[cfg(desktop)]
mod terminal;
#[cfg(not(desktop))]
#[path = "terminal_mobile.rs"]
mod terminal;
mod types;
mod utils;
mod window;
mod workspaces;
#[cfg(desktop)]
static EXIT_CLEANUP_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
#[cfg(desktop)]
fn keep_daemon_running_after_close(app_handle: &tauri::AppHandle) -> bool {
let state = app_handle.state::<state::AppState>();
tauri::async_runtime::block_on(async {
state
.app_settings
.lock()
.await
.keep_daemon_running_after_app_close
})
}
#[cfg(desktop)]
async fn stop_managed_daemons_for_exit(app_handle: tauri::AppHandle) {
let state = app_handle.state::<state::AppState>();
let _ = tailscale::tailscale_daemon_stop(state).await;
}
#[tauri::command]
fn is_mobile_runtime() -> bool {
cfg!(any(target_os = "ios", target_os = "android"))
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
#[cfg(target_os = "linux")]
{
// Avoid WebKit compositing issues on NVIDIA Linux setups (GBM buffer errors).
if std::env::var_os("__NV_PRIME_RENDER_OFFLOAD").is_none() {
std::env::set_var("__NV_PRIME_RENDER_OFFLOAD", "1");
}
let is_wayland = std::env::var("XDG_SESSION_TYPE")
.map(|session| session.eq_ignore_ascii_case("wayland"))
.unwrap_or(false)
|| std::env::var_os("WAYLAND_DISPLAY").is_some();
let has_nvidia = std::path::Path::new("/proc/driver/nvidia/version").exists();
if is_wayland && has_nvidia && std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_none()
{
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
}
let is_x11 = !is_wayland && std::env::var_os("DISPLAY").is_some();
// Work around sporadic blank WebKitGTK renders on X11 by disabling compositing mode.
// Keep Wayland untouched because this can interfere with input behavior on some setups.
if is_x11 && std::env::var_os("WEBKIT_DISABLE_COMPOSITING_MODE").is_none() {
std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
}
}
#[cfg(desktop)]
let builder = tauri::Builder::default()
.manage(menu::MenuItemRegistry::<tauri::Wry>::default())
.on_menu_event(menu::handle_menu_event)
.enable_macos_default_menu(false)
.menu(menu::build_menu);
#[cfg(not(desktop))]
let builder = tauri::Builder::default();
let builder = builder
.on_window_event(|window, event| {
if window.label() != "main" {
return;
}
#[cfg(target_os = "macos")]
if let WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
let _ = window.hide();
}
})
.setup(|app| {
let state = state::AppState::load(&app.handle());
app.manage(state);
#[cfg(target_os = "windows")]
{
if let Some(main_window) = app.get_webview_window("main") {
let _ = main_window.set_decorations(false);
// Keep menu accelerators wired while suppressing a visible native menu bar.
let _ = main_window.hide_menu();
}
}
#[cfg(desktop)]
{
let app_handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
let state = app_handle.state::<state::AppState>();
let settings = state.app_settings.lock().await.clone();
if matches!(
settings.remote_backend_provider,
crate::types::RemoteBackendProvider::Tcp
) {
if matches!(settings.backend_mode, crate::types::BackendMode::Remote) {
// Remote mode: ensure daemon is up and version-current.
let state = app_handle.state::<state::AppState>();
let _ = tailscale::tailscale_daemon_start(state).await;
} else {
// Local mode: only enforce version if daemon is already running.
let state = app_handle.state::<state::AppState>();
if let Ok(status) = tailscale::tailscale_daemon_status(state).await {
if matches!(status.state, crate::types::TcpDaemonState::Running) {
let state = app_handle.state::<state::AppState>();
let _ = tailscale::tailscale_daemon_start(state).await;
}
}
}
}
});
}
#[cfg(target_os = "ios")]
{
if let Some(main_webview) = app.get_webview_window("main") {
let _ = window::configure_ios_webview_edge_to_edge(&main_webview);
}
}
#[cfg(desktop)]
{
app.handle()
.plugin(tauri_plugin_updater::Builder::new().build())?;
}
Ok(())
});
#[cfg(desktop)]
let builder = builder.plugin(tauri_plugin_window_state::Builder::default().build());
let app = builder
.plugin(tauri_plugin_liquid_glass::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_notification::init())
.invoke_handler(tauri::generate_handler![
settings::get_app_settings,
settings::update_app_settings,
settings::get_codex_config_path,
files::file_read,
files::file_write,
files::read_image_as_data_url,
files::write_text_file,
codex::get_config_model,
menu::menu_set_accelerators,
codex::codex_doctor,
codex::codex_update,
workspaces::list_workspaces,
workspaces::is_workspace_path_dir,
workspaces::add_workspace,
workspaces::add_workspace_from_git_url,
workspaces::add_clone,
workspaces::add_worktree,
workspaces::worktree_setup_status,
workspaces::worktree_setup_mark_ran,
workspaces::remove_workspace,
workspaces::remove_worktree,
workspaces::rename_worktree,
workspaces::rename_worktree_upstream,
workspaces::apply_worktree_changes,
workspaces::update_workspace_settings,
workspaces::set_workspace_runtime_codex_args,
codex::start_thread,
codex::send_user_message,
codex::turn_steer,
codex::turn_interrupt,
codex::start_review,
codex::respond_to_server_request,
codex::remember_approval_rule,
codex::generate_commit_message,
codex::generate_run_metadata,
codex::generate_agent_description,
codex::resume_thread,
codex::thread_live_subscribe,
codex::thread_live_unsubscribe,
codex::fork_thread,
codex::list_threads,
codex::list_mcp_server_status,
codex::archive_thread,
codex::compact_thread,
codex::set_thread_name,
codex::collaboration_mode_list,
workspaces::connect_workspace,
git::get_git_status,
git::init_git_repo,
git::create_github_repo,
git::list_git_roots,
git::get_git_diffs,
git::get_git_log,
git::get_git_commit_diff,
git::get_git_remote,
git::stage_git_file,
git::stage_git_all,
git::unstage_git_file,
git::revert_git_file,
git::revert_git_all,
git::commit_git,
git::push_git,
git::pull_git,
git::fetch_git,
git::sync_git,
git::get_github_issues,
git::get_github_pull_requests,
git::get_github_pull_request_diff,
git::get_github_pull_request_comments,
git::checkout_github_pull_request,
workspaces::list_workspace_files,
workspaces::read_workspace_file,
workspaces::open_workspace_in,
workspaces::get_open_app_icon,
git::list_git_branches,
git::checkout_git_branch,
git::create_git_branch,
codex::model_list,
codex::experimental_feature_list,
codex::set_codex_feature_flag,
codex::get_agents_settings,
codex::set_agents_core_settings,
codex::create_agent,
codex::update_agent,
codex::delete_agent,
codex::read_agent_config_toml,
codex::write_agent_config_toml,
codex::account_rate_limits,
codex::account_read,
codex::codex_login,
codex::codex_login_cancel,
codex::skills_list,
codex::apps_list,
prompts::prompts_list,
prompts::prompts_create,
prompts::prompts_update,
prompts::prompts_delete,
prompts::prompts_move,
prompts::prompts_workspace_dir,
prompts::prompts_global_dir,
terminal::terminal_open,
terminal::terminal_write,
terminal::terminal_resize,
terminal::terminal_close,
dictation::dictation_model_status,
dictation::dictation_download_model,
dictation::dictation_cancel_download,
dictation::dictation_remove_model,
dictation::dictation_start,
dictation::dictation_request_permission,
dictation::dictation_stop,
dictation::dictation_cancel,
local_usage::local_usage_snapshot,
local_thread_usage::local_thread_usage_snapshot,
notifications::is_macos_debug_build,
notifications::app_build_type,
notifications::send_notification_fallback,
tailscale::tailscale_status,
tailscale::tailscale_daemon_command_preview,
tailscale::tailscale_daemon_start,
tailscale::tailscale_daemon_stop,
tailscale::tailscale_daemon_status,
is_mobile_runtime
])
.build(tauri::generate_context!())
.expect("error while running tauri application");
app.run(|app_handle, event| {
#[cfg(desktop)]
if let RunEvent::ExitRequested { api, .. } = event {
if !EXIT_CLEANUP_IN_PROGRESS.load(Ordering::SeqCst)
&& !keep_daemon_running_after_close(app_handle)
{
api.prevent_exit();
EXIT_CLEANUP_IN_PROGRESS.store(true, Ordering::SeqCst);
let app_handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
stop_managed_daemons_for_exit(app_handle.clone()).await;
app_handle.exit(0);
});
}
return;
}
#[cfg(target_os = "macos")]
if let RunEvent::Reopen { .. } = event {
if let Some(window) = app_handle.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
});
}