Skip to content

Making Preferences standalone #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Stefterv opened this issue May 16, 2025 · 6 comments · May be fixed by #1130
Open

Making Preferences standalone #1104

Stefterv opened this issue May 16, 2025 · 6 comments · May be fixed by #1130
Assignees

Comments

@Stefterv
Copy link
Collaborator

For the migration of the internal Gradle runner, I'm running into trouble with the Preferences class.

Problem description

Currently Preferences is tightly coupled with the PDE through the use of the Base, Messages, Toolkit and Language classes. These classes do not operate outside of the PDE, thus not allowing reuse of the Preferences class in other modules within Processing (e.g. Gradle plugins, Processing CLI, Processing pre-processor, etc.)

Proposed solution

Migrate the Preferences class to a standalone version.

  • Completing the migration of Preferences to be standalone from :app by moving it to a :app:utils module.
  • Move functionality dependent on :app into a AppPreferences class or into other relevant areas of the PDE
  • Adding callback events/listeners when a preference changes
  • Tests that will declare and test the functionality of Preferences, a few of the top of my head would be:
    • Test if the defaults are loaded and saved without creating changes
    • Test if \ work
    • Test if the preferences file is created if it does not yet exist
    • Any other tests to make sure we have backwards compatibility
  • A Github Action that will run the Tests on all supported platforms
  • Bonus: Removing the dependency on core

Steps taken so far

  • In IntelliJ IDEA create a new module utils in the app folder with the following settings (see image below)
  • Add package processing.utils to the newly created module
  • Refactoring the class by right clicking the Prefrences class and Refactor -> Move Class... and moving it to the newly created processing.utils package
Image
@Stefterv
Copy link
Collaborator Author

@AhmedMagedC is this something you would be interested in working on?

@AhmedMagedC
Copy link

@Stefterv Thanks for suggesting me to implement this, and yes i'm interested into working on it

unfortunately though im currently busy with college having practical exams this week, i can start working on it once i finish

@AhmedMagedC
Copy link

Hi @Stefterv , I would like to show my approach to make sure I'm moving in the right direction.

I will move Preferences class into :app:util module inside processing.utils package, while keeping AppPreferences class inside :app module which will extend Preferences main functionalities like load(), get(), set() and then provide functionalities that depend on :app like setFont(), getFont()

but for the Preferneces class, getting the preferences.txt file is platform-dependent so i thought of creating processing.utils.platform package to override getSettingFolder() for each platform (which is already implemented in processing.app.platform package i will just copy it)

and for things like getting the default.txt file or ,setting.txt (for portable versions), I can use built-in JAR Resources System instead of the deprecated Platform.getContentFile() which will make it independent of app.Base and app.Platform classes

so what do you think?

@Stefterv
Copy link
Collaborator Author

Stefterv commented May 21, 2025

Hi @AhmedMagedC, Thank you for writing down the approach.

I will move Preferences class into :app:util module inside processing.utils package, while keeping AppPreferences class inside :app module which will extend Preferences main functionalities like load(), get(), set() and then provide functionalities that depend on :app like setFont(), getFont()

and for things like getting the default.txt file or ,setting.txt (for portable versions), I can use built-in JAR Resources System instead of the deprecated Platform.getContentFile() which will make it independent of app.Base and app.Platform classes

Perfect 👍

but for the Preferneces class, getting the preferences.txt file is platform-dependent so i thought of creating processing.utils.platform package to override getSettingFolder() for each platform (which is already implemented in processing.app.platform package i will just copy it)

Let's use the existing Platform for now, I'd rather avoid duplicating code where we can. Then we create a new issue for the Platform class similar to this one after creating the new Preferences is finished.

Thank you for catching the dependency on Platform early on!

@AhmedMagedC
Copy link

Hi @Stefterv , so i managed to migrate the preference class to utils module and it properly compiles and runs

i took a different approach than using the Platform class because that made cyclic dependency problem (utils depend on app, app depends on utils)

i wanna make a PR so you and other devs can review the work done and prompts changes if needed

also note that i didnt yet work on the rest of requirements, i will once the migration alone makes sense

@Stefterv
Copy link
Collaborator Author

Stefterv commented Jun 1, 2025

Hi @AhmedMagedC, thanks so much for the update and the work you’ve done so far! Please go ahead and open a draft PR. We can take a look and continue the discussion there.

@AhmedMagedC AhmedMagedC linked a pull request Jun 1, 2025 that will close this issue
3 tasks
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 a pull request may close this issue.

2 participants