Skip to content

Commit

Permalink
refactor: Add notifier for some failure and adjust some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 22, 2024
1 parent 3e877e1 commit 3043402
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
5 changes: 4 additions & 1 deletion xmcl-keystone-ui/src/composables/modrinthInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ export function useModrinthInstallModpack(icon: Ref<string | undefined>) {
const installModpack = async (v: ProjectVersion) => {
const result = await installVersion({ version: v, icon: icon.value })
const resource = result.resources[0]

if (!resource) throw new Error('NO_RESOURCE')

const config = resolveModpackInstanceConfig(resource)

if (!config) return
if (!config) throw new Error('NO_MODPACK_CONFIG')
const name = generateDistinctName(config.name, instances.value.map(i => i.name))
const path = await createInstance({
...config,
Expand Down
6 changes: 5 additions & 1 deletion xmcl-keystone-ui/src/views/StoreProjectModrinth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { kModrinthTags } from '@/composables/modrinth'
import { useModrinthInstallModpack } from '@/composables/modrinthInstall'
import { useModrinthProject } from '@/composables/modrinthProject'
import { useModrinthVersions } from '@/composables/modrinthVersions'
import { useNotifier } from '@/composables/notifier'
import { usePresence } from '@/composables/presence'
import { kSWRVConfig } from '@/composables/swrvConfig'
import { useTasks } from '@/composables/task'
Expand Down Expand Up @@ -105,10 +106,13 @@ const project = computed(() => {
const { versions, error } = useModrinthVersions(computed(() => props.id))
const _installing = ref(false)
const { notify } = useNotifier()
const onInstall = (v: StoreProjectVersion) => {
const ver = v as ProjectVersion
_installing.value = true
installModpack(ver).finally(() => {
installModpack(ver).catch((e) => {
notify({ level: 'error', title: e.message })
}).finally(() => {
_installing.value = false
})
}
Expand Down
12 changes: 11 additions & 1 deletion xmcl-runtime-api/src/services/InstanceIOService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ export interface InstanceIOService {
exportInstance(options: ExportInstanceOptions): Promise<void>

getGameDefaultPath(type?: 'modrinth-root' | 'modrinth-instances' | 'vanilla'): Promise<string>
/**
* Parse instances folders
* @param path The instance or .minecraft folder path
* @param type Determine if this is a vanilla, mmc or modrinth folder
*/
parseInstances(path: string, type?: InstanceType): Promise<CreateInstanceManifest[]>
parseInstanceFiles(instancePath: string, type?: InstanceType): Promise<InstanceFile[]>
/**
* Parse the files from the path of instance or .minecraft folder
* @param path The instance or .minecraft folder path
* @param type Determine if this is a vanilla, mmc or modrinth folder
*/
parseInstanceFiles(path: string, type?: InstanceType): Promise<InstanceFile[]>
}

export type InstanceIOExceptions = InstanceNotFoundException | {
Expand Down
18 changes: 11 additions & 7 deletions xmcl-runtime-api/src/services/ModpackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,32 @@ export interface ImportModpackCreateInstanceOptions {
}

export interface ModpackInstallProfile {
/**
* @deprecated This can be derived from the modpack metadata
*/
instance: CreateInstanceOption & {
runtime: RuntimeVersions
}
files: InstanceFile[]
}

/**
* Provide the abilities to import/export instance from/to modpack file.
* For json format modpack like FTB, you can use the `InstanceIOService`
* Provide the abilities to parse the modpack files data.
* For json format modpack like FTB, you can use the `InstanceIOService` to do the actual install operation.
*/
export interface ModpackService {
/**
* Export the instance as an curseforge modpack
* @param options The curseforge modpack export options
* Export the instance as an curseforge/modrinth/mcbbs modpack
* @param options The curseforge/modrinth/mcbbs modpack export options
*/
exportModpack(options: ExportModpackOptions): Promise<void>
/**
* Get modpack installable files from the modpack. Use the `installInstanceFiles` to create an instance.
*/
getModpackInstallFiles(modpackPath: string): Promise<InstanceFile[]>
/**
* Get modpack install profile from the modpack. Use the `installInstanceFiles` to create an instance.
* Show the modpack folder
*/
getModpackInstallProfile(modpackPath: string): Promise<ModpackInstallProfile>

showModpacksFolder(): Promise<void>
}

Expand Down

0 comments on commit 3043402

Please sign in to comment.