migrate to relm 0.8.1

This commit is contained in:
2024-03-17 17:37:38 +01:00
parent 9e95347226
commit 8c3db04c3e
9 changed files with 250 additions and 234 deletions

View File

@@ -59,9 +59,11 @@ impl Component for App {
view! {
main_window = adw::ApplicationWindow::new(&main_application()) {
set_visible: true,
connect_close_request[sender] => move |_| {
sender.input(AppMsg::Quit);
gtk::Inhibit(true)
glib::Propagation::Stop
},
#[wrap(Some)]
@@ -105,22 +107,22 @@ impl Component for App {
fn init(
_init: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let about_dialog = AboutDialog::builder()
.transient_for(root)
.transient_for(&root)
.launch(())
.detach();
let unsupported_dialog = UnsupportedDialog::builder()
.transient_for(root)
.transient_for(&root)
.launch(())
.forward(sender.input_sender(), |msg| match msg {
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
});
let mut containers = FactoryHashMap::new(gtk::ListBox::default(), sender.input_sender());
let mut containers = FactoryHashMap::builder().launch_default().detach();
containers.insert("123".to_string(), 2);
containers.insert("124".to_string(), 3);

View File

@@ -24,7 +24,6 @@ impl FactoryComponent for Container {
type Output = ();
type CommandOutput = ();
type Widgets = ContainerWidgets;
type ParentInput = AppMsg;
type ParentWidget = gtk::ListBox;
type Index = String;

View File

@@ -1,30 +1,41 @@
#[rustfmt::skip]
mod config;
mod app;
mod config;
mod factories;
mod modals;
mod setup;
use crate::config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
use gettextrs::{gettext, LocaleCategory};
use gtk::prelude::ApplicationExt;
use gtk::{gio, glib};
use relm4::{
actions::{AccelsPlus, RelmAction, RelmActionGroup},
gtk, main_application, RelmApp,
};
use app::App;
use setup::setup;
relm4::new_action_group!(AppActionGroup, "app");
relm4::new_stateless_action!(QuitAction, AppActionGroup, "quit");
fn main() {
gtk::init().unwrap();
// Enable logging
tracing_subscriber::fmt()
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL)
.with_max_level(tracing::Level::INFO)
.init();
setup();
// setup gettext
gettextrs::setlocale(LocaleCategory::LcAll, "");
gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");
glib::set_application_name(&gettext("Toolbox Tuner"));
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
gio::resources_register(&res);
gtk::Window::set_default_icon_name(APP_ID);
let app = main_application();
app.set_resource_base_path(Some("/org/kuchelmeister/ToolboxTuner/"));
@@ -45,5 +56,12 @@ fn main() {
let app = RelmApp::from_app(app);
relm4_icons::initialize_icons();
app.run::<App>(());
let data = res
.lookup_data(
"/org/kuchelmeister/ToolboxTuner/style.css",
gio::ResourceLookupFlags::NONE,
)
.unwrap();
app.set_global_css(&glib::GString::from_utf8_checked(data.to_vec()).unwrap());
app.visible_on_activate(false).run::<App>(());
}

View File

@@ -33,7 +33,7 @@ impl SimpleComponent for AboutDialog {
fn init(
_: Self::Init,
root: &Self::Root,
root: Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {};

View File

@@ -2,7 +2,7 @@ use adw::StatusPage;
use gtk::prelude::{ButtonExt, GtkWindowExt};
use relm4::view;
use relm4::{adw, gtk, ComponentParts, ComponentSender, SimpleComponent};
use relm4_icons::icon_name;
use relm4_icons::icon_names;
pub struct UnsupportedDialog {}
@@ -24,7 +24,7 @@ impl SimpleComponent for UnsupportedDialog {
fn init(
_: Self::Init,
root: &Self::Root,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {};
@@ -38,7 +38,7 @@ impl SimpleComponent for UnsupportedDialog {
StatusPage::new() {
set_icon_name: Some(icon_name::ISSUE),
set_icon_name: Some(icon_names::ISSUE),
set_title: "Missing requirements",
set_description: Some("Make sure Toolbox and Gnome Terminal are installed."),

View File

@@ -1,39 +0,0 @@
use relm4::gtk;
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};
use crate::config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
pub fn setup() {
// Initialize GTK
gtk::init().unwrap();
setup_gettext();
glib::set_application_name(&gettext("Toolbox Tuner"));
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
gio::resources_register(&res);
setup_css(&res);
gtk::Window::set_default_icon_name(APP_ID);
}
fn setup_gettext() {
// Prepare i18n
gettextrs::setlocale(LocaleCategory::LcAll, "");
gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");
}
fn setup_css(res: &gio::Resource) {
let data = res
.lookup_data(
"/org/kuchelmeister/ToolboxTuner/style.css",
gio::ResourceLookupFlags::NONE,
)
.unwrap();
relm4::set_global_css(&glib::GString::from_utf8_checked(data.to_vec()).unwrap());
}