Skip to content

Commit

Permalink
fix: First instance is not selected; user cannot login by MS
Browse files Browse the repository at this point in the history
  • Loading branch information
doabackflip authored and ci010 committed Oct 9, 2023
1 parent cada3b8 commit 5703081
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
11 changes: 10 additions & 1 deletion xmcl-keystone-ui/src/composables/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ export function useInstances() {
await deleteInstance(instancePath)
if (instancePath === lastSelected) {
path.value = instances.value[Math.max(index - 1, 0)]?.path ?? ''
if (!path.value) {
createInstance({
name: 'Minecraft',
}).then(p => {
path.value = p
})
}
}
}
watch(state, (newState) => {
if (!newState?.instances.length) {
const path = createInstance({
createInstance({
name: 'Minecraft',
}).then(p => {
path.value = p
})
}
})
Expand Down
1 change: 0 additions & 1 deletion xmcl-runtime-api/src/services/OfficialUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface OfficialUserServiceEventMap {
interval: number
message: string
}
'microsoft-authorize-code': [any, string]
}

export interface Skin {
Expand Down
5 changes: 4 additions & 1 deletion xmcl-runtime/lib/app/LauncherApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ export class LauncherApp extends EventEmitter {

this.managers = [this.taskManager, this.serviceStateManager, this.semaphoreManager, this.launcherAppManager]

this.localhostServerPort = listen(this.server, 25555, (cur) => cur + 7)
this.localhostServerPort = listen(this.server, 25555, (cur) => cur + 7).then((port) => {
this.logger.log(`Localhost server is listening on port ${port}`)
return port
})
}

getAppInstallerStartUpUrl(): string {
Expand Down
16 changes: 16 additions & 0 deletions xmcl-runtime/lib/plugins/pluginOfficialUserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ export const pluginOfficialUserApi: LauncherAppPlugin = (app) => {

userService.registerAccountSystem(AUTHORITY_MICROSOFT, system)

app.protocol.registerHandler('xmcl', ({ request, response }) => {
const parsed = request.url
if (parsed.host === 'launcher' && parsed.pathname === '/auth') {
let error: Error | undefined
if (parsed.searchParams.get('error')) {
const err = parsed.searchParams.get('error')!
const errDescription = parsed.searchParams.get('error')!
error = new Error(unescape(errDescription));
(error as any).error = err
}
const code = parsed.searchParams.get('code') as string
userService.emit('microsoft-authorize-code', error, code)
response.status = 200
}
})

const headers = {}
const legacyClient = new YggdrasilClient('https://authserver.mojang.com', {
dispatcher,
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/InstallService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { XMLParser } from 'fast-xml-parser'
*/
@ExposeServiceKey(InstallServiceKey)
export class InstallService extends AbstractService implements IInstallService {
private latestRelease = '1.20'
private latestRelease = '1.20.2'

constructor(@Inject(LauncherAppKey) app: LauncherApp,
@Inject(VersionService) private versionService: VersionService,
Expand Down
16 changes: 0 additions & 16 deletions xmcl-runtime/lib/services/OfficialUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ export class OfficialUserService extends AbstractService implements IOfficialUse
@Inject(kUserTokenStorage) private userTokenStorage: UserTokenStorage,
@Inject(MojangClient) private mojangApi: MojangClient) {
super(app)

app.protocol.registerHandler('xmcl', ({ request, response }) => {
const parsed = request.url
if (parsed.host === 'launcher' && parsed.pathname === '/auth') {
let error: Error | undefined
if (parsed.searchParams.get('error')) {
const err = parsed.searchParams.get('error')!
const errDescription = parsed.searchParams.get('error')!
error = new Error(unescape(errDescription));
(error as any).error = err
}
const code = parsed.searchParams.get('code') as string
this.emit('microsoft-authorize-code', error, code)
response.status = 200
}
})
}

async setName(user: UserProfile, name: string) {
Expand Down

0 comments on commit 5703081

Please sign in to comment.