refactor(io): set up file association once, not on every launch (#205)

Drop the every-launch (re)registration thread. File association is now set up
once via the first-launch prompt (Yes → register + set default; No → decline,
persisted as file_assoc_enabled) and managed afterwards by the FILEASSOC
command. set_default_app now registers the handler entries (.desktop / mime /
ProgIDs) itself before asking the OS to default to us, since boot no longer
does — so the default never points at a missing handler.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-29 13:06:33 +03:00
1 parent 9ea800f049
commit 54186309b2
3 files changed
+11 -16

No files matched your search

+3 -16
View File
@@ -2150,22 +2150,9 @@ impl OpenCADStudio {
#[cfg(not(target_arch = "wasm32"))]
fn boot() -> (Self, Task<Message>) {
use helpers::build_window_icon;
// Silently (re)register this binary as a .dwg/.dxf handler so it appears
// in the OS "Open with" list. Best-effort and idempotent; covers the
// portable .exe / AppImage that no installer has registered. Detached so
// it never delays startup.
std::thread::spawn(|| {
// Honour the FILEASSOC toggle: skip (re)registration when the user
// has turned file association off.
let enabled = settings::UserSettings::load()
.map(|s| s.file_assoc_enabled)
.unwrap_or(true);
if enabled {
if let Err(e) = crate::io::file_association::register_as_handler() {
eprintln!("file association: handler registration failed: {e}");
}
}
});
// File association is no longer re-registered on every launch. It is set
// up once via the first-launch prompt below (when the user hasn't been
// asked yet) and afterwards managed entirely by the FILEASSOC command.
let state = Self::new();
let (id, open_task) = window::open(window::Settings {
maximized: true,
+4
View File
@@ -2590,14 +2590,18 @@ impl OpenCADStudio {
Task::none()
}
Message::AssocPromptYes => {
self.file_assoc_enabled = true;
self.mark_assoc_prompted();
self.active_modal = None;
// set_default_app registers the handler first, then makes us the
// default — boot no longer does this automatically.
Task::perform(
crate::io::file_association::set_default_app(),
Message::AssocResult,
)
}
Message::AssocPromptNo => {
self.file_assoc_enabled = false;
self.mark_assoc_prompted();
self.active_modal = None;
Task::none()
+4
View File
@@ -96,6 +96,10 @@ pub async fn set_default_app() -> Result<String, String> {
}
fn set_default_app_blocking() -> Result<String, String> {
// Boot no longer auto-registers, so make sure the handler entries (the
// .desktop / mime package / ProgIDs) exist before asking the OS to default
// to us — otherwise the default would point at nothing.
register_as_handler()?;
#[cfg(target_os = "windows")]
{
windows_impl::set_default()