From c366f0b93e1f9863aed66d01fc86dc02167258b2 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 26 Feb 2024 19:06:41 -0500 Subject: [PATCH] Set up gio settings --- kifu/core/src/api.rs | 56 +++++++++++-------- kifu/core/src/lib.rs | 2 +- kifu/core/src/types.rs | 6 ++ kifu/gtk/build.rs | 2 +- kifu/gtk/{resources => }/gresources.xml | 0 kifu/gtk/override.nix | 10 ++-- ...om.luminescent-dreams.kifu.dev.gschema.xml | 13 +++++ .../com.luminescent-dreams.kifu.gschema.xml | 13 +++++ kifu/gtk/resources/kifu.desktop | 5 ++ kifu/gtk/src/main.rs | 23 +++++++- 10 files changed, 97 insertions(+), 33 deletions(-) rename kifu/gtk/{resources => }/gresources.xml (100%) create mode 100644 kifu/gtk/resources/com.luminescent-dreams.kifu.dev.gschema.xml create mode 100644 kifu/gtk/resources/com.luminescent-dreams.kifu.gschema.xml create mode 100644 kifu/gtk/resources/kifu.desktop diff --git a/kifu/core/src/api.rs b/kifu/core/src/api.rs index 8ec9d86..d09427f 100644 --- a/kifu/core/src/api.rs +++ b/kifu/core/src/api.rs @@ -1,6 +1,5 @@ use crate::{ - types::{AppState, Config, ConfigOption, DatabasePath, GameState, Player, Rank}, - ui::{configuration, home, playing_field, ConfigurationView, HomeView, PlayingFieldView}, + database::Database, types::{AppState, Config, ConfigOption, DatabasePath, GameState, Player, Rank}, ui::{configuration, home, playing_field, ConfigurationView, HomeView, PlayingFieldView} }; use serde::{Deserialize, Serialize}; use std::{ @@ -77,20 +76,21 @@ pub enum CoreResponse { #[derive(Clone, Debug)] pub struct CoreApp { - config: Arc>, - state: Arc>, + // config: Arc>, + // state: Arc>, + database: Arc>>, } impl CoreApp { - pub fn new(config_path: std::path::PathBuf) -> Self { - let config = Config::from_path(config_path).expect("configuration to open"); + pub fn new(config: Config) -> Self { + // let config = Config::from_path(config_path).expect("configuration to open"); - let db_path: DatabasePath = config.get().unwrap(); - let state = Arc::new(RwLock::new(AppState::new(db_path))); + // let state = Arc::new(RwLock::new(AppState::new(db_path))); Self { - config: Arc::new(RwLock::new(config)), - state, + // config: Arc::new(RwLock::new(config)), + // state, + database: Arc::new(RwLock::new(None)), } } @@ -98,14 +98,16 @@ impl CoreApp { match request { CoreRequest::ChangeSetting(request) => match request { ChangeSettingRequest::LibraryPath(path) => { - let mut config = self.config.write().unwrap(); - config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from( - path, - )))); - CoreResponse::UpdatedConfigurationView(configuration(&config)) + // let mut config = self.config.write().unwrap(); + // config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from( + // path, + // )))); + // CoreResponse::UpdatedConfigurationView(configuration(&config)) + unimplemented!() } }, CoreRequest::CreateGame(create_request) => { + /* let mut app_state = self.state.write().unwrap(); let white_player = { match create_request.white_player { @@ -124,24 +126,30 @@ impl CoreApp { }); let game_state = app_state.game.as_ref().unwrap(); CoreResponse::PlayingFieldView(playing_field(game_state)) + */ + unimplemented!() } CoreRequest::Home => { - CoreResponse::HomeView(home(self.state.read().unwrap().database.all_games())) + // CoreResponse::HomeView(home(self.state.read().unwrap().database.all_games())) + unimplemented!() } CoreRequest::OpenConfiguration => { - CoreResponse::ConfigurationView(configuration(&self.config.read().unwrap())) + // CoreResponse::ConfigurationView(configuration(&self.config.read().unwrap())) + unimplemented!() } CoreRequest::PlayingField => { - let app_state = self.state.read().unwrap(); - let game = app_state.game.as_ref().unwrap(); - CoreResponse::PlayingFieldView(playing_field(game)) + // let app_state = self.state.read().unwrap(); + // let game = app_state.game.as_ref().unwrap(); + // CoreResponse::PlayingFieldView(playing_field(game)) + unimplemented!() } CoreRequest::PlayStone(request) => { - let mut app_state = self.state.write().unwrap(); - app_state.place_stone(request); + // let mut app_state = self.state.write().unwrap(); + // app_state.place_stone(request); - let game = app_state.game.as_ref().unwrap(); - CoreResponse::PlayingFieldView(playing_field(game)) + // let game = app_state.game.as_ref().unwrap(); + // CoreResponse::PlayingFieldView(playing_field(game)) + unimplemented!() } CoreRequest::StartGame => { unimplemented!() diff --git a/kifu/core/src/lib.rs b/kifu/core/src/lib.rs index 3ad93c0..d5d377c 100644 --- a/kifu/core/src/lib.rs +++ b/kifu/core/src/lib.rs @@ -12,6 +12,6 @@ pub use board::*; mod database; mod types; -pub use types::{BoardError, Color, Rank, Size}; +pub use types::{BoardError, Color, Rank, Size, DatabasePath, Config, ConfigOption}; pub mod ui; diff --git a/kifu/core/src/types.rs b/kifu/core/src/types.rs index 86c00d9..99bcec2 100644 --- a/kifu/core/src/types.rs +++ b/kifu/core/src/types.rs @@ -25,6 +25,12 @@ impl std::ops::Deref for DatabasePath { } } +impl From for DatabasePath { + fn from(s: String) -> Self { + Self(PathBuf::from(s)) + } +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ConfigOption)] pub struct Me(Player); diff --git a/kifu/gtk/build.rs b/kifu/gtk/build.rs index 6e5a750..5a48d02 100644 --- a/kifu/gtk/build.rs +++ b/kifu/gtk/build.rs @@ -1,7 +1,7 @@ fn main() { glib_build_tools::compile_resources( &["resources"], - "resources/gresources.xml", + "gresources.xml", "com.luminescent-dreams.kifu-gtk.gresource", ); } diff --git a/kifu/gtk/resources/gresources.xml b/kifu/gtk/gresources.xml similarity index 100% rename from kifu/gtk/resources/gresources.xml rename to kifu/gtk/gresources.xml diff --git a/kifu/gtk/override.nix b/kifu/gtk/override.nix index cb5ea10..040dd61 100644 --- a/kifu/gtk/override.nix +++ b/kifu/gtk/override.nix @@ -4,11 +4,11 @@ let gsettingsDir = "${attrs.crateName}-${attrs.version}"; in { nativeBuildInputs = gtkNativeInputs; - # postInstall = '' - # install -Dt $out/share/applications resources/kifu.desktop - # install -Dt $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas resources/com.luminescent-dreams.fitnesstrax.gschema.xml - # glib-compile-schemas $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas - # ''; + postInstall = '' + install -Dt $out/share/applications resources/kifu.desktop + install -Dt $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas resources/com.luminescent-dreams.kifu.gschema.xml + glib-compile-schemas $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas + ''; # preFixup = '' # gappsWrapperArgs+=( # --prefix XDG_DATA_DIRS : $out/gsettings-schemas/${gsettingsDir} diff --git a/kifu/gtk/resources/com.luminescent-dreams.kifu.dev.gschema.xml b/kifu/gtk/resources/com.luminescent-dreams.kifu.dev.gschema.xml new file mode 100644 index 0000000..9918738 --- /dev/null +++ b/kifu/gtk/resources/com.luminescent-dreams.kifu.dev.gschema.xml @@ -0,0 +1,13 @@ + + + + + "" + Path to the directory of games + + + "" + Language override, use system settings if empty + + + \ No newline at end of file diff --git a/kifu/gtk/resources/com.luminescent-dreams.kifu.gschema.xml b/kifu/gtk/resources/com.luminescent-dreams.kifu.gschema.xml new file mode 100644 index 0000000..bed47e9 --- /dev/null +++ b/kifu/gtk/resources/com.luminescent-dreams.kifu.gschema.xml @@ -0,0 +1,13 @@ + + + + + "" + Path to the directory of games + + + "" + Language override, use system settings if empty + + + \ No newline at end of file diff --git a/kifu/gtk/resources/kifu.desktop b/kifu/gtk/resources/kifu.desktop new file mode 100644 index 0000000..540640e --- /dev/null +++ b/kifu/gtk/resources/kifu.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Version=0.2 +Type=Application +Name=Kifu +Exec=kifu \ No newline at end of file diff --git a/kifu/gtk/src/main.rs b/kifu/gtk/src/main.rs index e6089b2..124bc9a 100644 --- a/kifu/gtk/src/main.rs +++ b/kifu/gtk/src/main.rs @@ -1,5 +1,5 @@ use adw::prelude::*; -use kifu_core::{CoreApp, CoreRequest, CoreResponse}; +use kifu_core::{CoreApp, CoreRequest, CoreResponse, DatabasePath, Config, ConfigOption}; use kifu_gtk::{ perftrace, ui::{AppWindow, ConfigurationPage, Home, PlayingField}, @@ -7,6 +7,12 @@ use kifu_gtk::{ }; use std::sync::{Arc, RwLock}; + +const APP_ID_DEV: &str = "com.luminescent-dreams.kifu-gtk.dev"; +const APP_ID_PROD: &str = "com.luminescent-dreams.kifu-gtk"; + +const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/kifu-gtk/"; + fn handle_response(api: CoreApi, app_window: &AppWindow, message: CoreResponse) { let playing_field = Arc::new(RwLock::new(None)); match message { @@ -48,6 +54,17 @@ fn main() { gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource") .expect("Failed to register resources"); + let app_id = if std::env::var_os("ENV") == Some("dev".into()) { + APP_ID_DEV + } else { + APP_ID_PROD + }; + + let settings = gio::Settings::new(app_id); + let db_path: String = settings.string("database-path").into(); + let mut config = Config::new(); + config.set(ConfigOption::DatabasePath(db_path.into())); + let runtime = Arc::new( tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -55,6 +72,7 @@ fn main() { .unwrap(), ); + /* let config_path = std::env::var("CONFIG") .map(std::path::PathBuf::from) .or({ @@ -66,8 +84,9 @@ fn main() { }) }) .expect("no config path could be found"); + */ - let core = CoreApp::new(config_path); + let core = CoreApp::new(config); let core_handle = runtime.spawn({ let core = core.clone();