Only the brain keeps its box awake: a computer showing another brain leaves its own box alone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
王性驊 2026-11-05 17:10:05 +08:00
parent ab564f706f
commit c3e2e28ec4
2 changed files with 13 additions and 2 deletions

View File

@ -762,6 +762,8 @@ impl App {
self.mir.base = Value::Null; self.mir.base = Value::Null;
self.mir.local = Some(local); self.mir.local = Some(local);
self.mir.on = true; self.mir.on = true;
// The bots' computer is the brain's now; this one's box isn't kept awake.
crate::cloudbox::set_brain(false);
self.mir.online = false; self.mir.online = false;
self.mir.version.store(0, Ordering::SeqCst); self.mir.version.store(0, Ordering::SeqCst);
self.mir.pending.lock().unwrap().clear(); self.mir.pending.lock().unwrap().clear();
@ -777,6 +779,7 @@ impl App {
fn mirror_leave(&mut self) { fn mirror_leave(&mut self) {
self.mir.gen.fetch_add(1, Ordering::SeqCst); self.mir.gen.fetch_add(1, Ordering::SeqCst);
self.mir.on = false; self.mir.on = false;
crate::cloudbox::set_brain(true);
self.mir.online = false; self.mir.online = false;
self.mir.outbox = None; self.mir.outbox = None;
self.streams.clear(); self.streams.clear();

View File

@ -697,12 +697,14 @@ pub fn start_background() {
set_run(probe()); set_run(probe());
resume_interrupted(); resume_interrupted();
loop { loop {
// (First wait a little: a computer showing another brain says so right after start.)
std::thread::sleep(Duration::from_secs(20));
let (idle, rebuilding) = { let (idle, rebuilding) = {
let s = shared().lock().unwrap(); let s = shared().lock().unwrap();
(s.last_used.elapsed().as_secs(), s.rebuilding) (s.last_used.elapsed().as_secs(), s.rebuilding)
}; };
if !rebuilding { if !rebuilding {
if matches!(probe(), Run::Asleep) { if IS_BRAIN.load(Ordering::SeqCst) && matches!(probe(), Run::Asleep) {
log("Bot 的電腦不休眠:叫醒它。"); log("Bot 的電腦不休眠:叫醒它。");
let _ = ensure_running(); let _ = ensure_running();
} }
@ -714,11 +716,17 @@ pub fn start_background() {
refresh(); refresh();
maybe_scheduled_update(); maybe_scheduled_update();
} }
std::thread::sleep(Duration::from_secs(20));
} }
}); });
} }
/// This AnyBot is the brain (its box is the bots' computer). A computer showing another brain
/// doesn't use its own box, so it isn't kept awake there.
static IS_BRAIN: AtomicBool = AtomicBool::new(true);
pub fn set_brain(on: bool) {
IS_BRAIN.store(on, Ordering::SeqCst);
}
static VIEWER_OPEN: AtomicBool = AtomicBool::new(false); static VIEWER_OPEN: AtomicBool = AtomicBool::new(false);
pub fn set_viewer_open(on: bool) { pub fn set_viewer_open(on: bool) {
VIEWER_OPEN.store(on, Ordering::SeqCst); VIEWER_OPEN.store(on, Ordering::SeqCst);