mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
Feat/combine uis (#2633)
* wip * restructure backend for new ui structure * new patchdb bootstrap, single websocket api, local storage migration, more * update db websocket * init apis * update patch-db * setup progress * feat: implement state service, alert and routing Signed-off-by: waterplea <alexander@inkin.ru> * update setup wizard for new types * feat: add init page Signed-off-by: waterplea <alexander@inkin.ru> * chore: refactor message, patch-db source stream and connection service Signed-off-by: waterplea <alexander@inkin.ru> * fix method not found on state * fix backend bugs * fix compat assets * address comments * remove unneeded styling * cleaner progress * bugfixes * fix init logs * fix progress reporting * fix navigation by getting state after init * remove patch dependency from live api * fix caching * re-add patchDB to live api * fix metrics values * send close frame * add bootId and fix polling --------- Signed-off-by: waterplea <alexander@inkin.ru> Co-authored-by: Aiden McClelland <me@drbonez.dev> Co-authored-by: waterplea <alexander@inkin.ru>
This commit is contained in:
@@ -274,6 +274,81 @@ pub fn response_to_reader(response: reqwest::Response) -> impl AsyncRead + Unpin
|
||||
}))
|
||||
}
|
||||
|
||||
#[pin_project::pin_project]
|
||||
pub struct IOHook<'a, T> {
|
||||
#[pin]
|
||||
pub io: T,
|
||||
pre_write: Option<Box<dyn FnMut(&[u8]) -> Result<(), std::io::Error> + Send + 'a>>,
|
||||
post_write: Option<Box<dyn FnMut(&[u8]) + Send + 'a>>,
|
||||
post_read: Option<Box<dyn FnMut(&[u8]) + Send + 'a>>,
|
||||
}
|
||||
impl<'a, T> IOHook<'a, T> {
|
||||
pub fn new(io: T) -> Self {
|
||||
Self {
|
||||
io,
|
||||
pre_write: None,
|
||||
post_write: None,
|
||||
post_read: None,
|
||||
}
|
||||
}
|
||||
pub fn into_inner(self) -> T {
|
||||
self.io
|
||||
}
|
||||
pub fn pre_write<F: FnMut(&[u8]) -> Result<(), std::io::Error> + Send + 'a>(&mut self, f: F) {
|
||||
self.pre_write = Some(Box::new(f))
|
||||
}
|
||||
pub fn post_write<F: FnMut(&[u8]) + Send + 'a>(&mut self, f: F) {
|
||||
self.post_write = Some(Box::new(f))
|
||||
}
|
||||
pub fn post_read<F: FnMut(&[u8]) + Send + 'a>(&mut self, f: F) {
|
||||
self.post_read = Some(Box::new(f))
|
||||
}
|
||||
}
|
||||
impl<'a, T: AsyncWrite> AsyncWrite for IOHook<'a, T> {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, std::io::Error>> {
|
||||
let this = self.project();
|
||||
if let Some(pre_write) = this.pre_write {
|
||||
pre_write(buf)?;
|
||||
}
|
||||
let written = futures::ready!(this.io.poll_write(cx, buf)?);
|
||||
if let Some(post_write) = this.post_write {
|
||||
post_write(&buf[..written]);
|
||||
}
|
||||
Poll::Ready(Ok(written))
|
||||
}
|
||||
fn poll_flush(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
self.project().io.poll_flush(cx)
|
||||
}
|
||||
fn poll_shutdown(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
self.project().io.poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
impl<'a, T: AsyncRead> AsyncRead for IOHook<'a, T> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> Poll<std::io::Result<()>> {
|
||||
let this = self.project();
|
||||
let start = buf.filled().len();
|
||||
futures::ready!(this.io.poll_read(cx, buf)?);
|
||||
if let Some(post_read) = this.post_read {
|
||||
post_read(&buf.filled()[start..]);
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
#[pin_project::pin_project]
|
||||
pub struct BufferedWriteReader {
|
||||
#[pin]
|
||||
@@ -768,7 +843,7 @@ fn poll_flush_prefix<W: AsyncWrite>(
|
||||
flush_writer: bool,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
while let Some(mut cur) = prefix.pop_front() {
|
||||
let buf = cur.remaining_slice();
|
||||
let buf = CursorExt::remaining_slice(&cur);
|
||||
if !buf.is_empty() {
|
||||
match writer.as_mut().poll_write(cx, buf)? {
|
||||
Poll::Ready(n) if n == buf.len() => (),
|
||||
|
||||
Reference in New Issue
Block a user