Repository navigation
Conversation
4ab7183 to
d041db5
Compare
catilac
left a comment
There was a problem hiding this comment.
left some questions! sorry it's taken so long to get to this.
this is a VERY big patch and it will affect a lot of users if it goes out so we need to be very careful. we will need more folks to test and review.
| // Now override the keys with any platform-specific defaults we've found. | ||
| for (String key : platformSpecific.keySet()) { | ||
| table.put(key, platformSpecific.get(key)); | ||
| } |
There was a problem hiding this comment.
was this moved somewhere? or just deleted?
There was a problem hiding this comment.
@catilac It was moved, not deleted. The whole load() method, including this loop, is now in processing.utils.Preferences in app/utils, and isPlatformSpecific() moved with it, just below. The logic is the same. Only two calls changed, so that app:utils doesn't need core: PApplet.loadStrings(input) is now a BufferedReader reading UTF-8, which is what loadStrings does internally, and PConstants.platformNames[PApplet.platform] is now Platform.getName() with a local copy of the platform names. I also ran the old and new load() side by side on defaults.txt and on a file with edge cases (comments, backslashes, platform-specific keys, values containing =), and they produce the same keys and values. testPlatformSpecificKeys in PreferencesTest covers this path.
|
|
||
| /* | ||
| supposedly not needed, because anything besides 'true' | ||
| (ignoring case) will just be false.. so if malformed -> false | ||
| if (value == null) return defaultValue; | ||
|
|
||
| try { | ||
| return (new Boolean(value)).booleanValue(); | ||
| } catch (NumberFormatException e) { | ||
| System.err.println("expecting an integer: " + attribute + " = " + value); | ||
| } | ||
| return defaultValue; | ||
| */ |
There was a problem hiding this comment.
I need help understanding why this was removed
There was a problem hiding this comment.
@catilac Added this back in. Since I was rewriting Preferences, I ended up cleaning this up because it was commented out and not used. My bad, I'll leave commented-out code alone when it's there for information and doesn't affect the change I'm making. I also restored the old init() signature comment that I'd removed the same way, so getBoolean() and the top of init() now match main.
The bundled defaults are loaded from the classpath, so shipping them inside the app:utils jar lets the standalone Preferences (upcoming) resolve its own defaults without the app being present. All existing readers load the file via getResourceAsStream() and are unaffected.
storage half of app.Preferences: defaults from classpath, load/save, platform-specific keys. throws instead of showing dialogs; init split so the app can insert its own defaults between stages.
app keeps fonts/colors, dialogs, and proxy/native-chooser side effects in their original startup order; loading and saving now go through the standalone class, with the settings folder passed in from Base.
replaces the per-call file re-read (platform charset, no defaults) with the standalone class, so the preprocessor resolves preferences from the bundled defaults even without a preferences.txt.
set()/unset() notify registered listeners when a value actually changes; loading stays silent.
covers defaults loading, first-run creation, save/load round trips, the preferences.file override, platform-specific keys, backslash normalization, getInteger fallback, sorted save, the 3.x sketchbook migration, and the change listener contract. adds a package-private reset() for test isolation.
found while smoke-testing the utils jar standalone: the PDE and the unit tests both pre-create the settings folder, but a standalone caller passing a new location would fail on the first save.
loadUserPrefs() saved preferences.txt itself on a first run or after a 3.x sketchbook migration, so a failed save surfaced through the app's 'Error reading preferences' handler, which exits. On main that case is only a 'Could not save' warning. loadUserPrefs() now only reads and reports whether a save is needed. The standalone init() and the app's init() each do the save, so the app goes through its own save() and shows the warning again.
The old init() signature comment and the block in getBoolean() were dropped as cleanup that does not belong in this change. Put them back as they are on main.
d041db5 to
c9238e7
Compare
c9238e7 to
ced8f93
Compare
|
Updates:
|
Resolves #1104
Splits
processing.app.Preferencesinto a standalone storage class (processing.utils.Preferencesinapp:utils) and an app-side facade, so preferences work in contexts without the PDE: the Gradle plugin, CLI tools, and the preprocessor, as motivated in #1104 and the standalone-CLI discussion in #1522.Changes
processing.utils.Preferences: the storage half of the old class. Bundled defaults from the classpath, reading/writingpreferences.txt, platform-specific keys, and the 3.x sketchbook migration. JDK-only (nocore, no AWT/Swing). Errors are reported by throwingIOExceptionwith the cause chained instead of showing dialogs, so callers decide how to react.processing.app.Preferencesbecomes a facade: keeps fonts/colors,Messagesdialogs, and the proxy/native-chooser side effects in their original startup order, delegating storage to the utils class. No call sites change (~246 acrossappandjava).defaults.txtmoves intoapp:utilsresources: the published utils jar now carries its own defaults and works standalone. All readers (including the ComposePreferencesProvider) load it viagetResourceAsStream, so nothing else changes.Platform.getName(): platform name for preference-key suffixes, mirroringPConstants.platformNames. The four strings are part of the preferences file format, so a small mirror avoids givingapp:utilsacoredependency.addChangeListener/removeChangeListeneron the utils class. Fires only on real changes fromset()/unset(); bulk loading is silent; a throwing listener can't block the change or other listeners. No consumers wired yet. First candidates are PDE components that currently re-read on window close, and possibly converging with the Compose side'sPreferencesEventslater.java:preprocessor'sprocessing.app.Preferencesused to re-readpreferences.txton every call with the platform charset and had no defaults, so a standalone preprocessor could crash ongetInteger("editor.tabs.size")with no prefs file present. It now resolves from the bundled defaults. Happy to split this commit into a follow-up PR if preferred.Design notes
:app(Base/Platform) whilePreferenceswas moving to:app:utils, so each module needed the other. Since then, RefactoringSketchExceptionto be available outside ofapp#1196 createdapp:utilsand Rewrite of theBase.getSettingsFolder()andPlatform.getSettingsFolder()#1335 moved settings-folder resolution intoprocessing.utils.Settings, so the knowledgePreferencesneeds now lives below it and all dependency arrows point one way. This PR adds no new dependencies on top of that: the remaining app couplings are handled by throwing instead of dialogs, and by passing the settings folder in as an argument (loadUserPrefs(File)), withSettings.getFolder()and theprocessing.app.preferences.filesystem property as fallbacks for standalone use.run.window.bgcolor, CJK input-method support) between loading the bundled defaults and the user's file, so init is split intoloadDefaults()/loadUserPrefs(File), withinit(File)composing them for standalone consumers. This keeps the PDE's startup order exactly as onmain.extendsrelationship would let calls through the parent type silently skip the app's error dialogs. The facade delegates explicitly; the cost is fully-qualified names (Java can't alias same-named imports), which was preferred over renaming a class and churning every reference.preferences.txtsurfaces as an exception (the PDE shows the same error dialog as before), and the utils class won't run the sketchbook migration/save over a file it couldn't read.Builds on the direction @AhmedMagedC explored in #1209, thank you for the groundwork! Rebuilt on today's
mainsince that branch predates theapp:utilsmodule: delegation instead of static inheritance, chainedIOExceptions instead of a custom exception, nocoredependency, and defaults bundled in the utils jar.Tests
app:utils(PreferencesTest): default loading, file creation, and backwards compatibility (3.x sketchbook migration, backslash normalization, platform-suffix keys), plus save/load round trips, thepreferences.fileoverride,getIntegerfallback, sorted save, and the listener contract.app:utils,app(incl.PreferencesKtTest, so the Compose provider still finds the moveddefaults.txt), andjava(incl.ParserTeststhrough the preprocessor).Checklist