decouple App god object into controllers with proper interface boundaries#8
Merged
decouple App god object into controllers with proper interface boundaries#8
Conversation
…ispatch and extract command helper
…ction prerequisite
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.
right, so this is a fairly chunky refactoring that's been on the cards for a while. the App struct had grown into a proper god object, methods all over the place across half a dozen files, doing everything from GUI management to command execution to studio process handling. it was getting unwieldy.
here's roughly what happened.
first pass was tidying up the foundations. replaced concrete type assertions in keybinding.go with proper interface dispatch (IListContext, IScrollableContext, ITabbedContext). consolidated duplicated style and frame constants that were copy-pasted all over the shop into a single theme.go. got rid of a load of dead ANSI styling code in text_style.go that nobody was calling. also centralised the OnFocus/OnBlur logic into BaseContext rather than having it repeated in every context file. on top of that, extracted a runStreamingCommand helper to cut out the boilerplate that was showing up in every controller method.
then came the interface work. implemented IPopupHandler and IGuiCommon on App. these were defined in types but never actually wired up. this gave us a clean contract for controllers to depend on rather than reaching into App internals directly.
with that in place, extracted four controllers into their own types: MigrationsController, GenerateController, StudioController, and ClipboardController. zero cross-controller dependencies, which was nice. studio's process state (studioCmd, studioRunning) moved out of App entirely. controllers talk to App through IControllerHost, no type assertions needed.
along the way, caught and fixed a couple of thread safety issues. LogAction was being called outside the UI thread, and there was a missing finishCommand fallback path that could've left the app stuck in "command running" state forever. also made studioRunning atomic for good measure.
lastly, cleaned up a dead translation key that was left behind from the old type assertion pattern.