Skip to content

Commit

Permalink
chore: sorry I kinda forgot what I did
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Nov 22, 2024
1 parent f226ddd commit 62e652c
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 22 deletions.
33 changes: 33 additions & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
use gettextrs::gettext;
use relm4::Sender;

use crate::pages::_11_installing::InstallingPageMsg;

pub mod dnf;

pub const NUM_STAGES: usize = 5;

#[derive(Debug)]
pub enum Stage {
UserAdd,
SetTime,
SetTheme,
DnfUpdate,
DnfInstall,
}

impl From<Stage> for String {
fn from(value: Stage) -> Self {
match value {
Stage::UserAdd => gettext("Creating User…"),
Stage::SetTime => gettext("Setting Timezone…"),
Stage::SetTheme => gettext("Configuring Themes…"),
Stage::DnfUpdate => gettext("Performing System Update…"),
Stage::DnfInstall => gettext("Adding User Programs…"),
}
}
}

#[tracing::instrument]
pub async fn start_install(sender: Sender<InstallingPageMsg>) {
tracing::info!("Starting installation");
}
2 changes: 1 addition & 1 deletion src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Config {
self.populate_catalogue()
.expect("cannot populate catalogue");

tracing::debug!("Populated config: {self:#?}");
tracing::trace!("Populated config: {self:#?}");
}

/// # Errors
Expand Down
5 changes: 5 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ macro_rules! generate_page {
// HACK: this solves variable name obfuscation in macro_rules! {}
let mut $initmodel = model;
let $initwidgets = widgets;
#[allow(unused_variables)]
let $initsender = $sender;

$initblock

Expand Down Expand Up @@ -186,6 +188,7 @@ macro_rules! generate_component {
view! { $($viewtt)+ }


#[allow(clippy::used_underscore_binding)]
fn init(
init: Self::Init,
root: Self::Root,
Expand Down Expand Up @@ -213,6 +216,8 @@ macro_rules! generate_component {
#[allow(unused_mut)]
// HACK: this solves variable name obfuscation in macro_rules! {}
let $initwidgets = widgets;
#[allow(unused_variables)]
let $initsender = $sender;

$initblock

Expand Down
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ pub mod ui;
use crate::prelude::*;
use gtk::glib::translate::FromGlibPtrNone;
use relm4::{
Component, ComponentController, ComponentParts, ComponentSender, RelmApp, SharedState,
SimpleComponent,
Component, ComponentController, ComponentParts, ComponentSender, RelmApp, SimpleComponent,
};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

const APPID: &str = "com.FyraLabs.Taidan";

pub static CONFIG: SharedState<cfg::Config> = SharedState::new();
// configuration of the distro OOBE.
pub static CFG: std::sync::LazyLock<cfg::Config> = std::sync::LazyLock::new(|| {
tracing::debug!("Initializing cfg::Config");
let mut cfg = cfg::Config::default();
cfg.populate();
tracing::debug!("Populated cfg::Config (turn on `trace` to see body)");
cfg
});

generate_pages!(Page AppModel AppMsg:
00: Welcome,
Expand Down Expand Up @@ -57,7 +63,7 @@ impl SimpleComponent for AppModel {

view! {
libhelium::ApplicationWindow {
set_title: Some(&gettext("Welcome to %s").replace("%s", &CONFIG.read().distro)),
set_title: Some(&gettext("Welcome to %s").replace("%s", &CFG.distro)),
set_default_width: 600,
set_default_height: 500,
set_vexpand: true,
Expand Down Expand Up @@ -137,8 +143,9 @@ impl SimpleComponent for AppModel {
.try_into()
.expect("No next page!");
if self.page == Page::Installing {
// TODO: call start_install() or something with the sender to the page!
todo!();
relm4::spawn(backend::start_install(
self.installing_page.sender().clone(),
));
}
}
AppMsg::Nav(NavAction::Back) => {
Expand All @@ -155,7 +162,6 @@ impl SimpleComponent for AppModel {
#[allow(clippy::missing_panics_doc)]
fn main() -> std::io::Result<()> {
let _guard = setup_logs_and_install_panic_hook();
CONFIG.write().populate();

gettextrs::textdomain(APPID)?;
gettextrs::bind_textdomain_codeset(APPID, "UTF-8")?;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_00_welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ crate::generate_page!(Welcome {
},

gtk::Label {
set_label: &gettext("Welcome to %s").replace("%s", &CONFIG.read().distro),
set_label: &gettext("Welcome to %s").replace("%s", &CFG.distro),
add_css_class: "view-title",
inline_css: "font-weight: bold",
},
Expand Down
4 changes: 1 addition & 3 deletions src/pages/_09_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ crate::generate_page!(Browser {
optlist: gtk::Box,
}:
init[optlist](root, sender, model, widgets) {
let cfg = crate::CONFIG.read();
let browser_category = cfg.catalogue.iter()
let browser_category = CFG.catalogue.iter()
.find(|category| category.name == "Browser")
.expect("No browser category");
model.browser_rows = browser_category.choices.iter().cloned().enumerate()
Expand All @@ -17,7 +16,6 @@ crate::generate_page!(Browser {
})
.collect();
model.browser_rows.iter().for_each(|x| widgets.viewdual.browsers.add(x.widget()));
drop(cfg);
}
update(self, message, sender) {
BrowserRowSel(index: usize) => {
Expand Down
13 changes: 6 additions & 7 deletions src/pages/_10_categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate::generate_page!(Categories {
let mut catfactory: FactoryVecDeque<CategoryBtn>
= FactoryVecDeque::builder().launch(widgets.flowbox.clone()).forward(sender.input_sender(), CategoriesPageMsg::BtnClick);
let mut catf = catfactory.guard();
CONFIG.read().catalogue.iter().filter(|cat| cat.name != "Browser")
CFG.catalogue.iter().filter(|cat| cat.name != "Browser")
.for_each(|cat| _ = catf.push_back(CategoryBtn {
category: cat.name.clone(),
}));
Expand Down Expand Up @@ -139,9 +139,8 @@ crate::generate_component!(CategoryWindow {
rows: Vec<relm4::Controller<CatRow>>,
optlist: gtk::Box,
}:
init[optlist](root, sender, model, widgets) for init: String {
let cfg = crate::CONFIG.read();
let category = (cfg.catalogue.iter())
init[optlist](_root, sender, model, widgets) for init: String {
let category = (CFG.catalogue.iter())
.find(|category| category.name == init)
.expect("No browser category");
model.rows = (category.choices.iter().cloned().enumerate())
Expand All @@ -155,14 +154,13 @@ crate::generate_component!(CategoryWindow {
.forward(sender.input_sender(), Self::Input::BrowserRowSel)
})
.collect();
drop(cfg);
model
.rows
.iter()
.for_each(|x| widgets.viewdual.browsers.add(x.widget()));
}

update(self, message, sender) {
update(self, message, _sender) {
BrowserRowSel(index: usize) => {
self.optlist.remove_all();
let row = (self.rows.get(index)).expect("browser row not exist called browser page");
Expand Down Expand Up @@ -193,6 +191,7 @@ crate::generate_component!(CatRow {
category: String,
}:
init(root, sender, model, widgets) for init: Self {
model = init;
let index = model.index;
let ctl = gtk::GestureClick::new();
ctl.set_button(gtk::gdk::ffi::GDK_BUTTON_PRIMARY as u32);
Expand All @@ -203,7 +202,7 @@ crate::generate_component!(CatRow {
root.add_controller(ctl);
}
// NOTE: output `usize` index from `ctl` in `init()`
update(self, message, sender) { } => usize
update(self, message, _sender) { } => usize

libhelium::MiniContentBlock {
set_hexpand: true,
Expand Down
18 changes: 16 additions & 2 deletions src/pages/_11_installing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
crate::generate_page!(Installing:
crate::generate_page!(Installing {
main_progress_bar: gtk::ProgressBar,
}:
init[main_progress_bar](root, sender, model, widgets) {
}
update(self, message, sender) {
// handle UI updates here.
// NOTE: main.rs should call the start_install() fns.
UpdLbl(stage: crate::backend::Stage) => {
self.main_progress_bar.set_text(Some(&*String::from(stage)));
},
Finish => sender.output(Self::Output::Nav(NavAction::Next)).unwrap(),
} => {}

gtk::Box {
Expand Down Expand Up @@ -31,6 +39,12 @@ crate::generate_page!(Installing:
},

// FIXME: libhelium::ProgressBar
#[local_ref] main_progress_bar ->
gtk::ProgressBar {
}
set_text: Some(&*gettext("Loading…")),
},

gtk::ProgressBar {

},
);
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pub use relm4::{
prelude::*,
};

pub use crate::{NavAction, CONFIG};
pub use crate::{NavAction, CFG};

0 comments on commit 62e652c

Please sign in to comment.