Skip to content

Commit

Permalink
[apps_container] Reload country and exam mode after DFU
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNumworks committed Apr 16, 2024
1 parent 9c441fe commit b505da1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
15 changes: 10 additions & 5 deletions apps/apps_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ App::Snapshot* AppsContainer::usbConnectedAppSnapshot() {
return &m_usbConnectedSnapshot;
}

void AppsContainer::setExamMode(Poincare::ExamMode targetExamMode) {
ExamMode::Ruleset previousRules =
Preferences::SharedPreferences()->examMode().ruleset();
void AppsContainer::setExamMode(Poincare::ExamMode targetExamMode,
Poincare::ExamMode previousMode) {
Preferences::SharedPreferences()->setExamMode(targetExamMode);

if (targetExamMode.ruleset() != ExamMode::Ruleset::Off) {
Expand All @@ -75,7 +74,7 @@ void AppsContainer::setExamMode(Poincare::ExamMode targetExamMode) {
for (int i = 0; i < numberOfBuiltinApps(); i++) {
appSnapshotAtIndex(i)->reset();
}
} else if (previousRules == ExamMode::Ruleset::PressToTest) {
} else if (previousMode.ruleset() == ExamMode::Ruleset::PressToTest) {
// Reset when leaving PressToTest mode.
Ion::Reset::core();
}
Expand Down Expand Up @@ -179,6 +178,12 @@ bool AppsContainer::processEvent(Ion::Events::Event event) {
updateBatteryState();
switchToBuiltinApp(usbConnectedAppSnapshot());
Ion::USB::DFU();
/* DFU might have changed preferences and global preferences, update those
* that have callbacks : country and exam mode.*/
GlobalPreferences::SharedGlobalPreferences()->setCountry(
GlobalPreferences::SharedGlobalPreferences()->country());
setExamMode(Preferences::SharedPreferences()->examMode(),
Ion::ExamMode::get());
// Update LED when exiting DFU mode
Ion::LED::updateColorWithPlugAndCharge();
switchToBuiltinApp(activeSnapshot);
Expand Down Expand Up @@ -279,7 +284,7 @@ void AppsContainer::run() {
Preferences* poincarePreferences = Preferences::SharedPreferences();
Poincare::ExamMode examMode = poincarePreferences->examMode();
if (examMode.isActive()) {
setExamMode(examMode);
setExamMode(examMode, Poincare::ExamMode());
} else {
refreshPreferences();
}
Expand Down
3 changes: 2 additions & 1 deletion apps/apps_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class AppsContainer : public Escher::Container, Ion::Storage::StorageDelegate {
Escher::App::Snapshot* onBoardingAppSnapshot();
Escher::App::Snapshot* usbConnectedAppSnapshot();
Home::App::Snapshot* homeAppSnapshot() { return &m_homeSnapshot; }
void setExamMode(Poincare::ExamMode targetExamMode);
void setExamMode(Poincare::ExamMode targetExamMode,
Poincare::ExamMode previousMode);
Shared::GlobalContext* globalContext();
void didSuspend();
bool dispatchEvent(Ion::Events::Event event) override;
Expand Down
3 changes: 2 additions & 1 deletion apps/exam_pop_up_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ I18n::Message ExamPopUpController::activationWarningMessage() const {
bool ExamPopUpController::handleButton() const {
/* Warning : By unplugging before confirmation, the examMode may then be
* deactivated while unplugged. */
AppsContainer::sharedAppsContainer()->setExamMode(m_targetExamMode);
AppsContainer::sharedAppsContainer()->setExamMode(
m_targetExamMode, Preferences::SharedPreferences()->examMode());
return true;
}
3 changes: 0 additions & 3 deletions poincare/src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ ExamMode Preferences::examMode() const {
}

void Preferences::setExamMode(ExamMode mode) {
if (m_examMode == mode) {
return;
}
m_examMode = mode;
Ion::ExamMode::set(mode);
}
Expand Down

0 comments on commit b505da1

Please sign in to comment.