Refactor about:torconnects relation to TorConnectParent
When looking at the code for aboutTorConnect.js
and TorConnectParent.jsm
for #41608 (closed) and #41384 I realised that they have a strange mix of signalling.
- Each "about:torconnect" tab listens for "torconnect:state-change" from their
TorConnectParent
, which is passed on fromTorConnect
. - Each "about:torconnect" tab sends events to
TorConnectParent
that are essentially just passed on toTorConnect
to change its state. - Each "about:torconnect" tab regularly sends out "torconnect:set-ui-state" to their
TorConnectParent
, and then this state is saved for all instances ofTorConnectParent
. This state is only read by newly created "about:torconnect" tabs via "torconnect:get-init-args". - There are 3 actions that are not linked to the
TorConnect
state, which sends out "broadcast-user-action" to theirTorConnectParent
, which then broadcasts this to all instances ofTorConnectParent
, and each "about:torconnect" then receives "torconnect:user-action" to update their state.
I think basically 1 and 2 are there to interact with TorConnect
, and as a side effect if you have multiple "about:torconnect" tabs they will mostly stay in sync. 3 and 4 seem to be added to fill in the gaps to keep each tab absolutely in sync.
Since we want this tight synchronisation between each "about:torconnect" tab, I think it would make more sense to shift all the UI state information to the TorConnectParent
class, which is shared by each instance. I.e. drop aboutTorConnect.uiState
and shift the control out of the child and into the parent. And the relation would be:
- Each "about:torconnect" tab listens to a state change event, and it tells the tab all the information it needs to "paint" itself. All instances receive this at the same time.
- Each "about:torconnect" tab sends user interactions (clicking a button, selecting a country, etc) to the
TorConnectParent
.
NOTE: things like user focus should be managed independently by each "about:torconnect" tab.
This area might need some refactoring anyway to address #41384 so I might do this just before, or in combination.