chore: Add more functions in trait
This commit is contained in:
parent
337c4878fd
commit
2b039cdb04
3 changed files with 35 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{env, error::Error, fs, path::PathBuf};
|
||||
use std::{collections::HashMap, env, error::Error, fs, path::PathBuf};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -60,6 +60,8 @@ pub fn get_game_client(handle: AppHandle, details: GameClientDetails) -> Box<dyn
|
|||
#[async_trait]
|
||||
pub trait GameClient {
|
||||
fn new(handle: AppHandle, details: GameClientDetails) -> Self where Self: Sized;
|
||||
fn get_version_urls() -> HashMap<String, String> where Self: Sized;
|
||||
fn get_details_from_version(version: String) -> Result<GameClientDetails, Box<dyn Error>> where Self: Sized;
|
||||
|
||||
fn get_handle(&self) -> &AppHandle;
|
||||
fn get_details(&self) -> &GameClientDetails;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::error::Error;
|
||||
use std::{collections::HashMap, error::Error};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use tauri::AppHandle;
|
||||
|
|
@ -9,6 +9,22 @@ use crate::{create_client, create_manifest, game::client::{GameClient, GameClien
|
|||
create_manifest!(VanillaManifest {});
|
||||
create_client!(VanillaClient {});
|
||||
|
||||
pub mod vanilla_impl {
|
||||
use std::error::Error;
|
||||
|
||||
pub async fn install_libraries() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn install_natives() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn install_assets() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl GameClient for VanillaClient {
|
||||
fn new(handle: AppHandle, details: GameClientDetails) -> Self {
|
||||
|
|
@ -18,6 +34,14 @@ impl GameClient for VanillaClient {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_version_urls() -> HashMap<String, String> {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn get_details_from_version(version: String) -> Result<GameClientDetails, Box<dyn Error>> {
|
||||
Err("a".into())
|
||||
}
|
||||
|
||||
fn get_handle(&self) -> &AppHandle {
|
||||
&self.handle
|
||||
}
|
||||
|
|
@ -31,9 +55,9 @@ impl GameClient for VanillaClient {
|
|||
}
|
||||
|
||||
async fn install(&self) -> Result<(), Box<dyn Error>> {
|
||||
println!("Installing Vanilla client");
|
||||
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
||||
println!("Vanilla client installed");
|
||||
vanilla_impl::install_libraries().await?;
|
||||
vanilla_impl::install_natives().await?;
|
||||
vanilla_impl::install_assets().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ function BrowserPage() {
|
|||
<div class="flex flex-col gap-y-4">
|
||||
<h1>Browser</h1>
|
||||
<Button
|
||||
// eslint-disable-next-line solid/reactivity
|
||||
onClick={async () => {
|
||||
const value = await invoke('plugin:game|launch_game');
|
||||
console.log(`hello${value}`);
|
||||
await invoke('plugin:game|launch_game');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Game exited`);
|
||||
}}
|
||||
>
|
||||
Test Button
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue