fix: fix periodic freeze in print stack
This commit is contained in:
@@ -423,11 +423,35 @@ static void compute_config_layout(ConfigLayout* lo) {
|
||||
lo->cancel_btn = {pad + 88, g_config.height - BTN_H - 16, 80, BTN_H};
|
||||
}
|
||||
|
||||
static void refresh_state(bool force = false) {
|
||||
static bool refresh_state(bool force = false) {
|
||||
uint64_t now = montauk::get_milliseconds();
|
||||
if (!force && g_app.printers_loaded && now - g_app.last_refresh_ms < 1000) return;
|
||||
if (!force && g_app.printers_loaded && now - g_app.last_refresh_ms < 1000) return false;
|
||||
|
||||
ensure_spool_dirs();
|
||||
bool was_loaded = g_app.printers_loaded;
|
||||
char old_printer_uri[MAX_PATH_LEN];
|
||||
safe_copy(old_printer_uri, sizeof(old_printer_uri), g_app.printer_uri);
|
||||
bool old_daemon_running = g_app.daemon_running;
|
||||
int old_daemon_pid = g_app.daemon_pid;
|
||||
int old_queue_count = g_app.queue_count;
|
||||
int old_active_count = g_app.active_count;
|
||||
int old_done_count = g_app.done_count;
|
||||
int old_failed_count = g_app.failed_count;
|
||||
JobMeta old_active = g_app.last_active;
|
||||
JobMeta old_failed = g_app.last_failed;
|
||||
bool old_has_active = g_app.has_active;
|
||||
bool old_has_failed = g_app.has_failed;
|
||||
IppCapabilities old_probe_caps = g_app.probe_caps;
|
||||
bool old_probe_valid = g_app.probe_valid;
|
||||
bool old_probe_ok = g_app.probe_ok;
|
||||
char old_probe_message[sizeof(g_app.probe_message)];
|
||||
char old_probe_time[sizeof(g_app.probe_time)];
|
||||
char old_probe_detail[sizeof(g_app.probe_detail)];
|
||||
safe_copy(old_probe_message, sizeof(old_probe_message), g_app.probe_message);
|
||||
safe_copy(old_probe_time, sizeof(old_probe_time), g_app.probe_time);
|
||||
safe_copy(old_probe_detail, sizeof(old_probe_detail), g_app.probe_detail);
|
||||
|
||||
if (force || !g_app.printers_loaded)
|
||||
ensure_spool_dirs();
|
||||
|
||||
if (!read_default_printer_uri(g_app.printer_uri, sizeof(g_app.printer_uri)))
|
||||
g_app.printer_uri[0] = '\0';
|
||||
@@ -449,6 +473,25 @@ static void refresh_state(bool force = false) {
|
||||
g_app.has_failed = load_latest_job(SPOOL_FAILED_DIR, &g_app.last_failed);
|
||||
g_app.printers_loaded = true;
|
||||
g_app.last_refresh_ms = now;
|
||||
|
||||
return !was_loaded
|
||||
|| !montauk::streq(old_printer_uri, g_app.printer_uri)
|
||||
|| old_daemon_running != g_app.daemon_running
|
||||
|| old_daemon_pid != g_app.daemon_pid
|
||||
|| old_queue_count != g_app.queue_count
|
||||
|| old_active_count != g_app.active_count
|
||||
|| old_done_count != g_app.done_count
|
||||
|| old_failed_count != g_app.failed_count
|
||||
|| old_has_active != g_app.has_active
|
||||
|| (g_app.has_active && memcmp(&old_active, &g_app.last_active, sizeof(g_app.last_active)) != 0)
|
||||
|| old_has_failed != g_app.has_failed
|
||||
|| (g_app.has_failed && memcmp(&old_failed, &g_app.last_failed, sizeof(g_app.last_failed)) != 0)
|
||||
|| old_probe_valid != g_app.probe_valid
|
||||
|| old_probe_ok != g_app.probe_ok
|
||||
|| !montauk::streq(old_probe_message, g_app.probe_message)
|
||||
|| !montauk::streq(old_probe_time, g_app.probe_time)
|
||||
|| !montauk::streq(old_probe_detail, g_app.probe_detail)
|
||||
|| memcmp(&old_probe_caps, &g_app.probe_caps, sizeof(g_app.probe_caps)) != 0;
|
||||
}
|
||||
|
||||
static void probe_printer() {
|
||||
@@ -1207,10 +1250,12 @@ extern "C" void _start() {
|
||||
int r = g_win.poll(&ev);
|
||||
if (r < 0) break;
|
||||
if (r == 0) {
|
||||
uint64_t last_refresh = g_app.last_refresh_ms;
|
||||
refresh_state(false);
|
||||
if (g_app.last_refresh_ms != last_refresh)
|
||||
if (refresh_state(false))
|
||||
redraw_main = true;
|
||||
if (g_app.status_msg[0] && !status_visible()) {
|
||||
g_app.status_msg[0] = '\0';
|
||||
redraw_main = true;
|
||||
}
|
||||
|
||||
if (redraw_main)
|
||||
render();
|
||||
|
||||
Reference in New Issue
Block a user