// Server store — computed server state and RPC action proxies import { defineStore } from 'pinia' import { computed, ref } from 'vue' import { rpcClient } from '../api/rpc-client' import { useSyncStore } from './sync' import type { InstallProgress } from '../views/marketplace/marketplaceData' export const useServerStore = defineStore('server', () => { const sync = useSyncStore() // Global install tracking — persists across navigation const installingApps = ref>(new Map()) function setInstallProgress(appId: string, progress: Partial & { id: string; title: string }) { const existing = installingApps.value.get(appId) installingApps.value.set(appId, { status: 'downloading', progress: 0, message: 'Preparing...', attempt: 0, ...existing, ...progress, }) } function clearInstallProgress(appId: string) { installingApps.value.delete(appId) } function isInstalling(appId: string): boolean { return installingApps.value.has(appId) } // Computed — derived from sync store's data const serverName = computed(() => sync.serverInfo?.name || 'Archipelago') const isRestarting = computed(() => sync.serverInfo?.['status-info']?.restarting || false) const isShuttingDown = computed(() => sync.serverInfo?.['status-info']?.['shutting-down'] || false) const isOffline = computed(() => !sync.isConnected || isRestarting.value || isShuttingDown.value) // Package actions async function installPackage(id: string, marketplaceUrl: string, version: string): Promise { return rpcClient.installPackage(id, marketplaceUrl, version) } async function uninstallPackage(id: string): Promise { return rpcClient.uninstallPackage(id) } async function startPackage(id: string): Promise { return rpcClient.startPackage(id) } async function stopPackage(id: string): Promise { return rpcClient.stopPackage(id) } async function restartPackage(id: string): Promise { return rpcClient.restartPackage(id) } // Server actions async function updateServer(marketplaceUrl: string): Promise<'updating' | 'no-updates'> { return rpcClient.updateServer(marketplaceUrl) } async function restartServer(): Promise { return rpcClient.restartServer() } async function shutdownServer(): Promise { return rpcClient.shutdownServer() } async function getMetrics(): Promise> { return rpcClient.getMetrics() } // Marketplace actions async function getMarketplace(url: string): Promise> { return rpcClient.getMarketplace(url) } function updateServerName(name: string) { if (sync.data?.['server-info']) { sync.data['server-info'].name = name } } return { // Computed serverName, isRestarting, isShuttingDown, isOffline, // Install tracking (global, persists across navigation) installingApps, setInstallProgress, clearInstallProgress, isInstalling, // Actions installPackage, uninstallPackage, startPackage, stopPackage, restartPackage, updateServer, restartServer, shutdownServer, getMetrics, getMarketplace, updateServerName, } })