Skip to content

Commit

Permalink
Dialog methods revised
Browse files Browse the repository at this point in the history
  • Loading branch information
smh0505 committed Sep 14, 2024
1 parent 2ef191f commit 5afc0dd
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 25 deletions.
107 changes: 102 additions & 5 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [
tauri = { version = "1", features = [ "path-all",
"window-start-dragging",
"window-unminimize",
"window-close",
Expand All @@ -32,6 +32,7 @@ sea-orm = { version = "1.0.1", features = [
] }
sea-orm-migration = "1.0.1"
chrono = "0.4.38"
sysinfo = "0.31.4"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ impl From<tauri::Error> for BackendError {
}
}

impl From<tauri::api::Error> for BackendError {
fn from(value: tauri::api::Error) -> Self {
Self {
kind: String::from("tauri::api::Error"),
message: value.to_string(),
}
}
}

impl From<window_shadows::Error> for BackendError {
fn from(value: window_shadows::Error) -> Self {
Self {
Expand Down
14 changes: 9 additions & 5 deletions src-tauri/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ use crate::{
struct GameQuery;

impl GameQuery {
async fn create(db: &DbConn, form_data: game::Model) -> Result<game::ActiveModel, DbErr> {
async fn create(
db: &DbConn,
form_data: game::Model,
) -> Result<InsertResult<game::ActiveModel>, DbErr> {
let model = game::ActiveModel {
name: Set(form_data.name.to_owned()),
directory: Set(form_data.directory.to_owned()),
installed: Set(form_data.installed.to_owned()),
playtime: Set(form_data.playtime.to_owned()),
..Default::default()
};
Game::insert(model.clone()).exec(db).await?;
Ok(model)
let result = Game::insert(model.clone()).exec(db).await?;
Ok(result)
}

async fn read_page(
Expand Down Expand Up @@ -50,7 +53,7 @@ impl GameQuery {
pub async fn add_game(
state: tauri::State<'_, AppState>,
file: &str,
) -> Result<Response, BackendError> {
) -> Result<Response<i32>, BackendError> {
let dir = Path::new(file);
let form = game::Model {
id: 0,
Expand All @@ -70,11 +73,12 @@ pub async fn add_game(
playtime: 0,
};

GameQuery::create(&state.conn, form).await?;
let result = GameQuery::create(&state.conn, form).await?;

Ok(Response {
kind: "success".to_owned(),
message: "GameQuery::Create successful".to_owned(),
result: Some(result.last_insert_id),
})
}

Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ struct AppState {
}

#[derive(Deserialize, Serialize, Debug, Clone)]
struct Response {
struct Response<T> {
kind: String,
message: String,
result: Option<T>
}

fn main() {
Expand All @@ -43,6 +44,8 @@ fn main() {
game::add_game,
game::list_games,
window::open_file_dialog,
window::get_items,
window::get_parent
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
Loading

0 comments on commit 5afc0dd

Please sign in to comment.