Draft: status/keyboard: Activate source completely prior to returning inputsource
When commit ce89b15b made the code async, it did not only delay releasing the keyboard until after the engine has been updated, but also the following code that updates the current input source.
One result is that the current source is now initialized later, which breaks any code that relies on the source being set immidiately after calling activateInuptSource() as this function is now async.
This affects the login screen in particular (which uses different InputSourceSettings
than the regular session): It fails to come up entirely if the OSK is enabled.
This current MR uses promises with async and await, to detect that async activateInputSource() has completed setting the source.
This MR also leverages an async getter function.
While the above function is executing, an await statement prevents updating any other caller asking for the currentInputSource or inputSources from proceeding with incorrect information and any subsequent execution till the function is completed and sources set.
This could also potentially prevent any race condition and timing issues from returning the wrong currentInputSource or inputsource.
Only when it is done, is the await realease and the currentInputSource or the inputSources returned from the InputSourceManager to allow exection of subsequent code.
It insures, using async code with await, that-
-
status/keyboard will return a currentSource only after at least one source is activated.
-
status/keyboard will return a currentSource only after activation is fully complete and not during activation.
-
The above insure that a currentSource value with null is never returned.
-
The above Insures there will never be a race condition. The problem, albeit superficially, can be fixed by code execution order of sync code in the async function activateInputSource(), I believe that is not the comprehensive complete solution. It is better to return currentSource, only after all the code in the async function fully completes, and everything is set, and not prior to that. It also insures that changing any execution order in the function will not cause this problem in future.
My proposed fix insures that currentSource is only returned after activateInputSource() is assuredly complete.
-
get currentSource and get inputGroup are now returned in an async fashion. The advantage of doing this is, that the code, calling for these values, calls them with await, and so-
a. All execution is safely paused by the await till the values are completely resolved. At that time execution resumes normally. There is no race. This is efficient use of async await, and continues evolution to this code structure in gnome-shell instead of callbacks.
b. Code cannot continue to execute with an invalid value that can cause crashes.
b. The calling code is assured that a valid value will be returned, and does not have to check for null.
Closes: #7912 (closed)