use crate::{
api::Config,
client::Client,
errors::{ConnectionError, RemoteError},
Workspace,
};
use jni_toolbox::jni;
#[jni(package = "mp.code", class = "Client")]
fn connect(config: Config) -> Result<Client, ConnectionError> {
super::tokio().block_on(Client::connect(config))
}
#[jni(package = "mp.code", class = "Client")]
fn current_user(client: &mut Client) -> crate::api::User {
client.current_user().clone()
}
#[jni(package = "mp.code", class = "Client")]
fn attach_workspace(client: &mut Client, workspace: String) -> Result<Workspace, ConnectionError> {
super::tokio().block_on(client.attach_workspace(workspace))
}
#[jni(package = "mp.code", class = "Client")]
fn create_workspace(client: &mut Client, workspace: String) -> Result<(), RemoteError> {
super::tokio().block_on(client.create_workspace(workspace))
}
#[jni(package = "mp.code", class = "Client")]
fn delete_workspace(client: &mut Client, workspace: String) -> Result<(), RemoteError> {
super::tokio().block_on(client.delete_workspace(workspace))
}
#[jni(package = "mp.code", class = "Client")]
fn invite_to_workspace(
client: &mut Client,
workspace: String,
user: String,
) -> Result<(), RemoteError> {
super::tokio().block_on(client.invite_to_workspace(workspace, user))
}
#[jni(package = "mp.code", class = "Client")]
fn fetch_owned_workspaces(client: &mut Client) -> Result<Vec<String>, RemoteError> {
super::tokio().block_on(client.fetch_owned_workspaces())
}
#[jni(package = "mp.code", class = "Client")]
fn fetch_joined_workspaces(client: &mut Client) -> Result<Vec<String>, RemoteError> {
super::tokio().block_on(client.fetch_joined_workspaces())
}
#[jni(package = "mp.code", class = "Client")]
fn active_workspaces(client: &mut Client) -> Vec<String> {
client.active_workspaces()
}
#[jni(package = "mp.code", class = "Client")]
fn leave_workspace(client: &mut Client, workspace: String) -> bool {
client.leave_workspace(&workspace)
}
#[jni(package = "mp.code", class = "Client")]
fn get_workspace(client: &mut Client, workspace: String) -> Option<Workspace> {
client.get_workspace(&workspace)
}
#[jni(package = "mp.code", class = "Client")]
fn refresh(client: &mut Client) -> Result<(), RemoteError> {
super::tokio().block_on(client.refresh())
}
#[jni(package = "mp.code", class = "Client")]
fn free(input: jni::sys::jlong) {
let _ = unsafe { Box::from_raw(input as *mut Client) };
}