mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-11-07 13:04:32 +01:00
Remove unnecessary Futures from IUserInterface API
This commit is contained in:
@@ -3,8 +3,6 @@ package link.infra.packwiz.installer.ui
|
||||
import link.infra.packwiz.installer.ui.data.ExceptionDetails
|
||||
import link.infra.packwiz.installer.ui.data.IOptionDetails
|
||||
import link.infra.packwiz.installer.ui.data.InstallProgress
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
interface IUserInterface {
|
||||
@@ -19,16 +17,12 @@ interface IUserInterface {
|
||||
fun setTitle(title: String) {}
|
||||
fun submitProgress(progress: InstallProgress)
|
||||
// Return true if the installation was cancelled!
|
||||
fun showOptions(options: List<IOptionDetails>): Future<Boolean>
|
||||
fun showOptions(options: List<IOptionDetails>): Boolean
|
||||
|
||||
fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult>
|
||||
fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): ExceptionListResult
|
||||
fun disableOptionsButton() {}
|
||||
|
||||
fun showCancellationDialog(): Future<CancellationResult> {
|
||||
return CompletableFuture<CancellationResult>().apply {
|
||||
complete(CancellationResult.QUIT)
|
||||
}
|
||||
}
|
||||
fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
|
||||
|
||||
enum class ExceptionListResult {
|
||||
CONTINUE, CANCEL, IGNORE
|
||||
|
||||
@@ -5,8 +5,6 @@ import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult
|
||||
import link.infra.packwiz.installer.ui.data.ExceptionDetails
|
||||
import link.infra.packwiz.installer.ui.data.IOptionDetails
|
||||
import link.infra.packwiz.installer.ui.data.InstallProgress
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class CLIHandler : IUserInterface {
|
||||
@@ -34,18 +32,16 @@ class CLIHandler : IUserInterface {
|
||||
println(sb.toString())
|
||||
}
|
||||
|
||||
override fun showOptions(options: List<IOptionDetails>): Future<Boolean> {
|
||||
override fun showOptions(options: List<IOptionDetails>): Boolean {
|
||||
for (opt in options) {
|
||||
opt.optionValue = true
|
||||
// TODO: implement option choice in the CLI?
|
||||
println("Warning: accepting option " + opt.name + " as option choosing is not implemented in the CLI")
|
||||
}
|
||||
return CompletableFuture<Boolean>().apply {
|
||||
complete(false) // Can't be cancelled!
|
||||
}
|
||||
return false // Can't be cancelled!
|
||||
}
|
||||
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): ExceptionListResult {
|
||||
println("Failed to download modpack, the following errors were encountered:")
|
||||
for (ex in exceptions) {
|
||||
println(ex.name + ": ")
|
||||
|
||||
@@ -7,7 +7,6 @@ import link.infra.packwiz.installer.ui.data.IOptionDetails
|
||||
import link.infra.packwiz.installer.ui.data.InstallProgress
|
||||
import java.awt.EventQueue
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
import javax.swing.JDialog
|
||||
import javax.swing.JOptionPane
|
||||
import javax.swing.UIManager
|
||||
@@ -86,9 +85,9 @@ class GUIHandler : IUserInterface {
|
||||
}
|
||||
}
|
||||
|
||||
override fun showOptions(options: List<IOptionDetails>): Future<Boolean> {
|
||||
override fun showOptions(options: List<IOptionDetails>): Boolean {
|
||||
val future = CompletableFuture<Boolean>()
|
||||
EventQueue.invokeLater {
|
||||
EventQueue.invokeAndWait {
|
||||
if (options.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"This modpack has no optional mods!",
|
||||
@@ -101,10 +100,10 @@ class GUIHandler : IUserInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
return future
|
||||
return future.get()
|
||||
}
|
||||
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): ExceptionListResult {
|
||||
val future = CompletableFuture<ExceptionListResult>()
|
||||
EventQueue.invokeLater {
|
||||
ExceptionListWindow(exceptions, future, numTotal, allowsIgnore, frmPackwizlauncher).apply {
|
||||
@@ -112,14 +111,14 @@ class GUIHandler : IUserInterface {
|
||||
isVisible = true
|
||||
}
|
||||
}
|
||||
return future
|
||||
return future.get()
|
||||
}
|
||||
|
||||
override fun disableOptionsButton() = EventQueue.invokeLater {
|
||||
frmPackwizlauncher.disableOptionsButton()
|
||||
}
|
||||
|
||||
override fun showCancellationDialog(): Future<IUserInterface.CancellationResult> {
|
||||
override fun showCancellationDialog(): IUserInterface.CancellationResult {
|
||||
val future = CompletableFuture<IUserInterface.CancellationResult>()
|
||||
EventQueue.invokeLater {
|
||||
val buttons = arrayOf("Quit", "Ignore")
|
||||
@@ -129,6 +128,6 @@ class GUIHandler : IUserInterface {
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, buttons[0])
|
||||
future.complete(if (result == 0) IUserInterface.CancellationResult.QUIT else IUserInterface.CancellationResult.CONTINUE)
|
||||
}
|
||||
return future
|
||||
return future.get()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user