Skip to content

Show a progress bar while the update command runs - #287

Closed
kyleinoregon wants to merge 2 commits into
pellcorp:mainfrom
kyleinoregon:feat/update-progress-bar
Closed

Show a progress bar while the update command runs#287
kyleinoregon wants to merge 2 commits into
pellcorp:mainfrom
kyleinoregon:feat/update-progress-bar

Conversation

@kyleinoregon

@kyleinoregon kyleinoregon commented Sep 2, 2026

Copy link
Copy Markdown

Draft until #286 is merged: this branch is stacked on it, so the diff currently shows that commit as well. Only the second commit (src/update_progress.h, the Makefile default and the guarded #include in setting_panel.cpp) is new here.

Builds on #286.

What

When the update button is enabled (UPDATE_CMD), pressing it now spawns the update command detached with sp::Popen instead of blocking the UI thread, and shows a dialog with an lv_bar fed by a status file the command writes: a single <state>|<percent> line, with state one of downloading, flashing, rebooting, failed. The dialog polls the file every 500 ms from an lv_timer. The command's exit status stays authoritative: if it exits before reporting rebooting, the "Failed" dialog is shown, same as today.

The file path defaults to /run/cosmos-update.status (UPDATE_STATUS_FILE in the Makefile, right next to UPDATE_CMD; nothing needs to set it). Builds without UPDATE_CMD are untouched: the include and the header are guarded and compile to nothing.

Notes on the implementation:

  • Header-only (src/update_progress.h), following the simple_dialog.h pattern in the tree.
  • The dialog uses the multiline_message variant of create_configurable_dialog(). The default no-button dialog on a 272 px high screen is 95 px tall and the bar would be clipped; the taller variant leaves about 30 px spare.
  • The command is spawned the same way call_command() runs it (split on whitespace, executed directly), just without waiting.

The producer side for COSMOS is OpenCentauri/cosmos#308.

Tested

  • Elegoo Centauri Carbon (480x272, GUPPY_SMALL_SCREEN) on COSMOS 26.08.0 with the cosmos script change: the dialog appears immediately, percentage and bar track the real 124 MB download, "Installing update, do not power off!" during the flash, then "Your printer will restart shortly!" until the reboot.
  • Failure path exercised with a stub script that reports progress and then exits 1 part way through: red "Update COSMOS Failed" dialog with OK.
  • Built with UPDATE_CMD (COSMOS's variables) and without it (default configuration), both without warnings.

…ommands

The update, switch-to-stock and shutdown-host handlers ran their command
synchronously on the LVGL thread from inside the click dispatch and only
created the "Initiated" dialog after the command returned. Commands that
end in a reboot never return, so the screen showed nothing at all until
the printer restarted, not even the button's pressed state.

Factory reset already avoids this by creating the dialog first and
deferring the command to a one-shot lv_timer. Generalise that into
run_command_deferred() and use it for all four commands. Factory reset
keeps its 5 s delay; the others wait 500 ms, enough for LVGL to render
the dialog before the command blocks the thread. Failure handling is
unchanged: a non-zero exit replaces the dialog with the "Failed" one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@pellcorp

pellcorp commented Sep 2, 2026

Copy link
Copy Markdown
Owner

So Update is basically only for COSMOS now, the Simple AF project never used Update, and I have stopped supporting helper script. So really the question becomes, will the cosmos project actually use this? Are they going to change their update script to publish progress, cos if they are not, this seems pointless.

If they are committing to it, then I am all for this.

Comment thread src/setting_panel.cpp
#include "logger.h"
#include "subprocess.hpp"
#include "simple_dialog.h"
#include "update_progress.h"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be guarded with UPDATE_BUTTON_STATUS_FILE too.

@pellcorp

pellcorp commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Let me be really blunt, if Cosmos commit to the update status file, then there is no point in making this optional, where the UPDATE button is enabled in the Makefile, its expected that an update will proceed this way with progress, no need to add more options.

If they are not going to do the update status file then I wont merge this, I will merge your other PR though as that is good for everyone :-)

When the update button is enabled (UPDATE_CMD) the update command is now
spawned detached with sp::Popen instead of blocking the UI thread, and
the dialog shows a bar fed by the "<state>|<percent>" line the command
publishes to UPDATE_STATUS_FILE (default /run/cosmos-update.status):
downloading, flashing, rebooting, failed. The file is polled every
500 ms from an lv_timer; the command's exit status stays authoritative,
so exiting before it reports "rebooting" shows the "Failed" dialog.

The dialog uses the multiline_message variant because the default
no-button dialog on a 272 px high screen is 95 px tall and clips the bar.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@kyleinoregon
kyleinoregon force-pushed the feat/update-progress-bar branch from b76e932 to 4bd84fe Compare September 2, 2026 03:12
@kyleinoregon kyleinoregon changed the title Optional progress bar for the update command (UPDATE_STATUS_FILE) Show a progress bar while the update command runs Sep 2, 2026
@kyleinoregon

Copy link
Copy Markdown
Author

Makes sense. I've reworked it so there's no separate switch: when UPDATE_CMD is set the update always goes through the progress dialog, and the status file path is just a Makefile default (UPDATE_STATUS_FILE, /run/cosmos-update.status, nothing needs to set it). The include is guarded now too. I also dropped the recipe change from the cosmos PR, so cosmos only needs the script in OpenCentauri/cosmos#308, which is the one that decides whether this is worth merging. Leaving this as a draft until they answer.

@kyleinoregon

Copy link
Copy Markdown
Author

Closing in favour of #289: instead of parsing update-cosmos output on the screen, grumpyscreen now shows Moonraker's update_manager messages, following the cosmos discussion in OpenCentauri/cosmos#308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants