I don't understand how this fixes the issue. By adding an early return to the inner if and moving it out the top level of the function, this would mean the following:
- If the registered service is one of the watched services but we don't (yet) have both services registered, the behavior is the same as before this patch.
- If the registered service is none of the watched services, then
setTlpInstalled()gets called where it didn't before. This shouldn't happen though, as we're not connecting any other watchers or signals? Also setting TLP as installed seems like a random unrelated behavior if the service isn't even relevant. - If no service gets registered, this code doesn't get called anyway.
Please explain what I'm missing here.
In the interest of code cleanliness as well as actual correctness, I wouldn't mind a patch that moves this check out of onServiceRegistered. In fact, I guess it could go into the constructor itself: First, to initialize it to the correct value (in case powerdevil's D-Bus service never appears) and second, to update it whenever isPowerProfileDaemonInstalledChanged is emitted (making sure to set m_isTlpInstalled = false if m_isPowerProfileDaemonInstalled == true).
Given that we have all the state necessary to make this update at any time, we could change setTlpInstalled to updateTlpInstalled and always call that one... ideally by connecting it to the isPowerProfileDaemonInstalledChanged signal.
An even better patch might be to allow both m_isPowerProfileDaemonInstalled and m_isTlpInstalled to be true at the same time, with the QML instead taking care of the mutual exclusion logic. But I guess we don't have to do this here.