From 71452e7e305558b00c674e7cd86f06f429b5cc15 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 15 May 2024 14:50:33 +0200 Subject: [PATCH] bin: Use improved app creation interface --- bin/commands/inbox/select.rs | 31 +++++++------------------------ bin/commands/issue/select.rs | 30 +++++++----------------------- bin/commands/patch/select.rs | 29 ++++++----------------------- 3 files changed, 20 insertions(+), 70 deletions(-) diff --git a/bin/commands/inbox/select.rs b/bin/commands/inbox/select.rs index 5c8d2f12..6c88708e 100644 --- a/bin/commands/inbox/select.rs +++ b/bin/commands/inbox/select.rs @@ -14,15 +14,13 @@ use radicle::storage::git::Repository; use radicle::Profile; use radicle_tui as tui; -use tui::cob::inbox::{self}; +use tui::cob::inbox; use tui::store; use tui::store::StateValue; -use tui::task; -use tui::task::Interrupted; use tui::ui::items::{Filter, NotificationItem, NotificationItemFilter}; use tui::ui::widget::window::{Window, WindowProps}; use tui::ui::widget::{Properties, Widget}; -use tui::ui::Frontend; +use tui::Channel; use tui::Exit; use tui::PageStack; @@ -277,19 +275,16 @@ impl App { } pub async fn run(&self) -> Result> { - let (terminator, mut interrupt_rx) = task::create_termination(); - let (store, state_rx) = store::Store::::new(); - let (frontend, action_tx, action_rx) = Frontend::new(); + let channel = Channel::default(); let state = State::try_from(&self.context)?; - - let window: Window = Window::new(&state, action_tx.clone()) + let window: Window = Window::new(&state, channel.tx.clone()) .page( Page::Browse, - BrowserPage::new(&state, action_tx.clone()).to_boxed(), + BrowserPage::new(&state, channel.tx.clone()).to_boxed(), ) .page( Page::Help, - HelpPage::new(&state, action_tx.clone()).to_boxed(), + HelpPage::new(&state, channel.tx.clone()).to_boxed(), ) .on_update(|state| { WindowProps::default() @@ -297,18 +292,6 @@ impl App { .to_boxed() }); - tokio::try_join!( - store.main_loop(state, terminator, action_rx, interrupt_rx.resubscribe()), - frontend.main_loop(Some(window), state_rx, interrupt_rx.resubscribe()), - )?; - - if let Ok(reason) = interrupt_rx.recv().await { - match reason { - Interrupted::User { payload } => Ok(payload), - Interrupted::OsSignal => anyhow::bail!("exited because of an os sig int"), - } - } else { - anyhow::bail!("exited because of an unexpected error"); - } + tui::run(channel, state, window).await } } diff --git a/bin/commands/issue/select.rs b/bin/commands/issue/select.rs index 0ae8f65b..a1cf5f1c 100644 --- a/bin/commands/issue/select.rs +++ b/bin/commands/issue/select.rs @@ -13,12 +13,11 @@ use radicle_tui as tui; use tui::cob::issue; use tui::store::StateValue; -use tui::task; -use tui::task::Interrupted; use tui::ui::items::{Filter, IssueItem, IssueItemFilter}; use tui::ui::widget::window::{Window, WindowProps}; use tui::ui::widget::{Properties, Widget}; -use tui::ui::Frontend; +use tui::Channel; + use tui::Exit; use tui::{store, PageStack}; @@ -195,19 +194,16 @@ impl App { } pub async fn run(&self) -> Result> { - let (terminator, mut interrupt_rx) = task::create_termination(); - let (store, state_rx) = store::Store::::new(); - let (frontend, action_tx, action_rx) = Frontend::new(); + let channel = Channel::default(); let state = State::try_from(&self.context)?; - - let window: Window = Window::new(&state, action_tx.clone()) + let window: Window = Window::new(&state, channel.tx.clone()) .page( Page::Browse, - BrowserPage::new(&state, action_tx.clone()).to_boxed(), + BrowserPage::new(&state, channel.tx.clone()).to_boxed(), ) .page( Page::Help, - HelpPage::new(&state, action_tx.clone()).to_boxed(), + HelpPage::new(&state, channel.tx.clone()).to_boxed(), ) .on_update(|state| { WindowProps::default() @@ -215,18 +211,6 @@ impl App { .to_boxed() }); - tokio::try_join!( - store.main_loop(state, terminator, action_rx, interrupt_rx.resubscribe()), - frontend.main_loop(Some(window), state_rx, interrupt_rx.resubscribe()), - )?; - - if let Ok(reason) = interrupt_rx.recv().await { - match reason { - Interrupted::User { payload } => Ok(payload), - Interrupted::OsSignal => anyhow::bail!("exited because of an os sig int"), - } - } else { - anyhow::bail!("exited because of an unexpected error"); - } + tui::run(channel, state, window).await } } diff --git a/bin/commands/patch/select.rs b/bin/commands/patch/select.rs index 6b6b1047..b2a54bc7 100644 --- a/bin/commands/patch/select.rs +++ b/bin/commands/patch/select.rs @@ -13,12 +13,10 @@ use radicle_tui as tui; use tui::cob::patch; use tui::store; -use tui::task; -use tui::task::Interrupted; use tui::ui::items::{Filter, PatchItem, PatchItemFilter}; use tui::ui::widget::window::{Window, WindowProps}; use tui::ui::widget::{Properties, Widget}; -use tui::ui::Frontend; +use tui::Channel; use tui::Exit; use tui::PageStack; @@ -197,19 +195,16 @@ impl App { } pub async fn run(&self) -> Result> { - let (terminator, mut interrupt_rx) = task::create_termination(); - let (store, state_rx) = store::Store::::new(); - let (frontend, action_tx, action_rx) = Frontend::::new(); + let channel = Channel::default(); let state = State::try_from(&self.context)?; - - let window: Window = Window::new(&state, action_tx.clone()) + let window: Window = Window::new(&state, channel.tx.clone()) .page( Page::Browse, - BrowserPage::new(&state, action_tx.clone()).to_boxed(), + BrowserPage::new(&state, channel.tx.clone()).to_boxed(), ) .page( Page::Help, - HelpPage::new(&state, action_tx.clone()).to_boxed(), + HelpPage::new(&state, channel.tx.clone()).to_boxed(), ) .on_update(|state| { WindowProps::default() @@ -217,18 +212,6 @@ impl App { .to_boxed() }); - tokio::try_join!( - store.main_loop(state, terminator, action_rx, interrupt_rx.resubscribe()), - frontend.main_loop(Some(window), state_rx, interrupt_rx.resubscribe()), - )?; - - if let Ok(reason) = interrupt_rx.recv().await { - match reason { - Interrupted::User { payload } => Ok(payload), - Interrupted::OsSignal => anyhow::bail!("exited because of an os sig int"), - } - } else { - anyhow::bail!("exited because of an unexpected error"); - } + tui::run(channel, state, window).await } }