forked from akanyan/STARTLINER
feat: more breaking changes
This commit is contained in:
@ -1,15 +1,40 @@
|
||||
import { Ref, computed, ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import * as path from '@tauri-apps/api/path';
|
||||
import { invoke } from './invoke';
|
||||
import { Game, Package, Profile, ProfileMeta } from './types';
|
||||
import { Dirs, Game, Package, Profile, ProfileMeta } from './types';
|
||||
import { changePrimaryColor, pkgKey } from './util';
|
||||
|
||||
type InstallStatus = {
|
||||
pkg: string;
|
||||
};
|
||||
|
||||
export const useGeneralStore = defineStore('general', () => {
|
||||
const dirs: Ref<Dirs | null> = ref(null);
|
||||
|
||||
const configDir = computed(() => {
|
||||
if (dirs.value === null) {
|
||||
throw new Error('Invalid directory access');
|
||||
}
|
||||
return dirs.value.config_dir;
|
||||
});
|
||||
const dataDir = computed(() => {
|
||||
if (dirs.value === null) {
|
||||
throw new Error('Invalid directory access');
|
||||
}
|
||||
return dirs.value.data_dir;
|
||||
});
|
||||
const cacheDir = computed(() => {
|
||||
if (dirs.value === null) {
|
||||
throw new Error('Invalid directory access');
|
||||
}
|
||||
return dirs.value.cache_dir;
|
||||
});
|
||||
|
||||
return { dirs, configDir, dataDir, cacheDir };
|
||||
});
|
||||
|
||||
export const usePkgStore = defineStore('pkg', {
|
||||
state: (): { pkg: { [key: string]: Package } } => {
|
||||
return {
|
||||
@ -113,25 +138,15 @@ export const usePrfStore = defineStore('prf', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const prompt = async () => {
|
||||
const exePath = await open({
|
||||
multiple: false,
|
||||
directory: false,
|
||||
filters: [
|
||||
{
|
||||
name: 'mu3.exe or chusanApp.exe',
|
||||
extensions: ['exe'],
|
||||
},
|
||||
],
|
||||
});
|
||||
if (exePath !== null) {
|
||||
await create(exePath);
|
||||
}
|
||||
};
|
||||
// Hack around PrimeVu not supporting WritableComputedRef
|
||||
const cfgAny = <T extends string | boolean | number>(
|
||||
key: string,
|
||||
dflt: T
|
||||
) => cfg(key, dflt) as any;
|
||||
|
||||
const create = async (exePath: string) => {
|
||||
const create = async (game: Game) => {
|
||||
try {
|
||||
await invoke('init_profile', { exePath });
|
||||
await invoke('init_profile', { game, name: 'new-profile' });
|
||||
await reload();
|
||||
await reloadList();
|
||||
} catch (e) {
|
||||
@ -173,6 +188,15 @@ export const usePrfStore = defineStore('prf', () => {
|
||||
await save();
|
||||
};
|
||||
|
||||
const generalStore = useGeneralStore();
|
||||
|
||||
const configDir = computed(async () => {
|
||||
return await path.join(
|
||||
generalStore.configDir,
|
||||
`profile-${current.value?.game}-${current.value?.name}`
|
||||
);
|
||||
});
|
||||
|
||||
listen<InstallStatus>('install-end', async () => {
|
||||
await reload();
|
||||
});
|
||||
@ -184,10 +208,11 @@ export const usePrfStore = defineStore('prf', () => {
|
||||
reload,
|
||||
save,
|
||||
cfg,
|
||||
prompt,
|
||||
cfgAny,
|
||||
create,
|
||||
switchTo,
|
||||
reloadList,
|
||||
togglePkg,
|
||||
configDir,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user