mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 16:22:43 +10:00
beginnings of game state management
This commit is contained in:
@ -33,7 +33,7 @@
|
||||
</NuxtLink>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="grow">
|
||||
<div class="grow overflow-y-scroll">
|
||||
<NuxtPage />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -5,12 +5,22 @@
|
||||
<!-- banner image -->
|
||||
<div class="absolute flex top-0 h-fit inset-x-0 -z-[20]">
|
||||
<img :src="bannerUrl" class="w-full h-auto object-cover" />
|
||||
<h1
|
||||
class="absolute inset-x-0 w-full text-center top-32 -translate-y-[50%] text-4xl text-zinc-100 font-bold font-display z-50"
|
||||
>
|
||||
{{ game.mName }}
|
||||
</h1>
|
||||
<div
|
||||
class="absolute inset-0 bg-gradient-to-b from-transparent to-50% to-zinc-900"
|
||||
/>
|
||||
</div>
|
||||
<!-- main page -->
|
||||
<div class="w-full min-h-screen mx-auto bg-zinc-900 px-16 py-12"></div>
|
||||
<div class="w-full min-h-screen mx-auto bg-zinc-900 px-5 py-6">
|
||||
<!-- game toolbar -->
|
||||
<div>
|
||||
<GameButton v-model="status" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -21,8 +31,11 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
const route = useRoute();
|
||||
const id = route.params.id;
|
||||
|
||||
const rawGame = await invoke<string>("fetch_game", { id: id });
|
||||
const game: Game = JSON.parse(rawGame);
|
||||
const raw: { game: Game; status: any } = JSON.parse(
|
||||
await invoke<string>("fetch_game", { id: id })
|
||||
);
|
||||
const game = ref(raw.game);
|
||||
const status = ref(raw.status);
|
||||
|
||||
const bannerUrl = await useObject(game.mBannerId);
|
||||
const bannerUrl = await useObject(game.value.mBannerId);
|
||||
</script>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, create_dir_all},
|
||||
path::PathBuf,
|
||||
sync::LazyLock,
|
||||
@ -17,10 +18,20 @@ pub struct DatabaseAuth {
|
||||
pub client_id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Deserialize)]
|
||||
pub enum DatabaseGameStatus {
|
||||
Remote,
|
||||
Downloading,
|
||||
Installed,
|
||||
Updating,
|
||||
Uninstalling,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DatabaseApps {
|
||||
pub apps_base_dir: String,
|
||||
pub struct DatabaseGames {
|
||||
pub games_base_dir: String,
|
||||
pub games_statuses: HashMap<String, DatabaseGameStatus>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Deserialize)]
|
||||
@ -28,7 +39,7 @@ pub struct DatabaseApps {
|
||||
pub struct Database {
|
||||
pub auth: Option<DatabaseAuth>,
|
||||
pub base_url: String,
|
||||
pub downloads: DatabaseApps,
|
||||
pub games: DatabaseGames,
|
||||
}
|
||||
|
||||
pub type DatabaseInterface =
|
||||
@ -41,16 +52,17 @@ pub trait DatabaseImpls {
|
||||
impl DatabaseImpls for DatabaseInterface {
|
||||
fn set_up_database() -> DatabaseInterface {
|
||||
let db_path = DATA_ROOT_DIR.join("drop.db");
|
||||
let apps_base_dir = DATA_ROOT_DIR.join("apps");
|
||||
let games_base_dir = DATA_ROOT_DIR.join("games");
|
||||
|
||||
create_dir_all(DATA_ROOT_DIR.clone()).unwrap();
|
||||
create_dir_all(apps_base_dir.clone()).unwrap();
|
||||
create_dir_all(games_base_dir.clone()).unwrap();
|
||||
|
||||
let default = Database {
|
||||
auth: None,
|
||||
base_url: "".to_string(),
|
||||
downloads: DatabaseApps {
|
||||
apps_base_dir: apps_base_dir.to_str().unwrap().to_string(),
|
||||
games: DatabaseGames {
|
||||
games_base_dir: games_base_dir.to_str().unwrap().to_string(),
|
||||
games_statuses: HashMap::new(),
|
||||
},
|
||||
};
|
||||
#[allow(clippy::let_and_return)]
|
||||
|
||||
@ -147,8 +147,6 @@ pub fn run() {
|
||||
.join(object_id)
|
||||
.unwrap();
|
||||
|
||||
info!["{}", object_url.to_string()];
|
||||
|
||||
let header = generate_authorization_header();
|
||||
let client: reqwest::blocking::Client = reqwest::blocking::Client::new();
|
||||
let response = client
|
||||
|
||||
@ -6,6 +6,13 @@ use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::{auth::generate_authorization_header, AppState, DB};
|
||||
use crate::db::DatabaseImpls;
|
||||
use crate::db::DatabaseGameStatus;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct FetchGameStruct {
|
||||
game: Game,
|
||||
status: DatabaseGameStatus,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -16,7 +23,6 @@ pub struct Game {
|
||||
m_description: String,
|
||||
// mDevelopers
|
||||
// mPublishers
|
||||
|
||||
m_icon_id: String,
|
||||
m_banner_id: String,
|
||||
m_cover_id: String,
|
||||
@ -50,8 +56,16 @@ pub fn fetch_library(app: AppHandle) -> Result<String, String> {
|
||||
let state = app.state::<Mutex<AppState>>();
|
||||
let mut handle = state.lock().unwrap();
|
||||
|
||||
let mut db_handle = DB.borrow_data_mut().unwrap();
|
||||
|
||||
for game in games.iter() {
|
||||
handle.games.insert(game.id.clone(), game.clone());
|
||||
if !db_handle.games.games_statuses.contains_key(&game.id) {
|
||||
db_handle
|
||||
.games
|
||||
.games_statuses
|
||||
.insert(game.id.clone(), DatabaseGameStatus::Remote);
|
||||
}
|
||||
}
|
||||
|
||||
drop(handle);
|
||||
@ -64,9 +78,16 @@ pub fn fetch_game(id: String, app: tauri::AppHandle) -> Result<String, String> {
|
||||
let state = app.state::<Mutex<AppState>>();
|
||||
let handle = state.lock().unwrap();
|
||||
let game = handle.games.get(&id);
|
||||
if game.is_some() {
|
||||
return Ok(json!(game.unwrap()).to_string());
|
||||
if let Some(game) = game {
|
||||
let db_handle = DB.borrow_data().unwrap();
|
||||
|
||||
let data = FetchGameStruct {
|
||||
game: game.clone(),
|
||||
status: db_handle.games.games_statuses.get(&game.id).unwrap().clone(),
|
||||
};
|
||||
|
||||
return Ok(json!(data).to_string());
|
||||
}
|
||||
|
||||
Ok("".to_string())
|
||||
Err("".to_string())
|
||||
}
|
||||
|
||||
26
types.d.ts
vendored
26
types.d.ts
vendored
@ -1,17 +1,17 @@
|
||||
import type { User } from "@prisma/client";
|
||||
import type { Component } from "vue"
|
||||
import type { Component } from "vue";
|
||||
|
||||
export type NavigationItem = {
|
||||
prefix: string,
|
||||
route: string,
|
||||
label: string,
|
||||
}
|
||||
prefix: string;
|
||||
route: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
export type QuickActionNav = {
|
||||
icon: Component,
|
||||
notifications?: number,
|
||||
action: () => Promise<void>,
|
||||
}
|
||||
icon: Component;
|
||||
notifications?: number;
|
||||
action: () => Promise<void>;
|
||||
};
|
||||
export type AppState = {
|
||||
status: AppStatus;
|
||||
user?: User;
|
||||
@ -23,3 +23,11 @@ export enum AppStatus {
|
||||
SignedIn = "SignedIn",
|
||||
SignedInNeedsReauth = "SignedInNeedsReauth",
|
||||
}
|
||||
|
||||
export enum GameStatus {
|
||||
Remote = "Remote",
|
||||
Downloading = "Downloading",
|
||||
Installed = "Installed",
|
||||
Updating = "Updating",
|
||||
Uninstalling = "Uninstalling",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user