| 1 |
uniffi::setup_scaffolding!(); |
| 2 |
|
| 3 |
use std::path::Path; |
| 4 |
|
| 5 |
|
| 6 |
#[uniffi::export] |
| 7 |
pub fn oxygen_greeting(name: String) -> String { |
| 8 |
format!("Hello, {}! Oxygen Native Core is active.", name) |
| 9 |
} |
| 10 |
|
| 11 |
|
| 12 |
#[derive(Debug, uniffi::Error)] |
| 13 |
pub enum RunnerError { |
| 14 |
Failed { reason: String }, |
| 15 |
} |
| 16 |
|
| 17 |
impl std::fmt::Display for RunnerError { |
| 18 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 19 |
match self { |
| 20 |
RunnerError::Failed { reason } => f.write_str(reason), |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
impl std::error::Error for RunnerError {} |
| 26 |
|
| 27 |
fn failed(e: anyhow::Error) -> RunnerError { |
| 28 |
RunnerError::Failed { reason: format!("{e:#}") } |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#[uniffi::export] |
| 36 |
pub fn runner_register(home: String, hub: String, token: String, name: String) -> Result<String, RunnerError> { |
| 37 |
let h = flow::home::Home::locate(Some(Path::new(&home))).map_err(failed)?; |
| 38 |
let r = flow::runner::register(&h, &hub, &token, &name, None, vec!["android".into()]).map_err(failed)?; |
| 39 |
Ok(r.name) |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
#[uniffi::export] |
| 44 |
pub fn runner_is_registered(home: String) -> bool { |
| 45 |
Path::new(&home).join(flow::home::RUNNER_TOML).is_file() |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#[uniffi::export] |
| 52 |
pub fn runner_serve(home: String) -> Result<(), RunnerError> { |
| 53 |
let h = flow::home::Home::locate(Some(Path::new(&home))).map_err(failed)?; |
| 54 |
flow::runner::serve_embedded(&h).map_err(failed) |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#[uniffi::export] |
| 61 |
pub fn runner_stop() { |
| 62 |
flow::runner::stop(); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
#[uniffi::export] |
| 72 |
pub fn runner_leave(reason: String, notice_secs: u64) { |
| 73 |
flow::runner::leave_within(&reason, std::time::Duration::from_secs(notice_secs)); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
#[uniffi::export] |
| 78 |
pub fn runner_tiers(home: String) -> Vec<String> { |
| 79 |
let Ok(h) = flow::home::Home::locate(Some(Path::new(&home))) else { return vec![] }; |
| 80 |
match flow::runner::tiers(&h) { |
| 81 |
Ok((have, _)) => have, |
| 82 |
Err(_) => vec![], |
| 83 |
} |
| 84 |
} |