| 1 |
uniffi::setup_scaffolding!(); |
| 2 |
|
| 3 |
mod backdrop; |
| 4 |
pub mod scenes; |
| 5 |
|
| 6 |
use std::path::Path; |
| 7 |
|
| 8 |
|
| 9 |
#[uniffi::export] |
| 10 |
pub fn oxygen_greeting(name: String) -> String { |
| 11 |
format!("Hello, {}! Oxygen Native Core is active.", name) |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
#[derive(Debug, uniffi::Error)] |
| 16 |
pub enum RunnerError { |
| 17 |
Failed { reason: String }, |
| 18 |
} |
| 19 |
|
| 20 |
impl std::fmt::Display for RunnerError { |
| 21 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 22 |
match self { |
| 23 |
RunnerError::Failed { reason } => f.write_str(reason), |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl std::error::Error for RunnerError {} |
| 29 |
|
| 30 |
fn failed(e: anyhow::Error) -> RunnerError { |
| 31 |
RunnerError::Failed { reason: format!("{e:#}") } |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#[uniffi::export] |
| 39 |
pub fn runner_register(home: String, hub: String, token: String, name: String) -> Result<String, RunnerError> { |
| 40 |
let h = flow::home::Home::locate(Some(Path::new(&home))).map_err(failed)?; |
| 41 |
let r = flow::runner::register(&h, &hub, &token, &name, None, vec!["android".into()]).map_err(failed)?; |
| 42 |
Ok(r.name) |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
#[uniffi::export] |
| 47 |
pub fn runner_is_registered(home: String) -> bool { |
| 48 |
Path::new(&home).join(flow::home::RUNNER_TOML).is_file() |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#[uniffi::export] |
| 55 |
pub fn runner_serve(home: String) -> Result<(), RunnerError> { |
| 56 |
let h = flow::home::Home::locate(Some(Path::new(&home))).map_err(failed)?; |
| 57 |
flow::runner::serve_embedded(&h).map_err(failed) |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
#[uniffi::export] |
| 64 |
pub fn runner_stop() { |
| 65 |
flow::runner::stop(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
#[uniffi::export] |
| 75 |
pub fn runner_leave(reason: String, notice_secs: u64) { |
| 76 |
flow::runner::leave_within(&reason, std::time::Duration::from_secs(notice_secs)); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
#[uniffi::export] |
| 82 |
pub fn runner_running() -> Vec<String> { |
| 83 |
flow::runner::running() |
| 84 |
} |
| 85 |
|
| 86 |
#[uniffi::export] |
| 87 |
pub fn runner_tiers(home: String) -> Vec<String> { |
| 88 |
let Ok(h) = flow::home::Home::locate(Some(Path::new(&home))) else { return vec![] }; |
| 89 |
match flow::runner::tiers(&h) { |
| 90 |
Ok((have, _)) => have, |
| 91 |
Err(_) => vec![], |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
#[uniffi::export] |
| 98 |
pub fn alert_new_secret() -> Vec<u8> { |
| 99 |
flow_core::alert::new_secret().to_vec() |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
#[uniffi::export] |
| 105 |
pub fn alert_public_key(secret: Vec<u8>) -> Vec<u8> { |
| 106 |
<[u8; 32]>::try_from(secret.as_slice()).map(|s| flow_core::alert::public_key(&s).to_vec()).unwrap_or_default() |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
#[uniffi::export] |
| 112 |
pub fn alert_open(secret: Vec<u8>, sealed: Vec<u8>) -> Option<Vec<u8>> { |
| 113 |
let s = <[u8; 32]>::try_from(secret.as_slice()).ok()?; |
| 114 |
flow_core::alert::open(&s, &sealed) |
| 115 |
} |