Skip to content

Commit

Permalink
Clean up unnecessary imports and make unnecessarily async components …
Browse files Browse the repository at this point in the history
…synchronous
  • Loading branch information
nazar-pc committed Dec 7, 2023
1 parent bb04cd7 commit 0e8d13a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 45 deletions.
39 changes: 13 additions & 26 deletions src/frontend/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::backend::config::{Farm, RawConfig};
use bytesize::ByteSize;
use gtk::prelude::*;
use relm4::component::{AsyncComponent, AsyncComponentParts};
use relm4::prelude::*;
use relm4::AsyncComponentSender;
use relm4_components::open_dialog::{
OpenDialog, OpenDialogMsg, OpenDialogResponse, OpenDialogSettings,
};
Expand Down Expand Up @@ -97,8 +95,8 @@ pub struct ConfigurationView {
open_dialog: Controller<OpenDialog>,
}

#[relm4::component(async, pub)]
impl AsyncComponent for ConfigurationView {
#[relm4::component(pub)]
impl Component for ConfigurationView {
type Init = ();
type Input = ConfigurationInput;
type Output = ConfigurationOutput;
Expand Down Expand Up @@ -325,15 +323,13 @@ impl AsyncComponent for ConfigurationView {
connect_clicked => ConfigurationInput::Start,
set_margin_top: 20,
#[watch]
set_sensitive: {
// TODO
set_sensitive:
model.reward_address.valid()
&& model.node_path.valid()
&& !model.farms.is_empty()
&& model.farms.iter().all(|farm| {
farm.path.valid() && farm.size.valid()
})
},
}),

gtk::Label {
set_label: "Start",
Expand All @@ -346,13 +342,13 @@ impl AsyncComponent for ConfigurationView {
}
}

async fn init(
fn init(
_init: Self::Init,
root: Self::Root,
sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let open_dialog = OpenDialog::builder()
.transient_for_native(&root)
.transient_for_native(root)
.launch(OpenDialogSettings {
folder_mode: true,
accept_label: "Select".to_string(),
Expand All @@ -373,25 +369,16 @@ impl AsyncComponent for ConfigurationView {

let widgets = view_output!();

AsyncComponentParts { model, widgets }
ComponentParts { model, widgets }
}

async fn update(
&mut self,
input: Self::Input,
sender: AsyncComponentSender<Self>,
_root: &Self::Root,
) {
self.process_input(input, sender).await;
fn update(&mut self, input: Self::Input, sender: ComponentSender<Self>, _root: &Self::Root) {
self.process_input(input, sender);
}
}

impl ConfigurationView {
async fn process_input(
&mut self,
input: ConfigurationInput,
sender: AsyncComponentSender<Self>,
) {
fn process_input(&mut self, input: ConfigurationInput, sender: ComponentSender<Self>) {
match input {
ConfigurationInput::RewardAddressChanged(new_reward_address) => {
let new_reward_address = new_reward_address.trim();
Expand Down
27 changes: 10 additions & 17 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::backend::farmer::{PlottingKind, PlottingState};
use crate::backend::node::{SyncKind, SyncState};
use crate::backend::{FarmerNotification, NodeNotification};
use gtk::prelude::*;
use relm4::component::{AsyncComponent, AsyncComponentParts};
use relm4::prelude::*;
use relm4::AsyncComponentSender;
use subspace_core_primitives::BlockNumber;
use tracing::warn;

Expand Down Expand Up @@ -36,8 +34,8 @@ pub struct RunningView {
farmer_state: FarmerState,
}

#[relm4::component(async, pub)]
impl AsyncComponent for RunningView {
#[relm4::component(pub)]
impl Component for RunningView {
type Init = ();
type Input = RunningInput;
type Output = ();
Expand Down Expand Up @@ -184,33 +182,28 @@ impl AsyncComponent for RunningView {
}
}

async fn init(
fn init(
_init: Self::Init,
_root: Self::Root,
_sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
_root: &Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {
node_state: NodeState::default(),
farmer_state: FarmerState::default(),
};

let widgets = view_output!();

AsyncComponentParts { model, widgets }
ComponentParts { model, widgets }
}

async fn update(
&mut self,
input: Self::Input,
_sender: AsyncComponentSender<Self>,
_root: &Self::Root,
) {
self.process_input(input).await;
fn update(&mut self, input: Self::Input, _sender: ComponentSender<Self>, _root: &Self::Root) {
self.process_input(input);
}
}

impl RunningView {
async fn process_input(&mut self, input: RunningInput) {
fn process_input(&mut self, input: RunningInput) {
match input {
RunningInput::Initialize {
best_block_number,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct App {
current_view: View,
backend_action_sender: mpsc::Sender<BackendAction>,
loading_view: Controller<LoadingView>,
configuration_view: AsyncController<ConfigurationView>,
running_view: AsyncController<RunningView>,
configuration_view: Controller<ConfigurationView>,
running_view: Controller<RunningView>,
menu_popover: gtk::Popover,
about_dialog: gtk::AboutDialog,
}
Expand Down

0 comments on commit 0e8d13a

Please sign in to comment.