frontend: Fix OAuth and dock state save corruption#13445
Open
PatTheMav wants to merge 1 commit into
Open
Conversation
When the app is quit on macOS, the underlying process is either triggered by an application-level "Quit" event or by a main window "close" event. If the application-level "Quit" event is the trigger, OBSBasic::saveAll is called twice: First by Qt's session manager (via OBSApp::commitData) and another time by the main window's close event handled by OBSBasic::closeWindow. However if the main window is closed first (and is the first to call "saveAll") the underlying OAuth data object is destroyed after the data has been saved. When the second "saveAll" call takes place, it encounters a "nullptr" for the auth object, which makes "Auth::Save" effectively remove any OAuth configuration from the settings file (undoing prior work). At the other end, if the application quits first, some dock windows might have been explicitly closed by Qt before the main window is closed and thus the second call to "saveAll" will overwrite valid browser dock state data with incomplete data (any dock that has been closed by Qt before will not be present in that data). Wrapping the code responsible for saving OAuth and browser dock state data in a "std::call_once" block should ensure that this data is only written once and by whoever gets to call "saveAll" first (at which point state data is still considered "complete").
7 tasks
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.
Description
Wraps functionality that saves OAuth data and browser dock state in a
std::call_onceblock to ensure that regardless of how oftenOBSBasic::saveAllis called the data is only saved once and partial data does not overwrite the config values on consecutive calls (at which the state of the OAuth data and browser docks cannot be considered "complete" anymore).Motivation and Context
When the app is quit on macOS, the underlying process is either triggered by an application-level "Quit" event or by a main window "close" event.
If the application-level "Quit" event is the trigger,
OBSBasic::saveAllis called twice:OBSApp::commitData).OBSBasic::closeWindow.However if the main window is closed first (and is the first to call "saveAll") the underlying OAuth data object is destroyed after the data has been saved. When the second "saveAll" call takes place, it encounters a
nullptrfor the auth object, which makesAuth::Saveeffectively remove any OAuth configuration from the settings file (undoing prior work).At the other end, if the application quits first, some dock windows might have been explicitly closed by Qt before the main window is closed and thus the second call to
saveAllwill overwrite valid browser dock state data with incomplete data (any dock that has been closed by Qt before will not be present in that data).Wrapping the code responsible for saving OAuth and browser dock state data in a
std::call_onceblock should ensure that this data is only written once and by whoever gets to callsaveAllfirst (at which point state data is still considered "complete").Fixes #13440
Fixes #13099
How Has This Been Tested?
Tested on macOS 26 by having a YouTube service connection active and several browser and non-browser docks detached and placed at specific positions on screen.
Terminated OBS by menu item, dock menu, and by closing the main window, confirmed that both service connection and dock state and position were correctly restored when OBS was relaunched.
Types of changes
Checklist: