mirror of
https://github.com/snowfallorg/nix-software-center.git
synced 2024-08-17 09:00:35 +03:00
Fix issue with about and preferences windows
This commit is contained in:
parent
0ba4ad4475
commit
2120c82eb1
@ -3,61 +3,53 @@ use relm4::*;
|
||||
|
||||
use crate::config;
|
||||
|
||||
use super::window::AppMsg;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AboutPageModel {
|
||||
hidden: bool,
|
||||
}
|
||||
pub struct AboutPageModel {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AboutPageMsg {
|
||||
Show,
|
||||
Hide,
|
||||
}
|
||||
|
||||
pub struct Widgets {
|
||||
parent_window: gtk::Window,
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
impl SimpleComponent for AboutPageModel {
|
||||
type Init = gtk::Window;
|
||||
type Input = AboutPageMsg;
|
||||
type Output = AppMsg;
|
||||
type Widgets = Widgets;
|
||||
type Input = ();
|
||||
type Output = ();
|
||||
type Root = ();
|
||||
|
||||
view! {
|
||||
adw::AboutWindow {
|
||||
#[watch]
|
||||
set_visible: !model.hidden,
|
||||
set_transient_for: Some(&parent_window),
|
||||
set_modal: true,
|
||||
set_application_name: "Nix Software Center",
|
||||
set_application_icon: config::APP_ID,
|
||||
set_developer_name: "Victor Fuentes",
|
||||
set_version: config::VERSION,
|
||||
set_issue_url: "https://github.com/vlinkz/nix-software-center/issues",
|
||||
set_license_type: gtk::License::Gpl30,
|
||||
set_website: "https://github.com/vlinkz/nix-software-center",
|
||||
set_developers: &["Victor Fuentes https://github.com/vlinkz"],
|
||||
}
|
||||
}
|
||||
fn init_root() -> Self::Root {}
|
||||
|
||||
fn init(
|
||||
parent_window: Self::Init,
|
||||
root: &Self::Root,
|
||||
_root: &Self::Root,
|
||||
_sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = AboutPageModel {
|
||||
hidden: true,
|
||||
};
|
||||
let model = Self {};
|
||||
|
||||
let widgets = view_output!();
|
||||
let widgets = Widgets { parent_window };
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
|
||||
match msg {
|
||||
AboutPageMsg::Show => {
|
||||
self.hidden = false;
|
||||
}
|
||||
}
|
||||
fn update_view(&self, dialog: &mut Self::Widgets, _sender: ComponentSender<Self>) {
|
||||
let dialog = adw::AboutWindow::builder()
|
||||
.application_icon(config::APP_ID)
|
||||
.application_name("Nix Software Center")
|
||||
.developer_name("Victor Fuentes")
|
||||
.developers(vec!["Victor Fuentes https://github.com/vlinkz".into()])
|
||||
.issue_url("https://github.com/vlinkz/nix-software-center/issues")
|
||||
.license_type(gtk::License::Gpl30)
|
||||
.modal(true)
|
||||
.transient_for(&dialog.parent_window)
|
||||
.version(config::VERSION)
|
||||
.website("https://github.com/vlinkz/nix-software-center")
|
||||
.build();
|
||||
dialog.present();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use relm4_components::open_dialog::*;
|
||||
#[tracker::track]
|
||||
#[derive(Debug)]
|
||||
pub struct PreferencesPageModel {
|
||||
hidden: bool,
|
||||
configpath: Option<PathBuf>,
|
||||
flake: Option<PathBuf>,
|
||||
flakearg: Option<String>,
|
||||
@ -39,8 +38,7 @@ impl SimpleComponent for PreferencesPageModel {
|
||||
|
||||
view! {
|
||||
adw::PreferencesWindow {
|
||||
#[watch]
|
||||
set_visible: !model.hidden,
|
||||
set_hide_on_close: true,
|
||||
set_transient_for: Some(&parent_window),
|
||||
set_modal: true,
|
||||
set_search_enabled: false,
|
||||
@ -153,6 +151,7 @@ impl SimpleComponent for PreferencesPageModel {
|
||||
#[watch]
|
||||
set_visible: model.flake.is_some(),
|
||||
set_title: "Flake arguments (--flake path/to/flake.nix#<THIS ENTRY>)",
|
||||
set_use_markup: false,
|
||||
connect_changed[sender] => move |x| {
|
||||
sender.input(PreferencesPageMsg::SetFlakeArg({
|
||||
let text = x.text().to_string();
|
||||
@ -192,7 +191,6 @@ impl SimpleComponent for PreferencesPageModel {
|
||||
OpenDialogResponse::Cancel => PreferencesPageMsg::Ignore,
|
||||
});
|
||||
let model = PreferencesPageModel {
|
||||
hidden: true,
|
||||
configpath: None,
|
||||
flake: None,
|
||||
flakearg: None,
|
||||
@ -213,7 +211,6 @@ impl SimpleComponent for PreferencesPageModel {
|
||||
self.configpath = config.systemconfig.as_ref().map(PathBuf::from);
|
||||
self.set_flake(config.flake.as_ref().map(PathBuf::from));
|
||||
self.set_flakearg(config.flakearg);
|
||||
self.hidden = false;
|
||||
}
|
||||
PreferencesPageMsg::Open => self.open_dialog.emit(OpenDialogMsg::Open),
|
||||
PreferencesPageMsg::OpenFlake => self.flake_file_dialog.emit(OpenDialogMsg::Open),
|
||||
|
@ -119,6 +119,10 @@ pub struct AppModel {
|
||||
vschild: String,
|
||||
showvsbar: bool,
|
||||
#[tracker::no_eq]
|
||||
aboutpage: Controller<AboutPageModel>,
|
||||
#[tracker::no_eq]
|
||||
preferencespage: Controller<PreferencesPageModel>,
|
||||
#[tracker::no_eq]
|
||||
installedpage: Controller<InstalledPageModel>,
|
||||
#[tracker::no_eq]
|
||||
updatepage: Controller<UpdatePageModel>,
|
||||
@ -161,8 +165,6 @@ pub enum AppMsg {
|
||||
SetVsBar(bool),
|
||||
SetVsChild(String),
|
||||
Search(String),
|
||||
OpenAboutPage,
|
||||
OpenPreferencesPage,
|
||||
AddInstalledToWorkQueue(WorkPkg),
|
||||
RemoveInstalledBusy(WorkPkg),
|
||||
OpenCategoryPage(PkgCategory),
|
||||
@ -523,8 +525,14 @@ impl Component for AppModel {
|
||||
.forward(sender.input_sender(), identity);
|
||||
let viewstack = adw::ViewStack::new();
|
||||
let welcomepage = WelcomeModel::builder()
|
||||
.launch(root.clone().upcast())
|
||||
.forward(sender.input_sender(), identity);
|
||||
.launch(root.clone().upcast())
|
||||
.forward(sender.input_sender(), identity);
|
||||
let aboutpage = AboutPageModel::builder()
|
||||
.launch(root.clone().upcast())
|
||||
.detach();
|
||||
let preferencespage = PreferencesPageModel::builder()
|
||||
.launch(root.clone().upcast())
|
||||
.forward(sender.input_sender(), identity);
|
||||
|
||||
let model = AppModel {
|
||||
mainwindow: root.clone(),
|
||||
@ -559,6 +567,8 @@ impl Component for AppModel {
|
||||
installedpagebusy: vec![],
|
||||
rebuild,
|
||||
welcomepage,
|
||||
aboutpage,
|
||||
preferencespage,
|
||||
online,
|
||||
tracker: 0,
|
||||
};
|
||||
@ -588,16 +598,19 @@ impl Component for AppModel {
|
||||
|
||||
let group = RelmActionGroup::<MenuActionGroup>::new();
|
||||
let aboutpage: RelmAction<AboutAction> = {
|
||||
let sender = sender.clone();
|
||||
let sender = model.aboutpage.sender().clone();
|
||||
RelmAction::new_stateless(move |_| {
|
||||
sender.input(AppMsg::OpenAboutPage);
|
||||
sender.send(()).unwrap();
|
||||
})
|
||||
};
|
||||
|
||||
let prefernecespage: RelmAction<PreferencesAction> = {
|
||||
let sender = sender;
|
||||
let sender = model.preferencespage.sender().clone();
|
||||
let preferencespage = model.preferencespage.widget().clone();
|
||||
let config = model.config.clone();
|
||||
RelmAction::new_stateless(move |_| {
|
||||
sender.input(AppMsg::OpenPreferencesPage);
|
||||
sender.send(PreferencesPageMsg::Show(config.clone())).unwrap();
|
||||
preferencespage.present();
|
||||
})
|
||||
};
|
||||
|
||||
@ -1718,18 +1731,6 @@ FROM pkgs JOIN meta ON (pkgs.attribute = meta.attribute) WHERE pkgs.attribute =
|
||||
}).drop_on_shutdown()
|
||||
})
|
||||
}
|
||||
AppMsg::OpenAboutPage => {
|
||||
let aboutpage = AboutPageModel::builder()
|
||||
.launch(self.mainwindow.clone().upcast())
|
||||
.forward(sender.input_sender(), identity);
|
||||
aboutpage.emit(AboutPageMsg::Show);
|
||||
}
|
||||
AppMsg::OpenPreferencesPage => {
|
||||
let preferencespage = PreferencesPageModel::builder()
|
||||
.launch(self.mainwindow.clone().upcast())
|
||||
.forward(sender.input_sender(), identity);
|
||||
preferencespage.emit(PreferencesPageMsg::Show(self.config.clone()));
|
||||
}
|
||||
AppMsg::AddInstalledToWorkQueue(work) => {
|
||||
let p = match work.pkgtype {
|
||||
InstallType::User => work.pname.to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user