Skip to content

Commit c3baa62

Browse files
committed
feat(gui): auto-save the open project every 5 minutes
Adds a 5-minute timer that silently saves the current project when it is dirty and already has a file path, gated behind the `autosave_enabled` config key. Reduced from the original multi-feature PR to this single feature, as requested in review.
1 parent ba4f27b commit c3baa62

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/slic3r/GUI/MainFrame.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
301301
});
302302
#endif
303303

304+
// Auto-save timer: silently saves the open project every 5 minutes when enabled
305+
m_autosave_timer = new wxTimer(this);
306+
Bind(wxEVT_TIMER, [this](wxTimerEvent& e) {
307+
if (e.GetTimer().GetId() != m_autosave_timer->GetId()) { e.Skip(); return; }
308+
if (!wxGetApp().app_config || wxGetApp().app_config->get("autosave_enabled") != "1") return;
309+
if (!m_plater) return;
310+
if (!m_plater->is_project_dirty()) return;
311+
if (m_plater->get_project_filename(".3mf").IsEmpty()) return;
312+
BOOST_LOG_TRIVIAL(info) << "auto-save: saving project";
313+
m_plater->save_project(false);
314+
});
315+
m_autosave_timer->Start(5 * 60 * 1000); // every 5 minutes
316+
304317
#ifdef __APPLE__
305318
// Initialize the docker task bar icon.
306319
switch (wxGetApp().get_app_mode()) {

src/slic3r/GUI/MainFrame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class MainFrame : public DPIFrame
9797
bool m_loaded {false};
9898
wxTimer* m_reset_title_text_colour_timer{ nullptr };
9999
wxString m_title_cache; // last value applied by update_title(), avoids redundant SetTitle
100+
wxTimer* m_autosave_timer{ nullptr };
100101

101102
wxString m_qs_last_input_file = wxEmptyString;
102103
wxString m_qs_last_output_file = wxEmptyString;

0 commit comments

Comments
 (0)