State persistence/serialization support#14
Open
mitchcapper wants to merge 1 commit intoGeorgeEnglezos:mainfrom
Open
State persistence/serialization support#14mitchcapper wants to merge 1 commit intoGeorgeEnglezos:mainfrom
mitchcapper wants to merge 1 commit intoGeorgeEnglezos:mainfrom
Conversation
Large refactor to reduce duplicated code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depending on if/when this is merged it will generate merge conflicts with my others for sure. I will resolve in whatever order merged.
This persists the users last state back into the app on start. This also 'fixes' the issue where switching tabs reset all the options selected.
I say 'fixes' as the code specifically seemed to call
commandService.resetToDefaults()which would seem to imply I meant to reset any time you switched tabs?This is largely handed off to AI for code generation and I can't say I am fluent enough with flutter coding to see if there are any pitfalls with this approach.
Overall, while this changes a lot of files, it is a significant reduction in line counts (+914 -1366 net change -452 lines) and removes many places where options were duplicated. While I am always a fan of write once this was done at the same time as this serialization PR because the serialization was going to result in much more boilerplate code otherwise.
I had been working on a DEVELOPERS.md file it is included here due to the notes about the new freeze/serialization requirements before building.
Overview
%APPDATA%/ScrcpyGui/scrcpy_options_state.jsonvia a 4-second debounced timer, restoring on app startup.AudioOptions,GeneralCastOptions, etc.) converted to immutable frozen value objects (finalfields,constconstructors,copyWith) with@JsonSerializable()code-gen, wrapped in a top-levelOptionsBundle. This was required to be able to automatically serialize the members and handle when they were missing in the json.Consumer<CommandBuilderService>(rebuilds everything) tocontext.select(rebuilds only when the specific options object changes), significantly reducing unnecessary widget rebuilds.getApplicationSupportDirectory()+ directory-creation logic inSettingsService,CommandsService, and the newOptionsStateServicereplaced with a single cachedAppPaths.getBasePath()utility. The getApplicationSupportDirectory() looks like it should result in the exact same directory for windows/macos that we were manually computing before.resetToDefaults()call on tab switch that was wiping user configuration;Notes
dart run build_runner build --delete-conflicting-outputsto regeneratescrcpy_options.g.dart. The app will not compile without it.flushPendingSave()to mitigate this.loadOptionsFromJsonclearsScreenRecordingOptionsbecause the output filename contains a session-specific timestamp that would be stale.window_managerdependency: TheonWindowClosehook relies onWindowListenerfromwindow_manager(already a project dependency) — no new native dependency added.