feat(io): autosave to .sv$ recovery files (SAVETIME command) (#205)

A periodic subscription (every SAVETIME minutes — default 10, 0 disables)
writes a <name>.sv$ recovery copy of each dirty, already-saved drawing at its
own DWG version. Non-destructive: it never touches the original file or the
dirty flag, and skips unsaved (path-less) tabs. The SAVETIME command
sets/queries the interval and persists it. Recovery files (.sv$ and .bak) open
through the normal Open dialog — the loader detects DWG vs DXF from the leading
magic bytes, and a "Backup / Autosave" filter lists them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-29 13:17:40 +03:00
commit 02d2764e45
7 changed files with 93 additions and 6 deletions

View file

@ -109,6 +109,9 @@ pub struct UserSettings {
/// When true (default), the app (re)registers itself as a .dwg/.dxf/.bak
/// handler on every launch. Toggle with the FILEASSOC command.
pub file_assoc_enabled: bool,
/// Minutes between autosaves to a `.sv$` recovery file (SAVETIME command).
/// 0 disables autosave.
pub savetime_min: i32,
/// Persisted viewport background colours (0–255 RGB); `None` = app default
/// (dark grey model / off-white paper). Applied to every drawing tab on
/// launch and to tabs opened later, so a chosen background survives restarts
@ -141,6 +144,7 @@ impl Default for UserSettings {
texteditmode: false,
backup_on_save: true,
file_assoc_enabled: true,
savetime_min: 10,
bg_color: None,
paper_bg_color: None,
}
@ -187,6 +191,11 @@ impl UserSettings {
}
"backup_on_save" => s.backup_on_save = val == "1",
"file_assoc_enabled" => s.file_assoc_enabled = val == "1",
"savetime_min" => {
if let Ok(v) = val.parse::<i32>() {
s.savetime_min = v.max(0);
}
}
"disabled_plugins" => {
s.disabled_plugins = val
.split(',')
@ -228,7 +237,7 @@ impl UserSettings {
.collect::<Vec<_>>()
.join(",");
let body = format!(
"dyn={}\northo={}\npolar={}\npolar_increment_deg={}\nosnap={}\notrack={}\ndefault_assoc_prompted={}\nsnap_modes={}\ndisabled_plugins={}\nplugin_repos={}\ntexteditmode={}\nbackup_on_save={}\nfile_assoc_enabled={}\nbg_color={}\npaper_bg_color={}\n",
"dyn={}\northo={}\npolar={}\npolar_increment_deg={}\nosnap={}\notrack={}\ndefault_assoc_prompted={}\nsnap_modes={}\ndisabled_plugins={}\nplugin_repos={}\ntexteditmode={}\nbackup_on_save={}\nfile_assoc_enabled={}\nsavetime_min={}\nbg_color={}\npaper_bg_color={}\n",
b(self.dyn_input),
b(self.ortho),
b(self.polar),
@ -242,6 +251,7 @@ impl UserSettings {
self.texteditmode,
b(self.backup_on_save),
b(self.file_assoc_enabled),
self.savetime_min,
rgb_to_str(self.bg_color),
rgb_to_str(self.paper_bg_color),
);