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:
committed by
Jonas Platte
parent
541c0ef559
commit
6363cd5902
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user