Skip to content

Commit

Permalink
Use tokio executor for uniffi async (#408)
Browse files Browse the repository at this point in the history
## Type of change
```
- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective
When testing the username generator using uniffi, I noticed that uniffi
was using it's own async executor by default, while reqwest was
expecting tokio, which caused errors.

I've changed all uniffi exported async functions to use tokio by
default, to avoid these issues.
  • Loading branch information
dani-garcia authored Dec 11, 2023
1 parent 0a31e05 commit e1bf48b
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 12 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{error::Result, Client};
#[derive(uniffi::Object)]
pub struct ClientAuth(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientAuth {
/// **API Draft:** Calculate Password Strength
pub async fn password_strength(
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{error::Result, Client};
#[derive(uniffi::Object)]
pub struct ClientCrypto(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientCrypto {
/// Initialization method for the user crypto. Needs to be called before any other crypto operations.
pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{error::Result, Client};
#[derive(uniffi::Object)]
pub struct ClientPlatform(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientPlatform {
/// Fingerprint
pub async fn fingerprint(&self, req: FingerprintRequest) -> Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-uniffi/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{error::Result, Client};
#[derive(uniffi::Object)]
pub struct ClientGenerators(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientGenerators {
/// **API Draft:** Generate Password
pub async fn password(&self, settings: PasswordGeneratorRequest) -> Result<String> {
Expand Down Expand Up @@ -40,7 +40,7 @@ impl ClientGenerators {
#[derive(uniffi::Object)]
pub struct ClientExporters(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientExporters {
/// **API Draft:** Export user vault
pub async fn export_vault(
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Client, Result};
#[derive(uniffi::Object)]
pub struct ClientCiphers(pub Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientCiphers {
/// Encrypt cipher
pub async fn encrypt(&self, cipher_view: CipherView) -> Result<Cipher> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Client, Result};
#[derive(uniffi::Object)]
pub struct ClientCollections(pub Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientCollections {
/// Decrypt collection
pub async fn decrypt(&self, collection: Collection) -> Result<CollectionView> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Client, Result};
#[derive(uniffi::Object)]
pub struct ClientFolders(pub Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientFolders {
/// Encrypt folder
pub async fn encrypt(&self, folder: FolderView) -> Result<Folder> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod sends;
#[derive(uniffi::Object)]
pub struct ClientVault(pub(crate) Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientVault {
/// Folder operations
pub fn folders(self: Arc<Self>) -> Arc<folders::ClientFolders> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/password_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Client, Result};
#[derive(uniffi::Object)]
pub struct ClientPasswordHistory(pub Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientPasswordHistory {
/// Encrypt password history
pub async fn encrypt(&self, password_history: PasswordHistoryView) -> Result<PasswordHistory> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/vault/sends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Client, Result};
#[derive(uniffi::Object)]
pub struct ClientSends(pub Arc<Client>);

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl ClientSends {
/// Encrypt send
pub async fn encrypt(&self, send: SendView) -> Result<Send> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sha1 = ">=0.10.5, <0.11"
sha2 = ">=0.10.6, <0.11"
subtle = ">=2.5.0, <3.0"
thiserror = ">=1.0.40, <2.0"
uniffi = { version = "=0.25.2", optional = true }
uniffi = { version = "=0.25.2", optional = true, features = ["tokio"] }
uuid = { version = ">=1.3.3, <2.0", features = ["serde"] }

[dev-dependencies]
Expand Down

0 comments on commit e1bf48b

Please sign in to comment.