mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
load real toolbx information on startup
This commit is contained in:
91
src/main.rs
91
src/main.rs
@@ -1,96 +1,13 @@
|
|||||||
use relm4::{factory::FactoryVec, RelmApp};
|
use relm4::{factory::FactoryVec, RelmApp};
|
||||||
use ui::app::model::{AppModel, ToolboxContainer, ToolboxStatus};
|
use toolbx::ToolbxContainer;
|
||||||
|
use ui::app::model::{AppModel};
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
mod toolbx;
|
mod toolbx;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut factory_vec = FactoryVec::new();
|
let toolbx_list = ToolbxContainer::get_toolboxes();
|
||||||
factory_vec.push(ToolboxContainer {
|
let mut factory_vec = FactoryVec::from_vec(toolbx_list);
|
||||||
name: "fedora-toolbox-35".to_string(),
|
|
||||||
status: ToolboxStatus::Running,
|
|
||||||
update_available: false,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Latex".to_string(),
|
|
||||||
status: ToolboxStatus::Running,
|
|
||||||
update_available: false,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
factory_vec.push(ToolboxContainer {
|
|
||||||
name: "Rust".to_string(),
|
|
||||||
status: ToolboxStatus::Stopped,
|
|
||||||
update_available: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
let model = AppModel {
|
let model = AppModel {
|
||||||
toolboxes: factory_vec,
|
toolboxes: factory_vec,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::{iter::zip, process::Command, sync::Arc, fmt::Result, string::ParseError};
|
use std::{iter::zip, process::Command, sync::Arc, fmt::Result, string::ParseError};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Default)]
|
||||||
pub struct ToolbxContainer {
|
pub struct ToolbxContainer {
|
||||||
id: String,
|
pub id: String,
|
||||||
name: String,
|
pub name: String,
|
||||||
created: String,
|
pub created: String,
|
||||||
status: String,
|
pub status: String,
|
||||||
image: String,
|
pub image: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolbxContainer {
|
impl ToolbxContainer {
|
||||||
|
|||||||
@@ -1,31 +1,15 @@
|
|||||||
use relm4::{factory::FactoryVec, Model};
|
use relm4::{factory::FactoryVec, Model};
|
||||||
|
|
||||||
use crate::ui::components::AppComponents;
|
use crate::{ui::components::AppComponents, toolbx::ToolbxContainer};
|
||||||
|
|
||||||
use super::{messages::AppMsg, widgets::AppWidgets};
|
use super::{messages::AppMsg, widgets::AppWidgets};
|
||||||
|
|
||||||
pub struct AppModel {
|
pub struct AppModel {
|
||||||
pub toolboxes: FactoryVec<ToolboxContainer>,
|
pub toolboxes: FactoryVec<ToolbxContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct ToolboxContainer {
|
|
||||||
pub name: String,
|
|
||||||
pub status: ToolboxStatus,
|
|
||||||
pub update_available: bool,
|
|
||||||
}
|
|
||||||
impl Model for AppModel {
|
impl Model for AppModel {
|
||||||
type Msg = AppMsg;
|
type Msg = AppMsg;
|
||||||
type Widgets = AppWidgets;
|
type Widgets = AppWidgets;
|
||||||
type Components = AppComponents;
|
type Components = AppComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ToolboxStatus {
|
|
||||||
Stopped,
|
|
||||||
Running,
|
|
||||||
}
|
|
||||||
impl Default for ToolboxStatus {
|
|
||||||
fn default() -> Self {
|
|
||||||
ToolboxStatus::Stopped
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,22 +8,21 @@ use relm4::{
|
|||||||
gtk, send, view, Sender,
|
gtk, send, view, Sender,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::ui::{
|
use crate::{ui::{
|
||||||
app::model::ToolboxStatus,
|
|
||||||
ui_strings::{
|
ui_strings::{
|
||||||
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
|
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
|
||||||
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
|
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
|
||||||
},
|
},
|
||||||
};
|
}, toolbx::ToolbxContainer};
|
||||||
|
|
||||||
use super::{messages::AppMsg, model::ToolboxContainer};
|
use super::{messages::AppMsg};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FactoryWidgets {
|
pub struct FactoryWidgets {
|
||||||
pub action_row: adw::ActionRow,
|
pub action_row: adw::ActionRow,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FactoryPrototype for ToolboxContainer {
|
impl FactoryPrototype for ToolbxContainer {
|
||||||
type Factory = FactoryVec<Self>;
|
type Factory = FactoryVec<Self>;
|
||||||
type Widgets = FactoryWidgets;
|
type Widgets = FactoryWidgets;
|
||||||
type Root = adw::ActionRow;
|
type Root = adw::ActionRow;
|
||||||
@@ -37,7 +36,9 @@ impl FactoryPrototype for ToolboxContainer {
|
|||||||
) -> Self::Widgets {
|
) -> Self::Widgets {
|
||||||
view! {
|
view! {
|
||||||
suffix_box = >k::Box{
|
suffix_box = >k::Box{
|
||||||
append = >k::Button::from_icon_name(APP_ICON) {
|
append = >k::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
set_child = Some(>k::Button::from_icon_name(APP_ICON)) {
|
||||||
set_margin_start: 10,
|
set_margin_start: 10,
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
@@ -46,15 +47,21 @@ impl FactoryPrototype for ToolboxContainer {
|
|||||||
connect_clicked(sender) => move |btn| {
|
connect_clicked(sender) => move |btn| {
|
||||||
send!(sender, AppMsg::ShowToolboxAppsRequest);
|
send!(sender, AppMsg::ShowToolboxAppsRequest);
|
||||||
},
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
append = >k::Button::from_icon_name(TERMINAL_ICON) {
|
append = >k::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
set_child = Some(>k::Button::from_icon_name(TERMINAL_ICON)) {
|
||||||
set_margin_start: 10,
|
set_margin_start: 10,
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
set_tooltip_text: Some(TERMINAL_TOOLTIP),
|
set_tooltip_text: Some(TERMINAL_TOOLTIP),
|
||||||
set_css_classes: &["flat"],
|
set_css_classes: &["flat"],
|
||||||
|
}
|
||||||
},
|
},
|
||||||
append = >k::Button::from_icon_name(SETTINGS_ICON) {
|
append = >k::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
set_child = Some(>k::Button::from_icon_name(SETTINGS_ICON)) {
|
||||||
set_margin_start: 10,set_margin_start: 10,
|
set_margin_start: 10,set_margin_start: 10,
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
@@ -65,51 +72,61 @@ impl FactoryPrototype for ToolboxContainer {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
if self.update_available {
|
if self.update_available {
|
||||||
view! {
|
view! {
|
||||||
update_button = >k::Button::from_icon_name(UPDATE_ICON) {
|
update_button = >k::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
set_child = Some(>k::Button::from_icon_name(UPDATE_ICON)) {
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
set_margin_end: 10,
|
set_margin_end: 10,
|
||||||
set_tooltip_text: Some(UPDATE_TOOLTIP),
|
set_tooltip_text: Some(UPDATE_TOOLTIP),
|
||||||
set_css_classes: &["suggested-action"],
|
set_css_classes: &["suggested-action"],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
suffix_box.prepend(&update_button);
|
suffix_box.prepend(&update_button);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
let is_on = true;
|
|
||||||
|
|
||||||
let mut status_button_tooltip = START_TOOLTIP;
|
let mut status_button_tooltip = START_TOOLTIP;
|
||||||
let mut status_button_icon = START_ICON;
|
let mut status_button_icon = START_ICON;
|
||||||
|
|
||||||
match &self.status {
|
match self.status.as_str() {
|
||||||
&ToolboxStatus::Running => {
|
"running" => {
|
||||||
status_button_tooltip = SHUTDOWN_TOOLTIP;
|
status_button_tooltip = SHUTDOWN_TOOLTIP;
|
||||||
status_button_icon = SHUTDOWN_ICON;
|
status_button_icon = SHUTDOWN_ICON;
|
||||||
}
|
}
|
||||||
&ToolboxStatus::Stopped => {
|
_ => {
|
||||||
status_button_tooltip = START_TOOLTIP;
|
status_button_tooltip = START_TOOLTIP;
|
||||||
status_button_icon = START_ICON;
|
status_button_icon = START_ICON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let subtitle = format!("created {}\n{}", self.created, self.image);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
action_row = &adw::ActionRow {
|
action_row = &adw::ActionRow {
|
||||||
set_title: &self.name,
|
set_title: &self.name,
|
||||||
set_subtitle: "additional information",
|
set_subtitle: subtitle.as_str(),
|
||||||
add_prefix = >k::Box {
|
add_prefix = >k::Box {
|
||||||
append = >k::Button::from_icon_name(status_button_icon) {
|
append = >k::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
set_child = Some(>k::Button::from_icon_name(status_button_icon)) {
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
set_tooltip_text: Some(status_button_tooltip),
|
set_tooltip_text: Some(status_button_tooltip),
|
||||||
set_css_classes: &["circular"],
|
set_css_classes: &["circular"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
add_suffix: &suffix_box,
|
add_suffix: &suffix_box,
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
FactoryWidgets { action_row }
|
FactoryWidgets { action_row }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use relm4::{
|
|||||||
prelude::{BoxExt, GtkWindowExt, OrientableExt, WidgetExt},
|
prelude::{BoxExt, GtkWindowExt, OrientableExt, WidgetExt},
|
||||||
traits::AdwApplicationWindowExt,
|
traits::AdwApplicationWindowExt,
|
||||||
},
|
},
|
||||||
gtk::{self, SelectionMode},
|
gtk::{self, SelectionMode, Align, PolicyType},
|
||||||
WidgetPlus, Widgets,
|
WidgetPlus, Widgets,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,14 +27,15 @@ impl Widgets<AppModel, ()> for AppWidgets {
|
|||||||
append = >k::ScrolledWindow {
|
append = >k::ScrolledWindow {
|
||||||
set_hexpand: true,
|
set_hexpand: true,
|
||||||
set_vexpand: true,
|
set_vexpand: true,
|
||||||
|
set_hscrollbar_policy: PolicyType::Never,
|
||||||
set_child = Some(>k::ListBox) {
|
set_child = Some(>k::ListBox) {
|
||||||
|
set_valign: Align::Start,
|
||||||
set_selection_mode: SelectionMode::None,
|
set_selection_mode: SelectionMode::None,
|
||||||
set_margin_all: 30,
|
set_margin_all: 30,
|
||||||
set_css_classes: &["boxed-list"],
|
set_css_classes: &["boxed-list"],
|
||||||
factory!(model.toolboxes)
|
factory!(model.toolboxes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user