Skip to content

Commit

Permalink
Re-generate electron&web bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Sep 21, 2024
1 parent ddb5fd2 commit b57bae0
Show file tree
Hide file tree
Showing 4 changed files with 521 additions and 0 deletions.
56 changes: 56 additions & 0 deletions bindings/electron/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export interface DeviceInfo {
}


export interface Eula {
url: string
updatedOn: number
}


export interface HumanHandle {
email: string
label: string
Expand Down Expand Up @@ -445,6 +451,30 @@ export type ClaimerRetrieveInfoError =
| ClaimerRetrieveInfoErrorOffline


// ClientAcceptEulaError
export interface ClientAcceptEulaErrorEulaMismatch {
tag: "EulaMismatch"
error: string
}
export interface ClientAcceptEulaErrorInternal {
tag: "Internal"
error: string
}
export interface ClientAcceptEulaErrorNoEula {
tag: "NoEula"
error: string
}
export interface ClientAcceptEulaErrorOffline {
tag: "Offline"
error: string
}
export type ClientAcceptEulaError =
| ClientAcceptEulaErrorEulaMismatch
| ClientAcceptEulaErrorInternal
| ClientAcceptEulaErrorNoEula
| ClientAcceptEulaErrorOffline


// ClientCancelInvitationError
export interface ClientCancelInvitationErrorAlreadyDeleted {
tag: "AlreadyDeleted"
Expand Down Expand Up @@ -602,6 +632,25 @@ export type ClientEvent =
| ClientEventWorkspacesSelfListChanged


// ClientGetEulaError
export interface ClientGetEulaErrorInternal {
tag: "Internal"
error: string
}
export interface ClientGetEulaErrorNoEula {
tag: "NoEula"
error: string
}
export interface ClientGetEulaErrorOffline {
tag: "Offline"
error: string
}
export type ClientGetEulaError =
| ClientGetEulaErrorInternal
| ClientGetEulaErrorNoEula
| ClientGetEulaErrorOffline


// ClientGetUserDeviceError
export interface ClientGetUserDeviceErrorInternal {
tag: "Internal"
Expand Down Expand Up @@ -2104,6 +2153,10 @@ export function claimerUserInitialDoWaitPeer(
canceller: number,
handle: number
): Promise<Result<UserClaimInProgress1Info, ClaimInProgressError>>
export function clientAcceptEula(
client: number,
eula_updated_on: number
): Promise<Result<null, ClientAcceptEulaError>>
export function clientCancelInvitation(
client: number,
token: string
Expand All @@ -2117,6 +2170,9 @@ export function clientCreateWorkspace(
client: number,
name: string
): Promise<Result<string, ClientCreateWorkspaceError>>
export function clientGetEula(
client: number
): Promise<Result<Eula, ClientGetEulaError>>
export function clientGetUserDevice(
client: number,
device: string
Expand Down
227 changes: 227 additions & 0 deletions bindings/electron/src/meths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,55 @@ fn struct_device_info_rs_to_js<'a>(
Ok(js_obj)
}

// Eula

#[allow(dead_code)]
fn struct_eula_js_to_rs<'a>(
cx: &mut impl Context<'a>,
obj: Handle<'a, JsObject>,
) -> NeonResult<libparsec::Eula> {
let url = {
let js_val: Handle<JsString> = obj.get(cx, "url")?;
js_val.value(cx)
};
let updated_on = {
let js_val: Handle<JsNumber> = obj.get(cx, "updatedOn")?;
{
let v = js_val.value(cx);
let custom_from_rs_f64 = |n: f64| -> Result<_, &'static str> {
libparsec::DateTime::from_timestamp_micros((n * 1_000_000f64) as i64)
.map_err(|_| "Out-of-bound datetime")
};
match custom_from_rs_f64(v) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
Ok(libparsec::Eula { url, updated_on })
}

#[allow(dead_code)]
fn struct_eula_rs_to_js<'a>(
cx: &mut impl Context<'a>,
rs_obj: libparsec::Eula,
) -> NeonResult<Handle<'a, JsObject>> {
let js_obj = cx.empty_object();
let js_url = JsString::try_new(cx, rs_obj.url).or_throw(cx)?;
js_obj.set(cx, "url", js_url)?;
let js_updated_on = JsNumber::new(cx, {
let custom_to_rs_f64 = |dt: libparsec::DateTime| -> Result<f64, &'static str> {
Ok((dt.as_timestamp_micros() as f64) / 1_000_000f64)
};
match custom_to_rs_f64(rs_obj.updated_on) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
});
js_obj.set(cx, "updatedOn", js_updated_on)?;
Ok(js_obj)
}

// HumanHandle

#[allow(dead_code)]
Expand Down Expand Up @@ -2735,6 +2784,37 @@ fn variant_claimer_retrieve_info_error_rs_to_js<'a>(
Ok(js_obj)
}

// ClientAcceptEulaError

#[allow(dead_code)]
fn variant_client_accept_eula_error_rs_to_js<'a>(
cx: &mut impl Context<'a>,
rs_obj: libparsec::ClientAcceptEulaError,
) -> NeonResult<Handle<'a, JsObject>> {
let js_obj = cx.empty_object();
let js_display = JsString::try_new(cx, &rs_obj.to_string()).or_throw(cx)?;
js_obj.set(cx, "error", js_display)?;
match rs_obj {
libparsec::ClientAcceptEulaError::EulaMismatch { .. } => {
let js_tag = JsString::try_new(cx, "ClientAcceptEulaErrorEulaMismatch").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
libparsec::ClientAcceptEulaError::Internal { .. } => {
let js_tag = JsString::try_new(cx, "ClientAcceptEulaErrorInternal").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
libparsec::ClientAcceptEulaError::NoEula { .. } => {
let js_tag = JsString::try_new(cx, "ClientAcceptEulaErrorNoEula").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
libparsec::ClientAcceptEulaError::Offline { .. } => {
let js_tag = JsString::try_new(cx, "ClientAcceptEulaErrorOffline").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
}
Ok(js_obj)
}

// ClientCancelInvitationError

#[allow(dead_code)]
Expand Down Expand Up @@ -3422,6 +3502,33 @@ fn variant_client_event_rs_to_js<'a>(
Ok(js_obj)
}

// ClientGetEulaError

#[allow(dead_code)]
fn variant_client_get_eula_error_rs_to_js<'a>(
cx: &mut impl Context<'a>,
rs_obj: libparsec::ClientGetEulaError,
) -> NeonResult<Handle<'a, JsObject>> {
let js_obj = cx.empty_object();
let js_display = JsString::try_new(cx, &rs_obj.to_string()).or_throw(cx)?;
js_obj.set(cx, "error", js_display)?;
match rs_obj {
libparsec::ClientGetEulaError::Internal { .. } => {
let js_tag = JsString::try_new(cx, "ClientGetEulaErrorInternal").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
libparsec::ClientGetEulaError::NoEula { .. } => {
let js_tag = JsString::try_new(cx, "ClientGetEulaErrorNoEula").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
libparsec::ClientGetEulaError::Offline { .. } => {
let js_tag = JsString::try_new(cx, "ClientGetEulaErrorOffline").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
}
}
Ok(js_obj)
}

// ClientGetUserDeviceError

#[allow(dead_code)]
Expand Down Expand Up @@ -7936,6 +8043,74 @@ fn claimer_user_initial_do_wait_peer(mut cx: FunctionContext) -> JsResult<JsProm
Ok(promise)
}

// client_accept_eula
fn client_accept_eula(mut cx: FunctionContext) -> JsResult<JsPromise> {
crate::init_sentry();
let client = {
let js_val = cx.argument::<JsNumber>(0)?;
{
let v = js_val.value(&mut cx);
if v < (u32::MIN as f64) || (u32::MAX as f64) < v {
cx.throw_type_error("Not an u32 number")?
}
let v = v as u32;
v
}
};
let eula_updated_on = {
let js_val = cx.argument::<JsNumber>(1)?;
{
let v = js_val.value(&mut cx);
let custom_from_rs_f64 = |n: f64| -> Result<_, &'static str> {
libparsec::DateTime::from_timestamp_micros((n * 1_000_000f64) as i64)
.map_err(|_| "Out-of-bound datetime")
};
match custom_from_rs_f64(v) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let channel = cx.channel();
let (deferred, promise) = cx.promise();

// TODO: Promises are not cancellable in Javascript by default, should we add a custom cancel method ?
let _handle = crate::TOKIO_RUNTIME
.lock()
.expect("Mutex is poisoned")
.spawn(async move {
let ret = libparsec::client_accept_eula(client, eula_updated_on).await;

deferred.settle_with(&channel, move |mut cx| {
let js_ret = match ret {
Ok(ok) => {
let js_obj = JsObject::new(&mut cx);
let js_tag = JsBoolean::new(&mut cx, true);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_value = {
#[allow(clippy::let_unit_value)]
let _ = ok;
JsNull::new(&mut cx)
};
js_obj.set(&mut cx, "value", js_value)?;
js_obj
}
Err(err) => {
let js_obj = cx.empty_object();
let js_tag = JsBoolean::new(&mut cx, false);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_err = variant_client_accept_eula_error_rs_to_js(&mut cx, err)?;
js_obj.set(&mut cx, "error", js_err)?;
js_obj
}
};
Ok(js_ret)
});
});

Ok(promise)
}

// client_cancel_invitation
fn client_cancel_invitation(mut cx: FunctionContext) -> JsResult<JsPromise> {
crate::init_sentry();
Expand Down Expand Up @@ -8132,6 +8307,56 @@ fn client_create_workspace(mut cx: FunctionContext) -> JsResult<JsPromise> {
Ok(promise)
}

// client_get_eula
fn client_get_eula(mut cx: FunctionContext) -> JsResult<JsPromise> {
crate::init_sentry();
let client = {
let js_val = cx.argument::<JsNumber>(0)?;
{
let v = js_val.value(&mut cx);
if v < (u32::MIN as f64) || (u32::MAX as f64) < v {
cx.throw_type_error("Not an u32 number")?
}
let v = v as u32;
v
}
};
let channel = cx.channel();
let (deferred, promise) = cx.promise();

// TODO: Promises are not cancellable in Javascript by default, should we add a custom cancel method ?
let _handle = crate::TOKIO_RUNTIME
.lock()
.expect("Mutex is poisoned")
.spawn(async move {
let ret = libparsec::client_get_eula(client).await;

deferred.settle_with(&channel, move |mut cx| {
let js_ret = match ret {
Ok(ok) => {
let js_obj = JsObject::new(&mut cx);
let js_tag = JsBoolean::new(&mut cx, true);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_value = struct_eula_rs_to_js(&mut cx, ok)?;
js_obj.set(&mut cx, "value", js_value)?;
js_obj
}
Err(err) => {
let js_obj = cx.empty_object();
let js_tag = JsBoolean::new(&mut cx, false);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_err = variant_client_get_eula_error_rs_to_js(&mut cx, err)?;
js_obj.set(&mut cx, "error", js_err)?;
js_obj
}
};
Ok(js_ret)
});
});

Ok(promise)
}

// client_get_user_device
fn client_get_user_device(mut cx: FunctionContext) -> JsResult<JsPromise> {
crate::init_sentry();
Expand Down Expand Up @@ -12814,9 +13039,11 @@ pub fn register_meths(cx: &mut ModuleContext) -> NeonResult<()> {
"claimerUserInitialDoWaitPeer",
claimer_user_initial_do_wait_peer,
)?;
cx.export_function("clientAcceptEula", client_accept_eula)?;
cx.export_function("clientCancelInvitation", client_cancel_invitation)?;
cx.export_function("clientChangeAuthentication", client_change_authentication)?;
cx.export_function("clientCreateWorkspace", client_create_workspace)?;
cx.export_function("clientGetEula", client_get_eula)?;
cx.export_function("clientGetUserDevice", client_get_user_device)?;
cx.export_function("clientInfo", client_info)?;
cx.export_function("clientListInvitations", client_list_invitations)?;
Expand Down
Loading

0 comments on commit b57bae0

Please sign in to comment.