feat(mmterm): auto-save session on SIGTERM/SIGHUP/SIGINT#91
Open
roramirez wants to merge 1 commit into
Open
Conversation
An unattended termination — PC shutdown/reboot (SIGTERM), session teardown (SIGHUP), or kill (SIGINT) — previously lost the session because persistence only ran through the interactive Ctrl+Q / window-close prompt. A background signal-watcher thread now flips a flag and wakes the winit event loop via the existing EventLoopProxy; the main thread saves in user_event and exits without prompting. The save reuses build_saved_session + session::save_to and routes through the scope-aware session_path(), so reopening with the same --scope restores tabs/panes/layout/cwds/theme. Respects the general.restore_session gate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When mmterm is terminated unattended — PC shutdown/reboot (
SIGTERMfrom systemd), logout / display-server teardown (SIGHUP), orkill(SIGINT) — the session was lost. Persistence only ran through the interactiveCtrl+Q/ window-close prompt (InputMode::QuitSave), which needs a human keypress.This adds signal handling so the session is auto-saved on those signals and can be restored on the next launch. Reopening with the same
--scoperestores the tabs, panes, layout, cwds, and theme, because the save routes through the existing scope-awaresession_path().Changes
Cargo.toml— addsignal-hookunder[target.'cfg(unix)'.dependencies].src/main.rs— newApp.shutdown_requested: Arc<AtomicBool>flag;spawn_signal_watcher()runs a background thread onSignals::new([SIGTERM, SIGHUP, SIGINT]), sets the flag, and nudges the event loop awake via the existingEventLoopProxy; wired inmain()on Unix.src/winit_handler.rs—user_eventchecks the flag first; if set it saves and exits without prompting (an unattended shutdown must not block).src/restore.rs—save_session_on_shutdown()reusesbuild_saved_session()+session::save_to(), gated ongeneral.restore_session.CHANGELOG.md— entry under[Unreleased] → Added.src/restore_test.rs.Design notes: the actual save happens on the main thread (safe to touch
App/self.window, no async-signal-safety constraints); the watcher thread only flips a flag and wakes the loop.restore_session = falsestill exits promptly, just without saving. Interactive quit paths are unchanged.How to test
Automated:
New tests:
save_session_on_shutdown_{writes_when_restore_enabled,is_noop_when_restore_disabled,honors_scope_path}.Manual (end-to-end):
cargo run -- --scope worktest, open a couple of tabs / splits,cdsomewhere.kill -TERM $(pgrep -n mmterm)(repeat with-HUP,-INT).~/.config/mmterm/sessions/worktest.tomlwas written/updated.cargo run -- --scope worktest→ tabs, layout, cwds, theme restored.Ctrl+Qprompt and normal quit are unchanged.