// Server store — computed server state and RPC action proxies import { defineStore } from 'pinia' import { computed } from 'vue' import { rpcClient } from '../api/rpc-client' import { useSyncStore } from './sync' export const useServerStore = defineStore('server', () => { const sync = useSyncStore() // 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, // Actions installPackage, uninstallPackage, startPackage, stopPackage, restartPackage, updateServer, restartServer, shutdownServer, getMetrics, getMarketplace, updateServerName, } })