Skip to content

Conversation

MiguVT
Copy link

@MiguVT MiguVT commented Aug 14, 2025

This pull request adds support for a "portable mode" to the Modrinth App, allowing users to run the application from any location with all data stored alongside the executable. The implementation includes both backend and documentation updates to detect and describe portable mode activation via either an environment variable or a portable.txt file.

Portable Mode Implementation:

  • Added detection logic for portable mode in DirectoryInfo by checking for the MODRINTH_PORTABLE environment variable or the presence of a portable.txt file next to the executable. When enabled, all app data is stored in a ModrinthAppData directory beside the executable.
  • Updated the settings and config directory resolution to use the portable directory when portable mode is detected.

API and Command Updates:

  • Introduced a new Tauri command is_portable in main.rs to expose portable mode status to the frontend, and registered it in the app’s invoke handler. [1] [2]

Documentation:

  • Added a comprehensive guide on portable mode (portable-mode.md), including activation methods, directory structure, use cases, conversion instructions, troubleshooting, and security considerations.

@IMB11 IMB11 added enhancement New feature or request app Relates to Modrinth App labels Aug 14, 2025
MiguVT and others added 5 commits August 14, 2025 23:01
Centralizes portable mode detection and setup to ensure consistent behavior across the application, especially for the window state plugin and directory lookups.

This change introduces a `setup_portable_env_vars` function that sets environment variables based on the detected portable directory.  It ensures that `tauri-plugin-window-state` and `dirs.rs` correctly use the portable directory for storing application data and configuration.  The logic for detecting portable mode has been moved to `DirectoryInfo`. The `is_portable` command in `main.rs` now utilizes the centralized portable directory check.

The portable mode detection logic has been removed from `DirectoryInfo::get_initial_settings_dir` and `is_portable` to prevent duplicated checks.
Unifies portable mode detection logic into a single function
and reuses it across the application.

This ensures consistency in determining whether the application
is running in portable mode, particularly for setting
environment variables and checking portable status.
@MiguVT
Copy link
Author

MiguVT commented Aug 15, 2025

Hi @AlexTMjugador and @Gaming32, now everything should work fine, i have done a little workaround for doing that, at the start i changed dirs.rs but some files was hardcoded by some tauri plugins at appdata soo i made a workaround that change the env from where tauri store files depending on the operating system. Everything should work well now. I hope this workaround can be accepted cause its a clean workaround and not only simplify things, it helps to not need to adapt any code if new directory or something is added.

@MiguVT MiguVT marked this pull request as draft August 16, 2025 12:20
MiguVT and others added 7 commits August 16, 2025 14:36
@brawaru
Copy link
Contributor

brawaru commented Aug 17, 2025

That's a very welcome PR to see! Though, I have to wonder about a few things:

  • Would there be any risk just using the current directory for data instead of ModrinthAppData, sort of like Prism Launcher does it? I mean, if you have portable.txt in the same directory, it can probably be reasonably assumed you have isolated the app executable from any other files.

  • Is there need to introduce a separate environment variable when THESEUS_CONFIG_DIR does essentially the same thing?

@MiguVT
Copy link
Author

MiguVT commented Aug 17, 2025

That's a very welcome PR to see! Though, I have to wonder about a few things:

* Would there be any risk just using the current directory for data instead of `ModrinthAppData`, sort of like Prism Launcher does it? I mean, if you have `portable.txt` in the same directory, it can probably be reasonably assumed you have isolated the app executable from any other files.

No, there willnt be any risk but I prefer mantain it in a subdir allowing more easy migration.

* Is there need to introduce a separate environment variable when `THESEUS_CONFIG_DIR` does essentially the same thing?

Will research that, I didnt know that variable exist, its cool to know that :)

MiguVT added 4 commits August 17, 2025 16:24
Refactors portable mode detection and initialization.

- Simplifies portable mode enablement to rely solely on the presence of `portable.txt`.
- Removes environment variable method for enabling portable mode.
- Ensures portable environment is set up as early as possible in the application lifecycle.
- Sets `THESEUS_CONFIG_DIR` environment variable when in portable mode, ensuring consistent data directory usage across components.
- Updates documentation to reflect the simplified portable mode activation.
- Fixes window state location when using portable mode.
Refactors portable mode detection to use a dedicated command and improves reliability.

This change introduces a `is_portable_mode` command in Rust to check for portable mode, replacing the previous inline check.
It also fixes an issue where the portable mode was not being correctly detected in the frontend, potentially leading to window state saving in portable mode. The Vue component now calls the new tauri command.
@MiguVT
Copy link
Author

MiguVT commented Aug 17, 2025

Marking as ready for review.

  • Portable mode is now robustly detected via Tauri backend (is_portable_mode command).
  • Window state saving and plugin logic are fully portable-aware.
  • All error handling and edge cases are covered.

Ready for feedback! :D

@MiguVT MiguVT marked this pull request as ready for review August 17, 2025 18:47
@MiguVT
Copy link
Author

MiguVT commented Aug 20, 2025

Hi, any update? @AlexTMjugador @Gaming32 ????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Relates to Modrinth App enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants