mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
Feature/new registry (#2612)
* wip * overhaul boot process * wip: new registry * wip * wip * wip * wip * wip * wip * os registry complete * ui fixes * fixes * fixes * more fixes * fix merkle archive
This commit is contained in:
@@ -8,7 +8,7 @@ use clap::Parser;
|
||||
use isocountry::CountryCode;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use rpc_toolkit::{command, from_fn_async, AnyContext, Empty, HandlerExt, ParentHandler};
|
||||
use rpc_toolkit::{from_fn_async, Context, Empty, HandlerExt, ParentHandler};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::process::Command;
|
||||
use tokio::sync::RwLock;
|
||||
@@ -17,6 +17,7 @@ use ts_rs::TS;
|
||||
|
||||
use crate::context::{CliContext, RpcContext};
|
||||
use crate::db::model::public::WifiInfo;
|
||||
use crate::db::model::Database;
|
||||
use crate::net::utils::find_wifi_iface;
|
||||
use crate::prelude::*;
|
||||
use crate::util::serde::{display_serializable, HandlerExtSerde, WithIoFormat};
|
||||
@@ -36,57 +37,55 @@ pub fn wifi_manager(ctx: &RpcContext) -> Result<&WifiManager, Error> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wifi() -> ParentHandler {
|
||||
pub fn wifi<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new()
|
||||
.subcommand(
|
||||
"add",
|
||||
from_fn_async(add)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"connect",
|
||||
from_fn_async(connect)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"delete",
|
||||
from_fn_async(delete)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"get",
|
||||
from_fn_async(get)
|
||||
.with_display_serializable()
|
||||
.with_custom_display_fn::<AnyContext, _>(|handle, result| {
|
||||
.with_custom_display_fn(|handle, result| {
|
||||
Ok(display_wifi_info(handle.params, result))
|
||||
})
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("country", country())
|
||||
.subcommand("available", available())
|
||||
.subcommand("country", country::<C>())
|
||||
.subcommand("available", available::<C>())
|
||||
}
|
||||
|
||||
pub fn available() -> ParentHandler {
|
||||
pub fn available<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new().subcommand(
|
||||
"get",
|
||||
from_fn_async(get_available)
|
||||
.with_display_serializable()
|
||||
.with_custom_display_fn::<AnyContext, _>(|handle, result| {
|
||||
Ok(display_wifi_list(handle.params, result))
|
||||
})
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_custom_display_fn(|handle, result| Ok(display_wifi_list(handle.params, result)))
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn country() -> ParentHandler {
|
||||
pub fn country<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new().subcommand(
|
||||
"set",
|
||||
from_fn_async(set_country)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ pub async fn add(ctx: RpcContext, AddParams { ssid, password }: AddParams) -> Re
|
||||
));
|
||||
}
|
||||
async fn add_procedure(
|
||||
db: PatchDb,
|
||||
db: TypedPatchDb<Database>,
|
||||
wifi_manager: WifiManager,
|
||||
ssid: &Ssid,
|
||||
password: &Psk,
|
||||
@@ -170,7 +169,7 @@ pub async fn connect(ctx: RpcContext, SsidParams { ssid }: SsidParams) -> Result
|
||||
));
|
||||
}
|
||||
async fn connect_procedure(
|
||||
db: PatchDb,
|
||||
db: TypedPatchDb<Database>,
|
||||
wifi_manager: WifiManager,
|
||||
ssid: &Ssid,
|
||||
) -> Result<(), Error> {
|
||||
@@ -718,7 +717,7 @@ impl WpaCli {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub async fn save_config(&mut self, db: PatchDb) -> Result<(), Error> {
|
||||
pub async fn save_config(&mut self, db: TypedPatchDb<Database>) -> Result<(), Error> {
|
||||
let new_country = self.get_country_low().await?;
|
||||
db.mutate(|d| {
|
||||
d.as_public_mut()
|
||||
@@ -758,7 +757,11 @@ impl WpaCli {
|
||||
.collect())
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
pub async fn select_network(&mut self, db: PatchDb, ssid: &Ssid) -> Result<bool, Error> {
|
||||
pub async fn select_network(
|
||||
&mut self,
|
||||
db: TypedPatchDb<Database>,
|
||||
ssid: &Ssid,
|
||||
) -> Result<bool, Error> {
|
||||
let m_id = self.check_active_network(ssid).await?;
|
||||
match m_id {
|
||||
None => Err(Error::new(
|
||||
@@ -810,7 +813,11 @@ impl WpaCli {
|
||||
}
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
pub async fn remove_network(&mut self, db: PatchDb, ssid: &Ssid) -> Result<bool, Error> {
|
||||
pub async fn remove_network(
|
||||
&mut self,
|
||||
db: TypedPatchDb<Database>,
|
||||
ssid: &Ssid,
|
||||
) -> Result<bool, Error> {
|
||||
let found_networks = self.find_networks(ssid).await?;
|
||||
if found_networks.is_empty() {
|
||||
return Ok(true);
|
||||
@@ -824,7 +831,7 @@ impl WpaCli {
|
||||
#[instrument(skip_all)]
|
||||
pub async fn set_add_network(
|
||||
&mut self,
|
||||
db: PatchDb,
|
||||
db: TypedPatchDb<Database>,
|
||||
ssid: &Ssid,
|
||||
psk: &Psk,
|
||||
) -> Result<(), Error> {
|
||||
@@ -833,7 +840,12 @@ impl WpaCli {
|
||||
Ok(())
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
pub async fn add_network(&mut self, db: PatchDb, ssid: &Ssid, psk: &Psk) -> Result<(), Error> {
|
||||
pub async fn add_network(
|
||||
&mut self,
|
||||
db: TypedPatchDb<Database>,
|
||||
ssid: &Ssid,
|
||||
psk: &Psk,
|
||||
) -> Result<(), Error> {
|
||||
self.add_network_low(ssid, psk).await?;
|
||||
self.save_config(db).await?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user