Set up the settings user interface #225

Merged
savanni merged 5 commits from kifu/main-menu into main 2024-03-21 21:11:03 +00:00
2 changed files with 37 additions and 5 deletions
Showing only changes of commit de54ec676f - Show all commits

View File

@ -1,6 +1,8 @@
use adw::prelude::*;
use async_std::channel::Receiver;
use async_std::task::spawn;
use gio::ActionEntry;
use kifu_core::{Config, ConfigOption, Core};
use kifu_core::{Config, ConfigOption, Core, CoreNotification, LibraryPath, Observable};
use kifu_gtk::{
perftrace,
// ui::{ConfigurationPage, Home, PlayingField},
@ -14,6 +16,29 @@ const APP_ID_PROD: &str = "com.luminescent-dreams.kifu-gtk";
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/kifu-gtk/";
async fn handler(notifications: Receiver<CoreNotification>, app_id: String) {
loop {
let msg = notifications.recv().await;
match msg {
Ok(CoreNotification::ConfigurationUpdated(cfg)) => {
println!("commiting configuration");
let settings = gio::Settings::new(&app_id);
if let Some(LibraryPath(library_path)) = cfg.get() {
let _ = settings.set_string(
"library-path",
&library_path.into_os_string().into_string().unwrap(),
);
}
}
Ok(_) => println!("discarding message"),
Err(err) => {
println!("shutting down handler with error: {:?}", err);
return;
}
}
}
}
/*
fn handle_response(api: CoreApi, app_window: &AppWindow, message: CoreResponse) {
let playing_field = Arc::new(RwLock::new(None));
@ -107,6 +132,12 @@ fn main() {
let core = Core::new(config);
spawn({
let notifier = core.subscribe();
let app_id = app_id.to_owned();
handler(notifier, app_id)
});
/*
let core_handle = runtime.spawn({
let core = core.clone();
@ -121,14 +152,13 @@ fn main() {
.resource_base_path("/com/luminescent-dreams/kifu-gtk")
.build();
app.connect_activate({
let runtime = runtime.clone();
move |app| {
let mut app_window = AppWindow::new(app, core.clone());
match *core.library() {
Some(_) => {},
Some(_) => {}
None => app_window.open_settings(),
}

View File

@ -14,7 +14,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along with Kifu. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{cell::RefCell, path::Path, rc::Rc};
use std::{cell::RefCell, path::Path, rc::Rc, borrow::Cow};
use adw::prelude::*;
use glib::Object;
@ -23,6 +23,7 @@ use kifu_core::{Config, ConfigOption, LibraryPath};
fn library_chooser_row(
parent: &impl IsA<gtk::Window>,
library_path: Option<LibraryPath>,
on_library_chosen: Rc<impl Fn(ConfigOption) + 'static>,
) -> adw::ActionRow {
let dialog = gtk::FileDialog::builder().build();
@ -36,7 +37,7 @@ fn library_chooser_row(
let library_row = adw::ActionRow::builder()
.title("Library Path")
.subtitle("No library set")
.subtitle(library_path.map(|LibraryPath(path)| path.to_string_lossy().into_owned()).unwrap_or("No library set".to_owned()))
.css_classes(["preference-item"])
.build();
@ -104,6 +105,7 @@ impl SettingsView {
let library_row = library_chooser_row(
parent,
config.borrow().get(),
Rc::new({
let config = config.clone();
move |library_path| {