Skip to content

Commit

Permalink
fix: New external instance should on the front of the list with corre…
Browse files Browse the repository at this point in the history
…ct name
  • Loading branch information
ci010 committed Jun 8, 2023
1 parent 3c7a30e commit 4c56244
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 1 addition & 5 deletions xmcl-keystone-ui/src/composables/instanceSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export function useSortedInstance() {
const { state } = useService(InstanceServiceKey)
const unordered = computed(() => state.instances)

const sorted = computed(() => {
const result = unordered.value.slice().sort((a, b) => ordered.value.indexOf(a.path) - ordered.value.indexOf(b.path))
// console.log(result)
return result
})
const sorted = computed(() => unordered.value.slice().reverse().sort((a, b) => ordered.value.indexOf(a.path) - ordered.value.indexOf(b.path)))

const setToPrevious = (instancePath: string, pivot: string) => {
const targetIndex = sorted.value.findIndex(v => v.path === pivot)
Expand Down
7 changes: 4 additions & 3 deletions xmcl-runtime/lib/services/InstanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,9 @@ export class InstanceService extends StatefulService<InstanceState> implements I
}))

if (!isVersionIsolated) {
const folderName = dirname(path)
const options: CreateInstanceOption = {
path,
name: isPathDiskRootPath(folderName) ? basename(path) : basename(folderName),
name: '',
}
if (profile) {
const sorted = Object.values(profile.profiles).sort((a, b) =>
Expand Down Expand Up @@ -576,11 +575,13 @@ export class InstanceService extends StatefulService<InstanceState> implements I
}
}

const dirPath = dirname(path)
const folderName = basename(dirPath)
if (folderName === 'minecraft' || folderName === '.minecraft') {
const name = getExpectVersion(options.runtime)
options.name = name
} else {
options.name = folderName
options.name = isPathDiskRootPath(dirPath) ? basename(path) : folderName
}

await this.createInstance(options)
Expand Down

0 comments on commit 4c56244

Please sign in to comment.