mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-05-06 12:36:30 +02:00
Fix Swing multithreading issue, clean up slightly
This commit is contained in:
parent
ecc6f0440a
commit
b3370739a5
@ -18,6 +18,9 @@ import kotlin.system.exitProcess
|
||||
|
||||
@Suppress("unused")
|
||||
class Main(args: Array<String>) {
|
||||
// Don't attempt to start a GUI if we are headless
|
||||
var guiEnabled = !GraphicsEnvironment.isHeadless()
|
||||
|
||||
private fun startup(args: Array<String>) {
|
||||
val options = Options()
|
||||
addNonBootstrapOptions(options)
|
||||
@ -28,19 +31,24 @@ class Main(args: Array<String>) {
|
||||
parser.parse(options, args)
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
if (guiEnabled) {
|
||||
EventQueue.invokeAndWait {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
|
||||
} catch (e1: Exception) {
|
||||
} catch (ignored: Exception) {
|
||||
// Ignore the exceptions, just continue using the ugly L&F
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, e.message, "packwiz-installer", JOptionPane.ERROR_MESSAGE)
|
||||
}
|
||||
}
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
// if "headless", GUI creation will fail anyway!
|
||||
val ui = if (cmd.hasOption("no-gui") || GraphicsEnvironment.isHeadless()) {
|
||||
CLIHandler()
|
||||
} else InstallWindow()
|
||||
if (guiEnabled && cmd.hasOption("no-gui")) {
|
||||
guiEnabled = false
|
||||
}
|
||||
|
||||
val ui = if (guiEnabled) InstallWindow() else CLIHandler()
|
||||
|
||||
val unparsedArgs = cmd.args
|
||||
if (unparsedArgs.size > 1) {
|
||||
@ -49,15 +57,13 @@ class Main(args: Array<String>) {
|
||||
ui.handleExceptionAndExit(RuntimeException("URI to install from must be specified!"))
|
||||
}
|
||||
|
||||
cmd.getOptionValue("title")?.also {
|
||||
ui.setTitle(it)
|
||||
}
|
||||
cmd.getOptionValue("title")?.also(ui::setTitle)
|
||||
|
||||
val inputStateHandler = InputStateHandler()
|
||||
ui.show(inputStateHandler)
|
||||
|
||||
val uOptions = UpdateManager.Options().apply {
|
||||
side = cmd.getOptionValue("side")?.let { UpdateManager.Options.Side.from(it) } ?: side
|
||||
side = cmd.getOptionValue("side")?.let((UpdateManager.Options.Side)::from) ?: side
|
||||
packFolder = cmd.getOptionValue("pack-folder") ?: packFolder
|
||||
manifestFile = cmd.getOptionValue("meta-file") ?: manifestFile
|
||||
}
|
||||
@ -113,12 +119,14 @@ class Main(args: Array<String>) {
|
||||
startup(args)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
if (guiEnabled) {
|
||||
EventQueue.invokeLater {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"A fatal error occurred: \n" + e.javaClass.canonicalName + ": " + e.message,
|
||||
"packwiz-installer", JOptionPane.ERROR_MESSAGE)
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
// In case the EventQueue is broken, exit after 1 minute
|
||||
Thread.sleep(60 * 1000.toLong())
|
||||
exitProcess(1)
|
||||
|
@ -10,10 +10,10 @@ import javax.swing.border.EmptyBorder
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class InstallWindow : IUserInterface {
|
||||
private val frmPackwizlauncher: JFrame
|
||||
private val lblProgresslabel: JLabel
|
||||
private val progressBar: JProgressBar
|
||||
private val btnOptions: JButton
|
||||
private lateinit var frmPackwizlauncher: JFrame
|
||||
private lateinit var lblProgresslabel: JLabel
|
||||
private lateinit var progressBar: JProgressBar
|
||||
private lateinit var btnOptions: JButton
|
||||
|
||||
private var inputStateHandler: InputStateHandler? = null
|
||||
private var title = "Updating modpack..."
|
||||
@ -23,6 +23,7 @@ class InstallWindow : IUserInterface {
|
||||
// TODO: separate JFrame junk from IUserInterface junk?
|
||||
|
||||
init {
|
||||
EventQueue.invokeAndWait {
|
||||
frmPackwizlauncher = JFrame().apply {
|
||||
title = this@InstallWindow.title
|
||||
setBounds(100, 100, 493, 95)
|
||||
@ -74,6 +75,7 @@ class InstallWindow : IUserInterface {
|
||||
}, BorderLayout.EAST)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun show(handler: InputStateHandler) {
|
||||
inputStateHandler = handler
|
||||
|
Loading…
x
Reference in New Issue
Block a user