Update the build environment and some architectural elements of the Kifu app #210

Merged
savanni merged 13 commits from kifu/flake into main 2024-02-28 04:42:58 +00:00
9 changed files with 99 additions and 9 deletions
Showing only changes of commit 6f94e15c5d - Show all commits

1
Cargo.lock generated
View File

@ -2240,6 +2240,7 @@ name = "kifu-gtk"
version = "0.1.0"
dependencies = [
"async-channel 2.1.1",
"async-std",
"cairo-rs",
"gio",
"glib",

View File

@ -80,13 +80,13 @@ pub enum CoreNotification {
}
#[derive(Clone, Debug)]
pub struct CoreApp {
pub struct Core {
// config: Arc<RwLock<Config>>,
// state: Arc<RwLock<AppState>>,
database: Arc<RwLock<Option<Database>>>,
}
impl CoreApp {
impl Core {
pub fn new(_config: Config) -> Self {
// let config = Config::from_path(config_path).expect("configuration to open");

View File

@ -2,8 +2,8 @@ extern crate config_derive;
mod api;
pub use api::{
ChangeSettingRequest, CoreApp, CoreRequest, CoreResponse, CreateGameRequest,
HotseatPlayerRequest, PlayerInfoRequest,
ChangeSettingRequest, Core, CoreRequest, CoreResponse, CreateGameRequest,
HotseatPlayerRequest, PlayerInfoRequest, CoreNotification,
};
mod board;

View File

@ -11,6 +11,7 @@ screenplay = []
[dependencies]
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
async-channel = { version = "2" }
async-std = { version = "1" }
cairo-rs = { version = "0.18" }
gio = { version = "0.18" }
glib = { version = "0.18" }

View File

@ -1,5 +1,10 @@
pub mod ui;
use kifu_core::{CoreApp, CoreRequest, CoreResponse};
mod view_models;
mod views;
use kifu_core::{Core, CoreRequest, CoreResponse};
use std::sync::Arc;
use tokio::{spawn, runtime::Runtime};
@ -7,7 +12,7 @@ use tokio::{spawn, runtime::Runtime};
pub struct CoreApi {
pub notification_tx: async_channel::Sender<CoreResponse>,
pub rt: Arc<Runtime>,
pub core: CoreApp,
pub core: Core,
}
impl CoreApi {

View File

@ -1,5 +1,5 @@
use adw::prelude::*;
use kifu_core::{CoreApp, CoreRequest, CoreResponse, DatabasePath, Config, ConfigOption};
use kifu_core::{Core, CoreRequest, CoreResponse, DatabasePath, Config, ConfigOption};
use kifu_gtk::{
perftrace,
ui::{AppWindow, ConfigurationPage, Home, PlayingField},
@ -7,7 +7,6 @@ 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";
@ -86,7 +85,7 @@ fn main() {
.expect("no config path could be found");
*/
let core = CoreApp::new(config);
let core = Core::new(config);
/*
let core_handle = runtime.spawn({

View File

@ -0,0 +1,59 @@
/*
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Kifu.
Kifu is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Kifu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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 async_channel::Receiver;
use async_std::task::{spawn, spawn_blocking, yield_now, JoinHandle};
use kifu_core::{Core, CoreNotification};
/// DatabaseViewModel controls the view that the user sees when starting the application if the application has been configured and if there are no games in progress. It provides a window into the database, showing a list of recently recorded games (whether from this app or from a main database). It also provides the UI for starting a new game. This will render an empty database view if the user hasn't configured a database yet.
pub struct DatabaseViewModel {
core: Core,
notification_handler: JoinHandle<()>,
widget: gtk::Box,
}
impl DatabaseViewModel {
fn new(core: Core, notifications: Receiver<CoreNotification>) -> Self {
let handler = spawn(async move {
loop {
let message = notifications.recv().await;
println!("Message received in DatabaseViewModel: {:?}", message);
yield_now().await;
}
});
Self {
core,
notification_handler: handler,
widget: gtk::Box::new(gtk::Orientation::Horizontal, 0),
}
}
/// Create a new game with the given parameters.
fn new_game(&self) {
unimplemented!()
}
/// Select a game from the database to show in detail. This will require a transition away from this view model into a different one.
fn select_game(&self) {
unimplemented!()
}
/// Delete a game from the database.
fn delete_game(&self) {
unimplemented!()
}
}

View File

@ -0,0 +1,25 @@
/*
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Kifu.
Kifu is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Kifu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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/>.
*/
/*
Every view model requires a reference to the app so that it can call functions on the core, and a notification receiver so that it can receive messages from the core.
The view model is primary over the view. It will construct the view, it can make major changes to the view or even swap for another related view. It must listen for all messages from the core, discarding those that aren't relevant to it. It will also convert requests from sync to async.
*/
mod database_view_model;
pub use database_view_model::DatabaseViewModel;

View File