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