-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
216 lines (201 loc) · 9.4 KB
/
Copy pathlib.rs
File metadata and controls
216 lines (201 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
use std::{env, fs, path::PathBuf, sync::Once};
#[cfg(target_os = "windows")]
use std::process::Command;
use tauri::Manager;
pub mod app_state;
pub mod commands;
pub mod db;
pub mod domain;
pub mod error;
pub mod mcp;
pub mod services;
pub mod storage;
static PANIC_HOOK: Once = Once::new();
pub fn run() -> Result<(), String> {
install_panic_hook();
tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.setup(|app| {
let database = tauri::async_runtime::block_on(db::init(app.handle()))?;
tauri::async_runtime::block_on(db::ensure_application_defaults(&database))?;
let secret_store = services::secret_store_service::default_secret_store();
let response_bodies = services::response_body_service::ResponseBodyStore::new(
storage::paths::response_bodies_dir(app.handle())?,
);
let referenced_bodies = tauri::async_runtime::block_on(
services::history_service::stored_response_body_paths(&database),
)?;
tauri::async_runtime::block_on(response_bodies.reconcile(&referenced_bodies))?;
let realtime_payloads = services::realtime_payload_service::RealtimePayloadStore::new(
storage::paths::realtime_payloads_dir(app.handle())?,
);
tauri::async_runtime::block_on(realtime_payloads.reset())?;
let realtime_connections =
services::realtime_service::RealtimeConnectionManager::new(realtime_payloads);
app.manage(app_state::AppState::new(
database,
secret_store,
response_bodies,
realtime_connections,
));
if let Some(window) = app.get_webview_window("main") {
services::window_state_service::restore_and_track_main_window(&window);
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::activity::list_agent_activity,
commands::requests::send_request,
commands::requests::preview_request,
commands::requests::cancel_active_request,
commands::requests::pick_multipart_files,
commands::realtime::connect_realtime_connection,
commands::realtime::list_realtime_connection_profiles,
commands::realtime::create_realtime_connection_profile,
commands::realtime::get_realtime_connection_profile,
commands::realtime::update_realtime_connection_profile,
commands::realtime::delete_realtime_connection_profile,
commands::realtime::export_realtime_connection_profiles,
commands::realtime::import_realtime_connection_profiles,
commands::realtime::get_realtime_workspace_state,
commands::realtime::save_realtime_workspace_state,
commands::realtime::disconnect_realtime_connection,
commands::realtime::release_realtime_connection,
commands::realtime::send_realtime_message,
commands::realtime::ping_realtime_connection,
commands::realtime::close_realtime_connection,
commands::realtime::get_realtime_session_snapshot,
commands::realtime::clear_realtime_transcript,
commands::realtime::read_realtime_payload,
commands::realtime::save_realtime_payload,
commands::realtime::export_realtime_transcript,
commands::responses::read_response_body_window,
commands::responses::search_response_body,
commands::responses::cancel_response_search,
commands::responses::find_response_match,
commands::responses::read_response_body_text,
commands::responses::retain_response_body,
commands::responses::release_response_body,
commands::responses::get_response_body_path,
commands::responses::save_response_body,
commands::responses::format_response_body,
commands::responses::cancel_response_body_job,
commands::settings::get_settings,
commands::settings::get_mcp_setup_info,
commands::settings::update_settings,
commands::settings::get_request_workspace_state,
commands::settings::save_request_workspace_state,
commands::updates::check_for_updates,
commands::updates::install_update,
commands::history::list_history,
commands::history::get_history_entry,
commands::history::clear_history,
commands::collections::list_collections,
commands::collections::search_collection_entities,
commands::collections::get_collection_sidebar_state,
commands::collections::save_collection_sidebar_state,
commands::collections::create_collection,
commands::collections::list_collection_items,
commands::collections::create_collection_folder,
commands::collections::update_collection_folder,
commands::collections::move_collection_item,
commands::collections::update_collection,
commands::collections::delete_collection,
commands::collections::list_saved_requests,
commands::collections::save_request_to_collection,
commands::collections::update_saved_request,
commands::collections::get_saved_request,
commands::collections::list_saved_realtime_messages,
commands::collections::save_realtime_message_to_collection,
commands::collections::update_saved_realtime_message,
commands::collections::get_saved_realtime_message,
commands::collections::delete_collection_item,
commands::collections::delete_saved_request,
commands::collections::delete_saved_realtime_message,
commands::collections::export_collection,
commands::playbooks::list_playbooks,
commands::playbooks::create_playbook,
commands::playbooks::get_playbook,
commands::playbooks::update_playbook,
commands::playbooks::duplicate_playbook,
commands::playbooks::delete_playbook,
commands::playbooks::add_playbook_step,
commands::playbooks::update_playbook_step,
commands::playbooks::reorder_playbook_steps,
commands::playbooks::delete_playbook_step,
commands::playbooks::get_playbook_execution_context,
commands::playbooks::create_playbook_run,
commands::playbooks::finish_playbook_run,
commands::playbooks::record_playbook_run_step,
commands::playbooks::list_playbook_runs,
commands::playbooks::get_playbook_run,
commands::environments::list_environments,
commands::environments::create_environment,
commands::environments::get_environment,
commands::environments::update_environment,
commands::environments::delete_environment,
commands::environments::set_active_environment,
commands::environments::import_postman_environment,
commands::environments::export_environment,
commands::imports::import_requests,
commands::imports::import_curl_request_to_draft,
commands::imports::import_openapi_request_to_draft,
])
.run(tauri::generate_context!())
.map_err(|error| error.to_string())
}
pub fn report_startup_failure(message: &str) {
let log_path = write_startup_log(message);
let summary = format!(
"PostNot failed to start.\n\n{}\n\nStartup log: {}",
message,
log_path.display()
);
eprintln!("{}", summary);
#[cfg(target_os = "windows")]
{
show_windows_error_dialog(&summary);
}
}
fn install_panic_hook() {
PANIC_HOOK.call_once(|| {
std::panic::set_hook(Box::new(|panic_info| {
let message = match panic_info.payload().downcast_ref::<&str>() {
Some(payload) => (*payload).to_string(),
None => match panic_info.payload().downcast_ref::<String>() {
Some(payload) => payload.clone(),
None => "Unknown panic".to_string(),
},
};
let location = panic_info
.location()
.map(|location| {
format!(
"{}:{}:{}",
location.file(),
location.line(),
location.column()
)
})
.unwrap_or_else(|| "unknown location".to_string());
report_startup_failure(&format!("panic at {}: {}", location, message));
}));
});
}
fn write_startup_log(message: &str) -> PathBuf {
let log_path = env::temp_dir().join("postnot-startup.log");
let log_body = format!("PostNot startup failure\n\n{}", message);
let _ = fs::write(&log_path, log_body);
log_path
}
#[cfg(target_os = "windows")]
fn show_windows_error_dialog(message: &str) {
let escaped_message = message.replace('\'', "''");
let script = format!(
"Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('{escaped}', 'PostNot failed to start') | Out-Null",
escaped = escaped_message
);
let _ = Command::new("powershell")
.args(["-NoProfile", "-Command", &script])
.spawn();
}