fix(gtk): move some network-dependent computation to background thread
This commit is contained in:
parent
56c25880e8
commit
b6ef0da344
|
@ -9,6 +9,10 @@ fun schedule(task: Runnable) {
|
||||||
SCHEDULED.add(task)
|
SCHEDULED.add(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun backgroundTask(task: Runnable) {
|
||||||
|
Thread.ofVirtual().start(task)
|
||||||
|
}
|
||||||
|
|
||||||
fun runScheduledTasks() {
|
fun runScheduledTasks() {
|
||||||
var r: Runnable?
|
var r: Runnable?
|
||||||
while (SCHEDULED.poll().also { r = it } != null) {
|
while (SCHEDULED.poll().also { r = it } != null) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.gtk.window.create
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.StringFormatter
|
import io.gitlab.jfronny.commons.StringFormatter
|
||||||
import io.gitlab.jfronny.inceptum.common.InceptumConfig
|
import io.gitlab.jfronny.inceptum.common.InceptumConfig
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.backgroundTask
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.KEntry
|
import io.gitlab.jfronny.inceptum.gtk.control.KEntry
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant
|
import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant
|
||||||
|
@ -137,12 +138,12 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
|
||||||
onClose { pState.cancel() }
|
onClose { pState.cancel() }
|
||||||
onCancel { pState.cancel() }
|
onCancel { pState.cancel() }
|
||||||
pState.updateStep("Starting install process")
|
pState.updateStep("Starting install process")
|
||||||
Thread {
|
backgroundTask {
|
||||||
try {
|
try {
|
||||||
for (step in Steps.STEPS) {
|
for (step in Steps.STEPS) {
|
||||||
if (state.isCancelled) {
|
if (state.isCancelled) {
|
||||||
state.tryRemoveInstance()
|
state.tryRemoveInstance()
|
||||||
return@Thread
|
return@backgroundTask
|
||||||
}
|
}
|
||||||
pState.incrementStep(step.name)
|
pState.incrementStep(step.name)
|
||||||
step.execute(state)
|
step.execute(state)
|
||||||
|
@ -159,7 +160,7 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
|
||||||
schedule { setComplete(true) }
|
schedule { setComplete(true) }
|
||||||
schedule { nextPage() }
|
schedule { nextPage() }
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page("Done", AssistantPageType.SUMMARY) {
|
page("Done", AssistantPageType.SUMMARY) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.gtk.window.dialog
|
||||||
import io.gitlab.jfronny.commons.StringFormatter
|
import io.gitlab.jfronny.commons.StringFormatter
|
||||||
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable
|
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable
|
||||||
import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend
|
import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.backgroundTask
|
||||||
import io.gitlab.jfronny.inceptum.gtk.schedule
|
import io.gitlab.jfronny.inceptum.gtk.schedule
|
||||||
import io.gitlab.jfronny.inceptum.gtk.util.I18n
|
import io.gitlab.jfronny.inceptum.gtk.util.I18n
|
||||||
import io.gitlab.jfronny.inceptum.gtk.util.Log
|
import io.gitlab.jfronny.inceptum.gtk.util.Log
|
||||||
|
@ -61,7 +62,7 @@ class ProcessStateWatcherDialog(
|
||||||
}
|
}
|
||||||
GLib.SOURCE_CONTINUE
|
GLib.SOURCE_CONTINUE
|
||||||
}
|
}
|
||||||
Thread {
|
backgroundTask {
|
||||||
try {
|
try {
|
||||||
executor.run()
|
executor.run()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
@ -78,7 +79,7 @@ class ProcessStateWatcherDialog(
|
||||||
finished = true
|
finished = true
|
||||||
schedule { close() }
|
schedule { close() }
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class State(val msg: String, val progress: Float) {
|
data class State(val msg: String, val progress: Float) {
|
||||||
|
|
|
@ -6,8 +6,11 @@ import io.gitlab.jfronny.commons.io.JFiles
|
||||||
import io.gitlab.jfronny.inceptum.common.InceptumConfig
|
import io.gitlab.jfronny.inceptum.common.InceptumConfig
|
||||||
import io.gitlab.jfronny.inceptum.common.MetaHolder
|
import io.gitlab.jfronny.inceptum.common.MetaHolder
|
||||||
import io.gitlab.jfronny.inceptum.common.Utils
|
import io.gitlab.jfronny.inceptum.common.Utils
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.backgroundTask
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
|
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.settings.SectionedSettingsTab
|
import io.gitlab.jfronny.inceptum.gtk.control.settings.SectionedSettingsTab
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.schedule
|
||||||
import io.gitlab.jfronny.inceptum.gtk.util.*
|
import io.gitlab.jfronny.inceptum.gtk.util.*
|
||||||
import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi
|
import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi
|
||||||
import io.gitlab.jfronny.inceptum.launcher.api.McApi
|
import io.gitlab.jfronny.inceptum.launcher.api.McApi
|
||||||
|
@ -53,7 +56,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
||||||
run {
|
run {
|
||||||
var fabricEnabled: Switch? = null
|
var fabricEnabled: Switch? = null
|
||||||
var versionChanged: (() -> Unit)? = null
|
var versionChanged: (() -> Unit)? = null
|
||||||
var fabricVersion: DropDown? = null
|
var fabricVersion: KDropDown<String>? = null
|
||||||
var defaultFabric: String? = null
|
var defaultFabric: String? = null
|
||||||
var fabricVersions: Array<String>? = null
|
var fabricVersions: Array<String>? = null
|
||||||
|
|
||||||
|
@ -61,7 +64,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
||||||
.filter { InceptumConfig.snapshots || it.type == "release" }
|
.filter { InceptumConfig.snapshots || it.type == "release" }
|
||||||
.map { it.id }
|
.map { it.id }
|
||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
val def = versions.withIndex().firstOrNull { it.value == instance.gameVersion }?.index ?: 0
|
val def = instance.gameVersion.let { gameVersion -> versions.withIndex().firstOrNull { it.value == gameVersion }?.index ?: 0 }
|
||||||
|
|
||||||
row("instance.settings.general.game.version", "instance.settings.general.game.version.subtitle") {
|
row("instance.settings.general.game.version", "instance.settings.general.game.version.subtitle") {
|
||||||
setDropdown(versions, def) { i ->
|
setDropdown(versions, def) { i ->
|
||||||
|
@ -93,7 +96,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
||||||
}
|
}
|
||||||
fabricEnabled.bindProperty("active", loaderRow, "visible", BindingFlags.DEFAULT)
|
fabricEnabled.bindProperty("active", loaderRow, "visible", BindingFlags.DEFAULT)
|
||||||
|
|
||||||
versionChanged = {
|
versionChanged = { backgroundTask {
|
||||||
val ver = VERSIONS.versions.stream()
|
val ver = VERSIONS.versions.stream()
|
||||||
.filter { it.id == instance.gameVersion }
|
.filter { it.id == instance.gameVersion }
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
@ -108,18 +111,21 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
||||||
fabricVersions = ver.map { Arrays.stream(it) }
|
fabricVersions = ver.map { Arrays.stream(it) }
|
||||||
.map { it.map { l -> l.loader.version }.toTypedArray() }
|
.map { it.map { l -> l.loader.version }.toTypedArray() }
|
||||||
.orElse(null)
|
.orElse(null)
|
||||||
if (fabricVersions == null || fabricVersions!!.isEmpty()) {
|
schedule {
|
||||||
fabricEnabled.active = false
|
if (fabricVersions == null || fabricVersions!!.isEmpty()) {
|
||||||
} else if (fabricVersion != null) fabricVersion!!.model = StringList(fabricVersions)
|
fabricEnabled.active = false
|
||||||
}
|
fabricVersion!!.updateOptions(arrayOf(), Gtk.INVALID_LIST_POSITION)
|
||||||
versionChanged()
|
} else fabricVersion!!.updateOptions(fabricVersions!!, fabricVersions!!.indexOf(defaultFabric))
|
||||||
|
}
|
||||||
|
} }
|
||||||
fabricVersion =
|
fabricVersion =
|
||||||
loaderRow.setDropdown(fabricVersions!!, fabricVersions!!.indexOf(defaultFabric)) { i: Int ->
|
loaderRow.setDropdown(arrayOf(), Gtk.INVALID_LIST_POSITION) { i: Int ->
|
||||||
instance.meta.gameVersion =
|
instance.meta.gameVersion =
|
||||||
if (i == -1) instance.gameVersion
|
if (i == -1) instance.gameVersion
|
||||||
else GameVersionParser.createVersionWithFabric(instance.gameVersion, fabricVersions!![i])
|
else GameVersionParser.createVersionWithFabric(instance.gameVersion, fabricVersions!![i])
|
||||||
instance.writeMeta()
|
instance.writeMeta()
|
||||||
}
|
}
|
||||||
|
versionChanged()
|
||||||
fabricVersion.enableSearch = true
|
fabricVersion.enableSearch = true
|
||||||
}
|
}
|
||||||
row("instance.settings.general.game.java", "instance.settings.general.game.java.subtitle") {
|
row("instance.settings.general.game.java", "instance.settings.general.game.java.subtitle") {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.gtk.window.settings.instance
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.concurrent.AsyncRequest
|
import io.gitlab.jfronny.commons.concurrent.AsyncRequest
|
||||||
import io.gitlab.jfronny.commons.concurrent.VoidFuture
|
import io.gitlab.jfronny.commons.concurrent.VoidFuture
|
||||||
|
import io.gitlab.jfronny.inceptum.gtk.backgroundTask
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
|
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
||||||
import io.gitlab.jfronny.inceptum.gtk.control.KSignalListItemFactory
|
import io.gitlab.jfronny.inceptum.gtk.control.KSignalListItemFactory
|
||||||
|
@ -154,7 +155,7 @@ class ModsTab(window: InstanceSettingsWindow) : SettingsTab<Leaflet, InstanceSet
|
||||||
fun updateSearch(search: String): Unit {
|
fun updateSearch(search: String): Unit {
|
||||||
descriptionLabel.text = "Searching is currently unsupported"
|
descriptionLabel.text = "Searching is currently unsupported"
|
||||||
currentSearchString = search
|
currentSearchString = search
|
||||||
this.search.request()
|
backgroundTask { this.search.request() }
|
||||||
}
|
}
|
||||||
fun selectMod(mod: ModState): Unit {
|
fun selectMod(mod: ModState): Unit {
|
||||||
//TODO detailed menu for version selection, ...
|
//TODO detailed menu for version selection, ...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user