Set up gio settings

This commit is contained in:
Savanni D'Gerinel 2024-02-26 19:06:41 -05:00 committed by savanni
parent d3d3260091
commit 32cc74edfa
10 changed files with 97 additions and 33 deletions

View File

@ -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<RwLock<Config>>,
state: Arc<RwLock<AppState>>,
// config: Arc<RwLock<Config>>,
// state: Arc<RwLock<AppState>>,
database: Arc<RwLock<Option<Database>>>,
}
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!()

View File

@ -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;

View File

@ -25,6 +25,12 @@ impl std::ops::Deref for DatabasePath {
}
}
impl From<String> for DatabasePath {
fn from(s: String) -> Self {
Self(PathBuf::from(s))
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ConfigOption)]
pub struct Me(Player);

View File

@ -1,7 +1,7 @@
fn main() {
glib_build_tools::compile_resources(
&["resources"],
"resources/gresources.xml",
"gresources.xml",
"com.luminescent-dreams.kifu-gtk.gresource",
);
}

View File

@ -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}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema id="com.luminescent-dreams.kifu-gtk.dev" path="/com/luminescent-dreams/kifu-gtk/dev/">
<key name="database-path" type="s">
<default>""</default>
<summary>Path to the directory of games</summary>
</key>
<key name="language" type="s">
<default>""</default>
<summary>Language override, use system settings if empty</summary>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema id="com.luminescent-dreams.kifu-gtk" path="/com/luminescent-dreams/kifu-gtk/">
<key name="database-path" type="s">
<default>""</default>
<summary>Path to the directory of games</summary>
</key>
<key name="language" type="s">
<default>""</default>
<summary>Language override, use system settings if empty</summary>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,5 @@
[Desktop Entry]
Version=0.2
Type=Application
Name=Kifu
Exec=kifu

View File

@ -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();