Skip to content

Commit

Permalink
Fix: Windows not supporting relative hardlinks
Browse files Browse the repository at this point in the history
Fix: Auth not being tracked as in progress task, allowing multiple game launches
  • Loading branch information
0ffz committed Mar 9, 2024
1 parent 8202bf2 commit 59f9f90
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=2.0.0-alpha.11
version=2.0.0-alpha.12
idofrontVersion=0.22.3
50 changes: 28 additions & 22 deletions src/main/kotlin/com/mineinabyss/launchy/logic/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.mineinabyss.launchy.logic

import com.mineinabyss.launchy.data.auth.SessionStorage
import com.mineinabyss.launchy.data.config.PlayerProfile
import com.mineinabyss.launchy.state.InProgressTask
import com.mineinabyss.launchy.state.LaunchyState
import com.mineinabyss.launchy.state.ProfileState
import com.mineinabyss.launchy.ui.screens.Dialog
import com.mineinabyss.launchy.ui.screens.dialog
Expand All @@ -12,34 +14,38 @@ import net.raphimc.minecraftauth.MinecraftAuth
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession.FullJavaSession
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode.MsaDeviceCode
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode.MsaDeviceCodeCallback
import java.util.UUID
import java.util.*


object Auth {
suspend fun authOrShowDialog(
state: ProfileState,
state: LaunchyState,
profile: ProfileState,
onAuthenticate: (FullJavaSession) -> Unit = {},
) = coroutineScope {
launch(Dispatchers.IO) {
if (state.currentProfile == null) dialog = Dialog.Auth
authFlow(
state,
onVerificationRequired = {
Browser.browse(it.redirectTo)
state.authCode = it.code
dialog = Dialog.Auth
println(state.authCode)
},
onAuthenticate = {
launch(Dispatchers.IO) {
SessionStorage.save(it)
if (profile.currentProfile == null) dialog = Dialog.Auth
state.runTask("auth", InProgressTask("Authenticating")) {
authFlow(
profile,
onVerificationRequired = {
state.inProgressTasks.remove("auth")
Browser.browse(it.redirectTo)
profile.authCode = it.code
dialog = Dialog.Auth
println(profile.authCode)
},
onAuthenticate = {
launch(Dispatchers.IO) {
SessionStorage.save(it)
}
profile.currentSession = it
profile.currentProfile = PlayerProfile(it.mcProfile.name, it.mcProfile.id)
dialog = Dialog.None
onAuthenticate(it)
}
state.currentSession = it
state.currentProfile = PlayerProfile(it.mcProfile.name, it.mcProfile.id)
dialog = Dialog.None
onAuthenticate(it)
}
)
)
}
}
}

Expand All @@ -55,7 +61,7 @@ object Auth {
) {
val httpClient = MinecraftAuth.createHttpClient()
val previousSession = state.currentProfile?.let { SessionStorage.load(it.uuid) }
if(previousSession != null) {
if (previousSession != null) {
val refreshedSession = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.refresh(httpClient, previousSession)
onAuthenticate(refreshedSession)
return
Expand All @@ -76,7 +82,7 @@ object Auth {

fun ProfileState.logout(uuid: UUID) {
SessionStorage.deleteIfExists(uuid)
if(currentProfile?.uuid == uuid) {
if (currentProfile?.uuid == uuid) {
currentProfile = null
currentSession = null
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mineinabyss/launchy/logic/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object Launcher {
}
// Auth or show dialog
when (val session = profile.currentSession) {
null -> Auth.authOrShowDialog(profile) {
null -> Auth.authOrShowDialog(state, profile) {
launch { launch(state, pack, profile) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object ModDownloader {
val linkDest = (instance.minecraftDir / relative)
if (!linkDest.isSymbolicLink()) linkDest.deleteIfExists()
if (linkDest.notExists())
linkDest.createLinkPointingTo(absolute.relativeTo(linkDest.parent))
linkDest.createLinkPointingTo(absolute)
linkDest
}
.toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun LeftSidebar() {
FloatingActionButton(
onClick = {
if (state.profile.currentProfile == null) coroutineScope.launch {
if (profile == null) Auth.authOrShowDialog(state.profile)
if (profile == null) Auth.authOrShowDialog(state, state.profile)
} else {
showAccountsPopup = !showAccountsPopup
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun AuthButton() {
enabled = state.profile.currentSession == null,
onClick = {
coroutineScope.launch {
Auth.authOrShowDialog(state.profile)
Auth.authOrShowDialog(state, state.profile)
}
},
) {
Expand Down

0 comments on commit 59f9f90

Please sign in to comment.