fix(app): the wizard resumes until finished, late answers stay off other screens, logs follow the chosen folder
- app_status reports firstRun until wizard_finish; wizard_step saves the step reached in config/setup.json, and the wizard resumes there (a stored token lets the bot step go on). - show() and refresh() drop answers that arrive after the screen changed. - folder_choose points the log hub at the folder's logs/ at once. - Choosing another server clears the voice channel picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,8 @@ pub fn tab_of(category: &str) -> &'static str {
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
/// Where the daily files go; None: memory only (no data folder yet).
|
||||
dir: Option<PathBuf>,
|
||||
lines: VecDeque<LogLine>,
|
||||
next_seq: u64,
|
||||
files: HashMap<(String, NaiveDate), std::fs::File>,
|
||||
@@ -66,18 +68,28 @@ struct State {
|
||||
}
|
||||
|
||||
pub struct LogHub {
|
||||
dir: Option<PathBuf>,
|
||||
state: Mutex<State>,
|
||||
}
|
||||
|
||||
impl LogHub {
|
||||
/// A hub writing daily files to `dir` (None: memory only).
|
||||
pub fn new(dir: Option<&Path>) -> Arc<Self> {
|
||||
let hub = Arc::new(Self { dir: dir.map(Path::to_path_buf), state: Mutex::default() });
|
||||
let hub = Arc::new(Self { state: Mutex::new(State { dir: dir.map(Path::to_path_buf), ..State::default() }) });
|
||||
hub.cleanup(Local::now().date_naive());
|
||||
hub
|
||||
}
|
||||
|
||||
/// Start writing daily files to `dir` (the data folder was just chosen); lines kept in memory
|
||||
/// stay there, the next ones also go to the files.
|
||||
pub fn set_dir(&self, dir: &Path) {
|
||||
{
|
||||
let mut s = self.state.lock().unwrap();
|
||||
s.dir = Some(dir.to_path_buf());
|
||||
s.files.clear();
|
||||
}
|
||||
self.cleanup(Local::now().date_naive());
|
||||
}
|
||||
|
||||
/// The stored secrets' values, masked in every copy and export.
|
||||
pub fn set_secrets(&self, values: Vec<String>) {
|
||||
self.state.lock().unwrap().secrets = values;
|
||||
@@ -107,7 +119,7 @@ impl LogHub {
|
||||
let mut s = self.state.lock().unwrap();
|
||||
let line = LogLine { seq: s.next_seq, at_ms: at.timestamp_millis(), level, tab: tab.into(), text: text.into() };
|
||||
s.next_seq += 1;
|
||||
if let Some(dir) = &self.dir {
|
||||
if let Some(dir) = s.dir.clone() {
|
||||
let day = at.date_naive();
|
||||
let key = (tab.to_owned(), day);
|
||||
if !s.files.contains_key(&key) {
|
||||
@@ -135,8 +147,12 @@ impl LogHub {
|
||||
|
||||
/// Remove log files older than the retention.
|
||||
fn cleanup(&self, today: NaiveDate) {
|
||||
self.state.lock().unwrap().last_cleanup = Some(today);
|
||||
let Some(dir) = &self.dir else { return };
|
||||
let dir = {
|
||||
let mut s = self.state.lock().unwrap();
|
||||
s.last_cleanup = Some(today);
|
||||
s.dir.clone()
|
||||
};
|
||||
let Some(dir) = dir else { return };
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
for e in entries.flatten() {
|
||||
let name = e.file_name().to_string_lossy().into_owned();
|
||||
@@ -183,10 +199,13 @@ impl LogHub {
|
||||
/// The log files of days `from..=to` in a zip at `out`, masked, at most `ZIP_MAX_BYTES`: when
|
||||
/// larger, the oldest lines are left out and NOTE.txt says how many. Returns the lines left out.
|
||||
pub fn export_zip(&self, from: NaiveDate, to: NaiveDate, out: &Path) -> std::io::Result<usize> {
|
||||
let secrets = self.state.lock().unwrap().secrets.clone();
|
||||
let Some(dir) = &self.dir else { return Err(std::io::Error::other("no log folder")) };
|
||||
let (secrets, dir) = {
|
||||
let s = self.state.lock().unwrap();
|
||||
(s.secrets.clone(), s.dir.clone())
|
||||
};
|
||||
let Some(dir) = dir else { return Err(std::io::Error::other("no log folder")) };
|
||||
let mut files: Vec<(NaiveDate, String, Vec<String>)> = vec![];
|
||||
for e in std::fs::read_dir(dir)?.flatten() {
|
||||
for e in std::fs::read_dir(&dir)?.flatten() {
|
||||
let name = e.file_name().to_string_lossy().into_owned();
|
||||
let Some(day) = file_day(&name) else { continue };
|
||||
if day < from || day > to {
|
||||
|
||||
Reference in New Issue
Block a user