feat(io): FILEASSOC command to toggle file association on/off (#205)

`FILEASSOC 1` (re)registers the app as a .dwg/.dxf/.bak handler; `FILEASSOC 0`
unregisters it (removes the .desktop + CAD mime package on Linux, the per-user
registry keys on Windows); bare `FILEASSOC` reports the current state. The
choice persists (file_assoc_enabled) and gates the every-launch
re-registration, so turning it off stays off across restarts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-29 12:58:23 +03:00
commit 9ea800f049
5 changed files with 113 additions and 4 deletions

View file

@ -106,6 +106,9 @@ pub struct UserSettings {
/// When true, saving over an existing file first copies it to a sibling
/// `<name>.bak` so a faulty or accidental save can be recovered (#205).
pub backup_on_save: bool,
/// 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,
/// 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
@ -137,6 +140,7 @@ impl Default for UserSettings {
plugin_repos: Vec::new(),
texteditmode: false,
backup_on_save: true,
file_assoc_enabled: true,
bg_color: None,
paper_bg_color: None,
}
@ -182,6 +186,7 @@ impl UserSettings {
}
}
"backup_on_save" => s.backup_on_save = val == "1",
"file_assoc_enabled" => s.file_assoc_enabled = val == "1",
"disabled_plugins" => {
s.disabled_plugins = val
.split(',')
@ -223,7 +228,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={}\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={}\nbg_color={}\npaper_bg_color={}\n",
b(self.dyn_input),
b(self.ortho),
b(self.polar),
@ -236,6 +241,7 @@ impl UserSettings {
self.plugin_repos.join(","),
self.texteditmode,
b(self.backup_on_save),
b(self.file_assoc_enabled),
rgb_to_str(self.bg_color),
rgb_to_str(self.paper_bg_color),
);