S006: keys, cache, site-doctor smokes; single instance check; view source of file://; timed window requests
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
bdf66f96d7
commit
326dde8a97
3 changed files with 290 additions and 4 deletions
|
|
@ -779,6 +779,10 @@ impl App {
|
|||
let headers = Url::parse(&url).map(|u| self.request_headers(&u, "")).unwrap_or_default();
|
||||
let fetch_url = url.clone();
|
||||
self.spawn("source", move || {
|
||||
// Local files are read from disk: the HTTP client only speaks http(s).
|
||||
if let Some(path) = Url::parse(&fetch_url).ok().filter(|u| u.scheme() == "file").and_then(|u| u.to_file_path().ok()) {
|
||||
return std::fs::read(&path).map(|bytes| String::from_utf8_lossy(&bytes).into_owned()).map_err(|e| e.to_string());
|
||||
}
|
||||
let refs: Vec<(&str, &str)> = headers.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
|
||||
crate::net::fetch::get(&fetch_url, &refs, 16 * 1024 * 1024, Duration::from_secs(30)).map(|f| f.text())
|
||||
}, move |app, result| {
|
||||
|
|
|
|||
|
|
@ -1700,9 +1700,11 @@ fn standard_axis(axis: gilrs::Axis) -> Option<usize> {
|
|||
}
|
||||
|
||||
impl ApplicationHandler<AppEvent> for App {
|
||||
fn new_events(&mut self, _event_loop: &ActiveEventLoop, cause: StartCause) {
|
||||
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause) {
|
||||
if let StartCause::ResumeTimeReached { .. } = cause {
|
||||
self.tick();
|
||||
// A timed step (selftest, scheduled jobs) may have asked for a window.
|
||||
self.open_pending_windows(event_loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
//! scroll <x> <y> <dy> turn the wheel over x,y in the window by dy points (positive scrolls down)
|
||||
//! welcome <step> show step 0..5 of the welcome page
|
||||
//! customize [close] open (or close) the new tab page's Customize panel
|
||||
//! launch <args> start a second Nacre with these arguments (same profile, no script); it must hand
|
||||
//! them to this one and exit within 10 s (single instance), else the run fails
|
||||
//! log <text> write a line to the log
|
||||
//! quit
|
||||
|
||||
|
|
@ -594,6 +596,27 @@ impl App {
|
|||
}
|
||||
self.redraw(window);
|
||||
},
|
||||
"launch" => {
|
||||
// Single instance check: the second process must find this one, hand over and exit.
|
||||
let child = std::env::current_exe().and_then(|exe| std::process::Command::new(exe).args(rest.split_whitespace()).env_remove("NACRE_SCRIPT").spawn());
|
||||
let result = match child {
|
||||
Ok(mut child) => {
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
loop {
|
||||
match child.try_wait() {
|
||||
Ok(Some(status)) => break format!("launch exited: {status}"),
|
||||
Ok(None) if Instant::now() < deadline => std::thread::sleep(Duration::from_millis(100)),
|
||||
_ => {
|
||||
let _ = child.kill();
|
||||
break "ASSERT FAILED: launch did not hand off and exit".to_owned();
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(error) => format!("ASSERT FAILED: launch: {error}"),
|
||||
};
|
||||
self.selftest_log(&result);
|
||||
},
|
||||
"log" => self.selftest_log(rest),
|
||||
"quit" => self.quit(),
|
||||
_ => self.selftest_log(&format!("unknown line: {line}")),
|
||||
|
|
|
|||
Loading…
Reference in a new issue