feat: sync Aeronautics from launcher v2
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
- Tauri 2 native shell с безопасной командой `native_host`;
|
||||
- сохранение памяти профиля в локальном каталоге данных приложения;
|
||||
- безопасное обнаружение установленной Java (включая `JAVA_HOME`) перед запуском;
|
||||
- интеграция с фиксированным ShaCraft launcher v2 manifest для Aeronautics;
|
||||
- адаптивное окно для Windows, Linux и macOS;
|
||||
- базовая структура, в которую будут добавлены манифесты, проверка файлов,
|
||||
Java 21 и запуск Minecraft.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
mod java;
|
||||
mod manifest;
|
||||
mod profile;
|
||||
mod remote;
|
||||
mod settings;
|
||||
|
||||
use serde::Serialize;
|
||||
@@ -76,6 +77,30 @@ async fn sync_profile(app: AppHandle, manifest_json: String) -> Result<profile::
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
/// Loads and validates the published ShaCraft manifest before inspecting a profile.
|
||||
#[tauri::command]
|
||||
async fn inspect_remote_profile(app: AppHandle, profile_id: String) -> Result<profile::ProfileInspection, String> {
|
||||
let data_dir = app.path().app_data_dir()
|
||||
.map_err(|error| format!("Cannot resolve launcher data directory: {error}"))?;
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let manifest = remote::fetch_manifest(&profile_id).map_err(|error| error.to_string())?;
|
||||
profile::inspect(&data_dir.join("profiles").join(&manifest.id), &manifest)
|
||||
.map_err(|error| error.to_string())
|
||||
}).await.map_err(|error| format!("Profile inspection task failed: {error}"))?
|
||||
}
|
||||
|
||||
/// Downloads missing or changed ShaCraft-managed files from the fixed v2 endpoint.
|
||||
#[tauri::command]
|
||||
async fn sync_remote_profile(app: AppHandle, profile_id: String) -> Result<profile::SyncResult, String> {
|
||||
let data_dir = app.path().app_data_dir()
|
||||
.map_err(|error| format!("Cannot resolve launcher data directory: {error}"))?;
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let manifest = remote::fetch_manifest(&profile_id).map_err(|error| error.to_string())?;
|
||||
profile::sync(&data_dir.join("profiles").join(&manifest.id), &manifest)
|
||||
.map_err(|error| error.to_string())
|
||||
}).await.map_err(|error| format!("Profile synchronization task failed: {error}"))?
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn load_settings(app: AppHandle) -> Result<settings::LauncherSettings, String> {
|
||||
let data_dir = app
|
||||
@@ -108,6 +133,8 @@ pub fn run() {
|
||||
validate_manifest,
|
||||
inspect_profile,
|
||||
sync_profile,
|
||||
inspect_remote_profile,
|
||||
sync_remote_profile,
|
||||
load_settings,
|
||||
save_settings
|
||||
])
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
use crate::manifest::{self, Manifest};
|
||||
use reqwest::{blocking::Client, redirect::Policy};
|
||||
use std::{fmt, time::Duration};
|
||||
|
||||
const AERONAUTICS_MANIFEST: &str =
|
||||
"https://shacraft.ru/api/launcher/v2/profiles/aeronautics/manifest";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RemoteError {
|
||||
UnknownProfile,
|
||||
Network(reqwest::Error),
|
||||
Status(reqwest::StatusCode),
|
||||
TooLarge,
|
||||
InvalidManifest(manifest::ManifestError),
|
||||
}
|
||||
|
||||
impl fmt::Display for RemoteError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::UnknownProfile => formatter.write_str("Unknown ShaCraft profile"),
|
||||
Self::Network(error) => write!(formatter, "Cannot load ShaCraft manifest: {error}"),
|
||||
Self::Status(status) => write!(formatter, "ShaCraft manifest request failed: {status}"),
|
||||
Self::TooLarge => formatter.write_str("ShaCraft manifest is too large"),
|
||||
Self::InvalidManifest(error) => write!(formatter, "ShaCraft manifest is invalid: {error}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_manifest(profile_id: &str) -> Result<Manifest, RemoteError> {
|
||||
let url = match profile_id {
|
||||
"aeronautics" => AERONAUTICS_MANIFEST,
|
||||
_ => return Err(RemoteError::UnknownProfile),
|
||||
};
|
||||
let client = Client::builder()
|
||||
.timeout(Duration::from_secs(30))
|
||||
.redirect(Policy::none())
|
||||
.build()
|
||||
.map_err(RemoteError::Network)?;
|
||||
let response = client.get(url).send().map_err(RemoteError::Network)?;
|
||||
if !response.status().is_success() {
|
||||
return Err(RemoteError::Status(response.status()));
|
||||
}
|
||||
if response.content_length().is_some_and(|size| size > 2 * 1024 * 1024) {
|
||||
return Err(RemoteError::TooLarge);
|
||||
}
|
||||
let source = response.text().map_err(RemoteError::Network)?;
|
||||
manifest::validate_json(&source).map_err(RemoteError::InvalidManifest)
|
||||
}
|
||||
+50
-6
@@ -32,6 +32,7 @@ type Server = {
|
||||
version: string
|
||||
memory: string
|
||||
installed: boolean
|
||||
profileId?: string
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
@@ -51,6 +52,19 @@ type JavaInstallation = {
|
||||
version: string
|
||||
}
|
||||
|
||||
type ProfileInspection = {
|
||||
managedFiles: number
|
||||
missingFiles: number
|
||||
mismatchedFiles: number
|
||||
upToDate: boolean
|
||||
}
|
||||
|
||||
type SyncResult = {
|
||||
downloadedFiles: number
|
||||
reusedFiles: number
|
||||
downloadedBytes: number
|
||||
}
|
||||
|
||||
const servers: Server[] = [
|
||||
{
|
||||
id: 'aoc',
|
||||
@@ -61,6 +75,7 @@ const servers: Server[] = [
|
||||
version: '1.21.1 · NeoForge',
|
||||
memory: '6 ГБ',
|
||||
installed: true,
|
||||
profileId: 'aeronautics',
|
||||
},
|
||||
{
|
||||
id: 'create',
|
||||
@@ -83,6 +98,9 @@ function App() {
|
||||
const [ram, setRam] = useState(6)
|
||||
const [nativeHost, setNativeHost] = useState<NativeHost | null>(null)
|
||||
const [java, setJava] = useState<JavaInstallation | null | undefined>(undefined)
|
||||
const [profile, setProfile] = useState<ProfileInspection | null>(null)
|
||||
const [syncing, setSyncing] = useState(false)
|
||||
const [syncError, setSyncError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (progress === null) return
|
||||
@@ -106,6 +124,12 @@ function App() {
|
||||
invoke<JavaInstallation | null>('detect_java')
|
||||
.then(setJava)
|
||||
.catch(() => setJava(null))
|
||||
invoke<ProfileInspection>('inspect_remote_profile', { profileId: 'aeronautics' })
|
||||
.then((inspection) => {
|
||||
setProfile(inspection)
|
||||
setReady(inspection.upToDate)
|
||||
})
|
||||
.catch(() => undefined)
|
||||
}, [])
|
||||
|
||||
const updateRam = (memoryGb: number) => {
|
||||
@@ -116,8 +140,23 @@ function App() {
|
||||
}
|
||||
}
|
||||
|
||||
const repair = () => {
|
||||
const repair = async () => {
|
||||
if (selected.disabled) return
|
||||
if ('__TAURI_INTERNALS__' in window && selected.profileId) {
|
||||
setSyncError(null)
|
||||
setSyncing(true)
|
||||
setReady(false)
|
||||
try {
|
||||
const result = await invoke<SyncResult>('sync_remote_profile', { profileId: selected.profileId })
|
||||
setProfile({ managedFiles: result.downloadedFiles + result.reusedFiles, missingFiles: 0, mismatchedFiles: 0, upToDate: true })
|
||||
setReady(true)
|
||||
} catch (error) {
|
||||
setSyncError(error instanceof Error ? error.message : 'Не удалось синхронизировать сборку')
|
||||
} finally {
|
||||
setSyncing(false)
|
||||
}
|
||||
return
|
||||
}
|
||||
setReady(false)
|
||||
setProgress(0)
|
||||
}
|
||||
@@ -205,7 +244,12 @@ function App() {
|
||||
|
||||
<section className="play-dock">
|
||||
<div className="build-state">
|
||||
{progress !== null ? (
|
||||
{syncing ? (
|
||||
<>
|
||||
<span className="state-icon downloading"><Download size={19} /></span>
|
||||
<span><strong>Синхронизируем сборку</strong><small>Скачиваем и проверяем файлы</small></span>
|
||||
</>
|
||||
) : progress !== null ? (
|
||||
<>
|
||||
<span className="state-icon downloading"><Download size={19} /></span>
|
||||
<span>
|
||||
@@ -221,7 +265,7 @@ function App() {
|
||||
) : (
|
||||
<>
|
||||
<span className="state-icon"><ShieldCheck size={19} /></span>
|
||||
<span><strong>{ready ? 'Сборка готова' : 'Требуется проверка'}</strong><small>Обновлено сегодня в 21:42</small></span>
|
||||
<span><strong>{ready ? 'Сборка готова' : 'Требуется проверка'}</strong><small>{syncError || (profile ? `${profile.managedFiles} файлов под контролем` : 'Проверяем локальные файлы')}</small></span>
|
||||
</>
|
||||
)}
|
||||
{progress !== null && <div className="progress-track"><i style={{ width: `${progress}%` }} /></div>}
|
||||
@@ -232,16 +276,16 @@ function App() {
|
||||
<span><Gauge size={15} /> {ram} ГБ памяти</span>
|
||||
</div>
|
||||
|
||||
<button className="repair-button" onClick={repair} disabled={progress !== null || selected.disabled} aria-label="Проверить файлы">
|
||||
<button className="repair-button" onClick={repair} disabled={progress !== null || syncing || selected.disabled} aria-label="Проверить файлы">
|
||||
<RotateCcw size={19} />
|
||||
</button>
|
||||
<button
|
||||
className="play-button"
|
||||
disabled={progress !== null || selected.disabled}
|
||||
disabled={progress !== null || syncing || selected.disabled}
|
||||
onClick={() => !ready && repair()}
|
||||
>
|
||||
<Play size={21} fill="currentColor" />
|
||||
<span>{selected.disabled ? 'Недоступно' : progress !== null ? 'Обновление' : ready ? 'Играть' : 'Проверить'}</span>
|
||||
<span>{selected.disabled ? 'Недоступно' : syncing || progress !== null ? 'Обновление' : ready ? 'Играть' : 'Проверить'}</span>
|
||||
</button>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user