Skip to content

Commit

Permalink
Merge branch 'master' of github.com:EaterLabs/emo-aardvark
Browse files Browse the repository at this point in the history
  • Loading branch information
the-eater committed Oct 24, 2019
2 parents a5e6c80 + 415a847 commit 5f804fa
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ the remote profile looks like the following:
"servers": [
{
"name": "Eater's server",
"ip": "raquel.voor.money"
"ip": "minecraft.example.org"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation 'net.swiftzer.semver:semver:1.0.0'
implementation 'javax.servlet:javax.servlet-api:4.0.1'
implementation 'org.bouncycastle:bcprov-jdk15on:1.61'
implementation 'com.mojang:authlib:1.5.22'
}

compileKotlin {
Expand Down
56 changes: 32 additions & 24 deletions src/main/kotlin/controllers/AardvarkController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,42 @@ class AardvarkController : Controller() {
profiles[profile.location] = ProfileState.Preparing
}

val launcherJson = File("${profile.location}/.emo/launcher.json")

val requiresOwnJava = if (launcherJson.exists()) {
val launchOptions = settingsKlaxon.parse<LaunchOptions>(launcherJson.readText())
launchOptions?.java != null
} else settings.javaStyle !is JavaStyle.System

val defaultJava: String? = if (requiresOwnJava) {
val style = settings.javaStyle
when (style) {
is JavaStyle.MinecraftJDK -> checkMinecraftJDK()
is JavaStyle.AdoptOpenJDK -> checkAdoptOpenJDK(style)
else -> null
try {
val launcherJson = File("${profile.location}/.emo/launcher.json")

val requiresOwnJava = if (launcherJson.exists()) {
val launchOptions = settingsKlaxon.parse<LaunchOptions>(launcherJson.readText())
launchOptions?.java != null
} else settings.javaStyle !is JavaStyle.System

val defaultJava: String? = if (requiresOwnJava) {
val style = settings.javaStyle
when (style) {
is JavaStyle.MinecraftJDK -> checkMinecraftJDK()
is JavaStyle.AdoptOpenJDK -> checkAdoptOpenJDK(style)
else -> null
}
} else
null

if (profile.location !in profileProcessWatchers) {
profileProcessWatchers.add(profile.location)
emoController.getProcessProperty(profile).onChange {
profiles[profile.location] = if (it == null || !it.isAlive)
ProfileState.Stopped
else
ProfileState.Running
}
}
} else
null

if (profile.location !in profileProcessWatchers) {
profileProcessWatchers.add(profile.location)
emoController.getProcessProperty(profile).onChange {
profiles[profile.location] = if (it == null || !it.isAlive)
ProfileState.Stopped
else
ProfileState.Running
emoController.play(profile, defaultJava)
} catch (e: Throwable) {
GlobalScope.launch(Dispatchers.JavaFx) {
profiles[profile.location] = ProfileState.Stopped
}
}

emoController.play(profile, defaultJava)
throw e
}
}

private val java: String
Expand Down
19 changes: 18 additions & 1 deletion src/main/kotlin/fragments/ProfileFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.eater.emo.aardvark.fragments

import com.mojang.authlib.exceptions.AuthenticationException
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon
import javafx.geometry.Pos
import javafx.scene.layout.Priority
Expand All @@ -12,7 +13,10 @@ import me.eater.emo.aardvark.controllers.AardvarkController
import me.eater.emo.aardvark.controllers.EmoController
import me.eater.emo.aardvark.controllers.InstallerController
import me.eater.emo.aardvark.utils.*
import me.eater.emo.aardvark.views.AccountsView
import me.eater.emo.aardvark.views.MainWindow
import me.eater.emo.aardvark.views.ProfilesView
import me.eater.emo.aardvark.views.account.AccountLoginView
import me.eater.emo.aardvark.views.profile.InstallerView
import me.eater.emo.aardvark.views.profile.ProfileSettings
import me.eater.emo.emo.dto.repository.Modpack
Expand Down Expand Up @@ -109,7 +113,20 @@ class ProfileFragment : Fragment() {
when (profileState) {
AardvarkController.ProfileState.Running -> aardvarkController.stop(profile.profile)
AardvarkController.ProfileState.Stopped -> GlobalScope.launch {
aardvarkController.play(profile.profile)
try {
aardvarkController.play(profile.profile)
} catch (e: AuthenticationException) {
GlobalScope.launch(Dispatchers.JavaFx) {
val accountsView = find<AccountsView>()
val accountLoginView = find<AccountLoginView>()
val mainWindow = find<MainWindow>()
mainWindow.selectAccounts()
accountsView.root.center.replaceWith(accountLoginView.root)
accountLoginView.tryLogin(emoController.account, e) {
mainWindow.selectProfiles()
}
}
}
}
else -> {
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/views/account/AccountLoginView.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.eater.emo.aardvark.views.account

import com.mojang.authlib.exceptions.AuthenticationException
import javafx.event.EventHandler
import javafx.geometry.Pos
import javafx.scene.control.Label
Expand All @@ -9,6 +10,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import me.eater.emo.Account
import me.eater.emo.aardvark.controllers.EmoController
import tornadofx.*

Expand All @@ -24,6 +26,8 @@ class AccountLoginView : View() {

private val accountListView: AccountListView by inject()

private var actionAfterLogin: (() -> Unit)? = null

override fun onDock() {
password = ""
username = ""
Expand Down Expand Up @@ -115,8 +119,25 @@ class AccountLoginView : View() {
return@ui
}

val action = actionAfterLogin
if (action != null) {
actionAfterLogin = null
action()
return@ui
}

replaceWith(accountListView)
}
}
}

fun tryLogin(account: Account?, e: AuthenticationException, afterLogin: () -> Unit) {
account?.username?.let {
username = it
}
actionAfterLogin = afterLogin
errorLabel.text = e.message
hasError = true
passwordField.requestFocus()
}
}
27 changes: 24 additions & 3 deletions src/main/kotlin/views/profile/InstallerView.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package me.eater.emo.aardvark.views.profile

import com.mojang.authlib.exceptions.AuthenticationException
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon
import javafx.animation.Timeline
import javafx.beans.value.WritableValue
import javafx.scene.control.Label
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import me.eater.emo.aardvark.controllers.AardvarkController
import me.eater.emo.aardvark.controllers.EmoController
import me.eater.emo.aardvark.controllers.InstallerController
import me.eater.emo.aardvark.fragments.ModpackFragment
import me.eater.emo.aardvark.utils.*
import me.eater.emo.aardvark.views.AccountsView
import me.eater.emo.aardvark.views.MainWindow
import me.eater.emo.aardvark.views.account.AccountLoginView
import tornadofx.*

class InstallerView : View() {
private val installerController: InstallerController by inject()
private val aardvarkController: AardvarkController by inject()
private val emoController: EmoController by inject()
private var modpackSlot = vbox()

private val rotateProperty = object : WritableValue<Double> {
Expand Down Expand Up @@ -150,11 +158,24 @@ class InstallerView : View() {
val state = installerController.state

if (state is InstallerController.State.Done) {
replaceWith<ProfileListingView>()

GlobalScope.launch {
aardvarkController.play(state.profile)
try {
aardvarkController.play(state.profile)
} catch (e: AuthenticationException) {
GlobalScope.launch(Dispatchers.JavaFx) {
val accountsView = find<AccountsView>()
val accountLoginView = find<AccountLoginView>()
val mainWindow = find<MainWindow>()
mainWindow.selectAccounts()
accountsView.root.center.replaceWith(accountLoginView.root)
accountLoginView.tryLogin(emoController.account, e) {
mainWindow.selectProfiles()
}
}
}
}

replaceWith<ProfileListingView>()
}
}
}
Expand Down

0 comments on commit 5f804fa

Please sign in to comment.