widget: extract capability negotiation into fn

We will need to re-use it when processing the `ContentLoaded` message
from a widget.
This commit is contained in:
Daniel Abramov
2023-10-18 11:57:49 +02:00
committed by Jonas Platte
parent 541c0ef559
commit 6363cd5902
+18 -15
View File
@@ -75,21 +75,7 @@ impl WidgetMachine {
};
if !init_on_content_load {
machine
.send_to_widget_request(RequestPermissions {})
// TODO: Each request can actually fail here, take this into an account.
.then(|desired_permissions, machine| {
machine
.send_matrix_driver_request(AcquirePermissions {
desired_permissions: desired_permissions.clone(),
})
.then(|granted_permissions, machine| {
machine.send_to_widget_request(NotifyPermissionsChanged {
approved: granted_permissions,
requested: desired_permissions,
});
})
});
machine.negotiate_capabilities();
}
(machine, actions_receiver)
@@ -249,6 +235,23 @@ impl WidgetMachine {
trace!("No response_fn registered");
}
}
fn negotiate_capabilities(&mut self) {
self.send_to_widget_request(RequestPermissions {})
// TODO: Each request can actually fail here, take this into an account.
.then(|desired_permissions, machine| {
machine
.send_matrix_driver_request(AcquirePermissions {
desired_permissions: desired_permissions.clone(),
})
.then(|granted_permissions, machine| {
machine.send_to_widget_request(NotifyPermissionsChanged {
approved: granted_permissions,
requested: desired_permissions,
});
})
});
}
}
type ToWidgetResponseFn = Box<dyn FnOnce(Box<RawJsonValue>, &mut WidgetMachine) + Send>;