mirror of
				https://github.com/packwiz/packwiz-installer.git
				synced 2025-11-04 12:34:31 +01:00 
			
		
		
		
	Remove unnecessary Futures from IUserInterface API
This commit is contained in:
		@@ -336,17 +336,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
				
			|||||||
		val failedTaskDetails = tasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
 | 
							val failedTaskDetails = tasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
 | 
				
			||||||
		if (failedTaskDetails.isNotEmpty()) {
 | 
							if (failedTaskDetails.isNotEmpty()) {
 | 
				
			||||||
			errorsOccurred = true
 | 
								errorsOccurred = true
 | 
				
			||||||
			val exceptionListResult: ExceptionListResult
 | 
								when (ui.showExceptions(failedTaskDetails, tasks.size, true)) {
 | 
				
			||||||
			exceptionListResult = try {
 | 
					 | 
				
			||||||
				ui.showExceptions(failedTaskDetails, tasks.size, true).get()
 | 
					 | 
				
			||||||
			} catch (e: InterruptedException) { // Interrupted means cancelled???
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			} catch (e: ExecutionException) {
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			when (exceptionListResult) {
 | 
					 | 
				
			||||||
				ExceptionListResult.CONTINUE -> {}
 | 
									ExceptionListResult.CONTINUE -> {}
 | 
				
			||||||
				ExceptionListResult.CANCEL -> {
 | 
									ExceptionListResult.CANCEL -> {
 | 
				
			||||||
					cancelled = true
 | 
										cancelled = true
 | 
				
			||||||
@@ -370,18 +360,9 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
				
			|||||||
		// If options changed, present all options again
 | 
							// If options changed, present all options again
 | 
				
			||||||
		if (ui.optionsButtonPressed || optionTasks.any(DownloadTask::isNewOptional)) {
 | 
							if (ui.optionsButtonPressed || optionTasks.any(DownloadTask::isNewOptional)) {
 | 
				
			||||||
			// new ArrayList is required so it's an IOptionDetails rather than a DownloadTask list
 | 
								// new ArrayList is required so it's an IOptionDetails rather than a DownloadTask list
 | 
				
			||||||
			val cancelledResult = ui.showOptions(ArrayList(optionTasks))
 | 
								if (ui.showOptions(ArrayList(optionTasks))) {
 | 
				
			||||||
			try {
 | 
									cancelled = true
 | 
				
			||||||
				if (cancelledResult.get()) {
 | 
									handleCancellation()
 | 
				
			||||||
					cancelled = true
 | 
					 | 
				
			||||||
					// TODO: Should the UI be closed somehow??
 | 
					 | 
				
			||||||
					return
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} catch (e: InterruptedException) {
 | 
					 | 
				
			||||||
				// Interrupted means cancelled???
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
			} catch (e: ExecutionException) {
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ui.disableOptionsButton()
 | 
							ui.disableOptionsButton()
 | 
				
			||||||
@@ -445,18 +426,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
				
			|||||||
		val failedTasks2ElectricBoogaloo = nonFailedFirstTasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
 | 
							val failedTasks2ElectricBoogaloo = nonFailedFirstTasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
 | 
				
			||||||
		if (failedTasks2ElectricBoogaloo.isNotEmpty()) {
 | 
							if (failedTasks2ElectricBoogaloo.isNotEmpty()) {
 | 
				
			||||||
			errorsOccurred = true
 | 
								errorsOccurred = true
 | 
				
			||||||
			val exceptionListResult: ExceptionListResult
 | 
								when (ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size, false)) {
 | 
				
			||||||
			exceptionListResult = try {
 | 
					 | 
				
			||||||
				ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size, false).get()
 | 
					 | 
				
			||||||
			} catch (e: InterruptedException) {
 | 
					 | 
				
			||||||
				// Interrupted means cancelled???
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			} catch (e: ExecutionException) {
 | 
					 | 
				
			||||||
				ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			when (exceptionListResult) {
 | 
					 | 
				
			||||||
				ExceptionListResult.CONTINUE -> {}
 | 
									ExceptionListResult.CONTINUE -> {}
 | 
				
			||||||
				ExceptionListResult.CANCEL -> cancelled = true
 | 
									ExceptionListResult.CANCEL -> cancelled = true
 | 
				
			||||||
				ExceptionListResult.IGNORE -> cancelledStartGame = true
 | 
									ExceptionListResult.IGNORE -> cancelledStartGame = true
 | 
				
			||||||
@@ -465,18 +435,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private fun showCancellationDialog() {
 | 
						private fun showCancellationDialog() {
 | 
				
			||||||
		val cancellationResult: CancellationResult
 | 
							when (ui.showCancellationDialog()) {
 | 
				
			||||||
		cancellationResult = try {
 | 
					 | 
				
			||||||
			ui.showCancellationDialog().get()
 | 
					 | 
				
			||||||
		} catch (e: InterruptedException) {
 | 
					 | 
				
			||||||
			// Interrupted means cancelled???
 | 
					 | 
				
			||||||
			ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		} catch (e: ExecutionException) {
 | 
					 | 
				
			||||||
			ui.handleExceptionAndExit(e)
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		when (cancellationResult) {
 | 
					 | 
				
			||||||
			CancellationResult.QUIT -> cancelled = true
 | 
								CancellationResult.QUIT -> cancelled = true
 | 
				
			||||||
			CancellationResult.CONTINUE -> cancelledStartGame = true
 | 
								CancellationResult.CONTINUE -> cancelledStartGame = true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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.ExceptionDetails
 | 
				
			||||||
import link.infra.packwiz.installer.ui.data.IOptionDetails
 | 
					import link.infra.packwiz.installer.ui.data.IOptionDetails
 | 
				
			||||||
import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
					import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
				
			||||||
import java.util.concurrent.CompletableFuture
 | 
					 | 
				
			||||||
import java.util.concurrent.Future
 | 
					 | 
				
			||||||
import kotlin.system.exitProcess
 | 
					import kotlin.system.exitProcess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IUserInterface {
 | 
					interface IUserInterface {
 | 
				
			||||||
@@ -19,16 +17,12 @@ interface IUserInterface {
 | 
				
			|||||||
	fun setTitle(title: String) {}
 | 
						fun setTitle(title: String) {}
 | 
				
			||||||
	fun submitProgress(progress: InstallProgress)
 | 
						fun submitProgress(progress: InstallProgress)
 | 
				
			||||||
	// Return true if the installation was cancelled!
 | 
						// 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 disableOptionsButton() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fun showCancellationDialog(): Future<CancellationResult> {
 | 
						fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
 | 
				
			||||||
		return CompletableFuture<CancellationResult>().apply {
 | 
					 | 
				
			||||||
			complete(CancellationResult.QUIT)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum class ExceptionListResult {
 | 
						enum class ExceptionListResult {
 | 
				
			||||||
		CONTINUE, CANCEL, IGNORE
 | 
							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.ExceptionDetails
 | 
				
			||||||
import link.infra.packwiz.installer.ui.data.IOptionDetails
 | 
					import link.infra.packwiz.installer.ui.data.IOptionDetails
 | 
				
			||||||
import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
					import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
				
			||||||
import java.util.concurrent.CompletableFuture
 | 
					 | 
				
			||||||
import java.util.concurrent.Future
 | 
					 | 
				
			||||||
import kotlin.system.exitProcess
 | 
					import kotlin.system.exitProcess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CLIHandler : IUserInterface {
 | 
					class CLIHandler : IUserInterface {
 | 
				
			||||||
@@ -34,18 +32,16 @@ class CLIHandler : IUserInterface {
 | 
				
			|||||||
		println(sb.toString())
 | 
							println(sb.toString())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	override fun showOptions(options: List<IOptionDetails>): Future<Boolean> {
 | 
						override fun showOptions(options: List<IOptionDetails>): Boolean {
 | 
				
			||||||
		for (opt in options) {
 | 
							for (opt in options) {
 | 
				
			||||||
			opt.optionValue = true
 | 
								opt.optionValue = true
 | 
				
			||||||
			// TODO: implement option choice in the CLI?
 | 
								// TODO: implement option choice in the CLI?
 | 
				
			||||||
			println("Warning: accepting option " + opt.name + " as option choosing is not implemented in the CLI")
 | 
								println("Warning: accepting option " + opt.name + " as option choosing is not implemented in the CLI")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return CompletableFuture<Boolean>().apply {
 | 
							return false // Can't be cancelled!
 | 
				
			||||||
			complete(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:")
 | 
							println("Failed to download modpack, the following errors were encountered:")
 | 
				
			||||||
		for (ex in exceptions) {
 | 
							for (ex in exceptions) {
 | 
				
			||||||
			println(ex.name + ": ")
 | 
								println(ex.name + ": ")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,6 @@ import link.infra.packwiz.installer.ui.data.IOptionDetails
 | 
				
			|||||||
import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
					import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
				
			||||||
import java.awt.EventQueue
 | 
					import java.awt.EventQueue
 | 
				
			||||||
import java.util.concurrent.CompletableFuture
 | 
					import java.util.concurrent.CompletableFuture
 | 
				
			||||||
import java.util.concurrent.Future
 | 
					 | 
				
			||||||
import javax.swing.JDialog
 | 
					import javax.swing.JDialog
 | 
				
			||||||
import javax.swing.JOptionPane
 | 
					import javax.swing.JOptionPane
 | 
				
			||||||
import javax.swing.UIManager
 | 
					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>()
 | 
							val future = CompletableFuture<Boolean>()
 | 
				
			||||||
		EventQueue.invokeLater {
 | 
							EventQueue.invokeAndWait {
 | 
				
			||||||
			if (options.isEmpty()) {
 | 
								if (options.isEmpty()) {
 | 
				
			||||||
				JOptionPane.showMessageDialog(null,
 | 
									JOptionPane.showMessageDialog(null,
 | 
				
			||||||
					"This modpack has no optional mods!",
 | 
										"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>()
 | 
							val future = CompletableFuture<ExceptionListResult>()
 | 
				
			||||||
		EventQueue.invokeLater {
 | 
							EventQueue.invokeLater {
 | 
				
			||||||
			ExceptionListWindow(exceptions, future, numTotal, allowsIgnore, frmPackwizlauncher).apply {
 | 
								ExceptionListWindow(exceptions, future, numTotal, allowsIgnore, frmPackwizlauncher).apply {
 | 
				
			||||||
@@ -112,14 +111,14 @@ class GUIHandler : IUserInterface {
 | 
				
			|||||||
				isVisible = true
 | 
									isVisible = true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return future
 | 
							return future.get()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	override fun disableOptionsButton() = EventQueue.invokeLater {
 | 
						override fun disableOptionsButton() = EventQueue.invokeLater {
 | 
				
			||||||
		frmPackwizlauncher.disableOptionsButton()
 | 
							frmPackwizlauncher.disableOptionsButton()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	override fun showCancellationDialog(): Future<IUserInterface.CancellationResult> {
 | 
						override fun showCancellationDialog(): IUserInterface.CancellationResult {
 | 
				
			||||||
		val future = CompletableFuture<IUserInterface.CancellationResult>()
 | 
							val future = CompletableFuture<IUserInterface.CancellationResult>()
 | 
				
			||||||
		EventQueue.invokeLater {
 | 
							EventQueue.invokeLater {
 | 
				
			||||||
			val buttons = arrayOf("Quit", "Ignore")
 | 
								val buttons = arrayOf("Quit", "Ignore")
 | 
				
			||||||
@@ -129,6 +128,6 @@ class GUIHandler : IUserInterface {
 | 
				
			|||||||
					JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, buttons[0])
 | 
										JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, buttons[0])
 | 
				
			||||||
			future.complete(if (result == 0) IUserInterface.CancellationResult.QUIT else IUserInterface.CancellationResult.CONTINUE)
 | 
								future.complete(if (result == 0) IUserInterface.CancellationResult.QUIT else IUserInterface.CancellationResult.CONTINUE)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return future
 | 
							return future.get()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user