Skip to content

Fix: Resolve DataStore IOException by checking single instance before Koin (#2044)#2091

Merged
maxrave-dev merged 4 commits into
maxrave-dev:devfrom
zaibihsn:fix-datastore-clean
Jun 1, 2026
Merged

Fix: Resolve DataStore IOException by checking single instance before Koin (#2044)#2091
maxrave-dev merged 4 commits into
maxrave-dev:devfrom
zaibihsn:fix-datastore-clean

Conversation

@zaibihsn
Copy link
Copy Markdown

Fixes #2044

(Note to maintainer: Apologies for the messy Git history on the previous PR. I've closed that one and opened this clean branch pointing to dev with exactly one commit.)

Description of the Bug:
When a user launches a second instance of the SimpMusic Desktop app while the first instance is still running, the app crashes with a fatal java.io.IOException (Unable to rename ... settings.preferences_pb.tmp). This is caused by a file-locking collision on Windows because multiple instances of AndroidX DataStore attempt to access the same preferences file.

Root Cause:
In DesktopApp.kt, startKoin { ... } was being executed before the application checked if it was a single instance (SingleInstanceManager.isSingleInstance). Because Koin initialized the dependency graph immediately, the newly spawned Java process created a duplicate DataStore object. This duplicate DataStore attempted to lock and modify settings.preferences_pb while the original process still held the lock.

Resolution:

Moved the SingleInstanceManager.isSingleInstance() check to the very beginning of the runDesktopApp function, entirely before startKoin is called.

Added a restoreRequest callback to ensure the window state is correctly brought back to the foreground when a duplicate launch is intercepted.

Now, if a second instance is launched, it immediately passes the request and deep links to the running instance and gracefully exits before it ever attempts to initialize Koin or touch the DataStore preferences file on disk.

@zaibihsn
Copy link
Copy Markdown
Author

zaibihsn commented Jun 4, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SimpMusic has crashed on Windows

2 participants