Skip to content

Commit

Permalink
Cache on battery status
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoffland committed Jan 11, 2024
1 parent 4b2110a commit c73b397
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/fah/client/OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const char *OS::getCPU() const {
}


bool OS::isOnBattery() const {return PowerManagement::instance().onBattery();}
void OS::dispatch() {app.getEventBase().dispatch();}


Expand All @@ -97,12 +96,13 @@ void OS::update() {
app.triggerUpdate();
}

paused = app.getPaused();
active = app.isActive();
failure = app.hasFailure();
auto &pm = PowerManagement::instance();
paused = app.getPaused();
active = app.isActive();
failure = app.hasFailure();
onBattery = pm.onBattery();

// Keep system awake if not on battery
auto &pwrMan = PowerManagement::instance();
if (!pwrMan.onBattery() && app.keepAwake()) lastKeepAwake = Time::now();
pwrMan.allowSystemSleep(30 < Time::now() - lastKeepAwake);
if (!onBattery && app.keepAwake()) lastKeepAwake = Time::now();
pm.allowSystemSleep(30 < Time::now() - lastKeepAwake);
}
9 changes: 5 additions & 4 deletions src/fah/client/OS.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace FAH {
std::atomic<bool> paused;
std::atomic<bool> active;
std::atomic<bool> failure;
std::atomic<bool> onBattery;

protected:
cb::SmartPointer<cb::Event::Event> event;
Expand All @@ -59,12 +60,12 @@ namespace FAH {
virtual const char *getName() const = 0;
virtual const char *getCPU() const;
virtual bool isSystemIdle() const = 0;
virtual bool isOnBattery() const;
virtual void dispatch();

bool isPaused() const {return paused;}
bool isActive() const {return active;}
bool hasFailure() const {return failure;}
bool isPaused() const {return paused;}
bool isActive() const {return active;}
bool hasFailure() const {return failure;}
bool isOnBattery() const {return onBattery;}
void requestExit() const;
void setState(const std::string &state) const;

Expand Down

0 comments on commit c73b397

Please sign in to comment.