mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
- 引入 electron-updater 实现自动更新功能 - 新增 Java 环境扫描与校验的 IPC 处理逻辑 - 实现离线账号登录功能 - 新增配置变更跨进程广播机制 - 重构游戏启动逻辑,使用主进程内存配置作为唯一权威来源 - 新增界面显示与语言设置的配置页面 - 添加 Windows 平台自动发布 CI 流水线 - 迁移旧版配置/认证文件到用户数据目录 - 修复崩溃日志路径、表单控件等多项 bug - 重构设置页组件系统统一界面样式
105 lines
2.7 KiB
TypeScript
105 lines
2.7 KiB
TypeScript
import { create } from "zustand";
|
|
import {
|
|
createInstance,
|
|
listInstances,
|
|
deleteInstance,
|
|
getInstanceInfo,
|
|
installInstance,
|
|
type InstanceInfo,
|
|
type InstanceRuntime,
|
|
} from "../api/instance";
|
|
|
|
interface InstanceState {
|
|
instances: InstanceInfo[];
|
|
currentInstance: InstanceInfo | null;
|
|
loading: boolean;
|
|
error: string | null;
|
|
|
|
fetchInstances: (gamePath: string) => Promise<void>;
|
|
create: (
|
|
name: string,
|
|
gamePath: string,
|
|
runtime: InstanceRuntime,
|
|
options?: {
|
|
author?: string;
|
|
description?: string;
|
|
java?: string;
|
|
minMemory?: number;
|
|
maxMemory?: number;
|
|
}
|
|
) => Promise<void>;
|
|
remove: (name: string, gamePath: string) => Promise<void>;
|
|
select: (name: string, gamePath: string) => Promise<void>;
|
|
install: (name: string, gamePath: string) => Promise<string>;
|
|
clearError: () => void;
|
|
}
|
|
|
|
export const useInstanceStore = create<InstanceState>((set) => ({
|
|
instances: [],
|
|
currentInstance: null,
|
|
loading: false,
|
|
error: null,
|
|
|
|
fetchInstances: async (gamePath: string) => {
|
|
set({ loading: true, error: null });
|
|
try {
|
|
const instances = await listInstances(gamePath);
|
|
set({ instances, loading: false });
|
|
} catch (e: any) {
|
|
set({ error: e.message, loading: false });
|
|
}
|
|
},
|
|
|
|
create: async (name, gamePath, runtime, options?) => {
|
|
set({ loading: true, error: null });
|
|
try {
|
|
const instance = await createInstance(name, gamePath, runtime, options);
|
|
set((state) => ({
|
|
instances: [...state.instances, instance],
|
|
loading: false,
|
|
}));
|
|
} catch (e: any) {
|
|
set({ error: e.message, loading: false });
|
|
}
|
|
},
|
|
|
|
remove: async (name: string, gamePath: string) => {
|
|
set({ loading: true, error: null });
|
|
try {
|
|
await deleteInstance(name, gamePath);
|
|
set((state) => ({
|
|
instances: state.instances.filter((i) => i.name !== name),
|
|
currentInstance:
|
|
state.currentInstance?.name === name ? null : state.currentInstance,
|
|
loading: false,
|
|
}));
|
|
} catch (e: any) {
|
|
set({ error: e.message, loading: false });
|
|
}
|
|
},
|
|
|
|
select: async (name: string, gamePath: string) => {
|
|
set({ loading: true, error: null });
|
|
try {
|
|
const instance = await getInstanceInfo(name, gamePath);
|
|
set({ currentInstance: instance, loading: false });
|
|
} catch (e: any) {
|
|
set({ error: e.message, loading: false });
|
|
}
|
|
},
|
|
|
|
install: async (name: string, gamePath: string) => {
|
|
set({ loading: true, error: null });
|
|
try {
|
|
const { requestId } = await installInstance(name, gamePath);
|
|
set({ loading: false });
|
|
return requestId;
|
|
} catch (e: any) {
|
|
set({ error: e.message, loading: false });
|
|
throw e;
|
|
}
|
|
},
|
|
|
|
clearError: () => set({ error: null }),
|
|
}));
|