use super::super::*;
impl App {
pub(in crate::tui::app) fn make_report(&mut self) {
let platform = self.platform.clone();
self.reporting.start(&self.host, move |host| {
crate::report::markdown(&crate::report::gather(&host, &platform, true))
});
self.popup = Some(Popup::Text(TextPopup::new(
"Bug report",
"Gathering the report; the health checks take a few seconds…",
true,
)));
}
pub(in crate::tui::app) fn show_report(&mut self, report: &str) {
let saved = self.reports_dir.as_ref().map(|directory| {
let path = directory.join("bug-report.md");
std::fs::create_dir_all(directory)
.and_then(|()| std::fs::write(&path, report))
.map(|()| path)
});
let kept = match saved {
Some(Ok(path)) => {
let shown = path.display().to_string();
let home = self.host.home().to_string_lossy().into_owned();
let shown = match shown.strip_prefix(&home) {
Some(rest) if home.len() > 1 => format!("~{rest}"),
_ => shown,
};
format!("It is saved as {shown}, to copy from or attach.\n\n")
}
Some(Err(error)) => format!("It could not be saved: {error}\n\n"),
None => String::new(),
};
let text = format!(
"Paste it into a new issue at github.com/Commanderx-code/Helix-toolbox/issues, with what happened and how to make it happen again. It shows your home folder as ~ and holds no host name or logs, but read it before posting. {kept}{report}"
);
if matches!(self.popup, None | Some(Popup::Text(_))) {
self.popup = Some(Popup::Text(
TextPopup::new("Bug report", text, true).copying(report),
));
}
}
pub(in crate::tui::app) fn report_worked(
&mut self,
record: &history::Record,
only: Option<&str>,
) {
let machine = hardware_report::machine(
&self.host,
&self.platform,
&helix_toolbox_engine::desktop::detect_on(&self.host),
);
let report = match hardware_report::prepare(record, only, machine, crate::VERSION, "") {
Ok(report) => report,
Err(why) => {
self.popup = Some(Popup::Text(TextPopup::new("No hardware report", why, true)));
return;
}
};
let url = report.issue_url();
let text = report.text();
if let Some(directory) = &self.reports_dir {
let kept = std::fs::create_dir_all(directory).and_then(|()| {
std::fs::write(
directory.join("hardware-report.md"),
format!("{text}\nThe issue, filled in:\n\n{url}\n"),
)
});
if let Err(error) = kept {
tracing::warn!(%error, "the hardware report was not saved");
}
}
self.popup = Some(Popup::HardwareReport(
TextPopup::new(
"Hardware report",
format!(
"{text}\no opens the issue in your browser, filled in; GitHub asks you to sign in, and the form asks what you checked. Nothing is sent until you submit it there. c copies the report."
),
true,
)
.copying(format!("{text}\nThe issue, filled in:\n\n{url}\n")),
url,
));
}
}