Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Check for updates only once (#71)
Browse files Browse the repository at this point in the history
* Fix update view padding and size

* Check for updates only once

* Lint

* Set current version before integration tests

* Improve build time

* Lint

Co-authored-by: andrea-vinci <[email protected]>
  • Loading branch information
andrewinci and andrewinci authored Oct 3, 2020
1 parent 8455324 commit 5104ce1
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m
org.gradle.caching=true
kotlin.incremental=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package insulator.integrationtest.helper

import insulator.di.CONFIG_FILE_NAME
import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.test.TestCaseOrder
import java.net.URLDecoder
import java.nio.file.Paths

object KotestConfig : AbstractProjectConfig() {

override val parallelism = 1
override val testCaseOrder = TestCaseOrder.Random

override fun beforeAll() {
mockCurrentAppVersion("999.999.999")
super.beforeAll()
}

fun mockCurrentAppVersion(version: String) {
val jarPath = Paths.get(this::class.java.protectionDomain.codeSource.location.toURI()).toString()
val jarFolder = Paths.get(URLDecoder.decode(jarPath, "UTF-8")).parent.toAbsolutePath().toString()
val configPath =
with(Paths.get(jarFolder, CONFIG_FILE_NAME).toAbsolutePath().toFile()) {
createNewFile()
writeText("app.version=$version")
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/insulator/lib/update/VersionChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VersionChecker(private val customJarPath: String? = null) {
get() = customJarPath ?: Paths.get(this::class.java.protectionDomain.codeSource.location.toURI()).toString()

fun getCurrentVersion() = Either.fx<Throwable, Version> {
val appVersion = !getAppVersion()
val appVersion = getAppVersion().fold({ "0.0.0" }, { it })
val latestVersion = !getLatestVersion()
val isANewVersionAvailable = Semver(appVersion).isLowerThan(latestVersion.version)
Version(appVersion, if (isANewVersionAvailable) latestVersion else null)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/insulator/styles/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import tornadofx.multi
import tornadofx.px

class Controls : Stylesheet() {
private val defaultPadding = 15.0.px
private val defaultPadding = 12.0.px

companion object {

Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/insulator/views/configurations/ListClusterView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import javafx.scene.layout.BorderPane
import javafx.stage.Modality
import javafx.stage.StageStyle
import tornadofx.* // ktlint-disable no-wildcard-imports
import java.util.concurrent.atomic.AtomicBoolean

class ListClusterView : InsulatorView<ListClusterViewModel>("Insulator", ListClusterViewModel::class) {

Expand Down Expand Up @@ -80,12 +81,19 @@ class ListClusterView : InsulatorView<ListClusterViewModel>("Insulator", ListClu
checkVersion()
}

private fun checkVersion() = VersionChecker().getCurrentVersion().map {
if (it.latestRelease != null) UpdateInfoView(it.latestRelease).customOpenWindow()
private fun checkVersion() {
if (wasVersionChecked.compareAndSet(false, true))
VersionChecker().getCurrentVersion().map {
if (it.latestRelease != null) UpdateInfoView(it.latestRelease).customOpenWindow(modality = Modality.WINDOW_MODAL)
}
}

override fun onError(throwable: Throwable) {
// we can't continue without the list of clusters
close()
}

companion object {
private val wasVersionChecked = AtomicBoolean(false)
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/insulator/views/update/UpdateInfoView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package insulator.views.update

import insulator.lib.update.Release
import insulator.styles.Controls
import insulator.styles.Titles
import javafx.geometry.Pos
import tornadofx.* // ktlint-disable no-wildcard-imports
Expand All @@ -21,13 +22,13 @@ class UpdateInfoView(release: Release) : View() {
bottom = hbox(alignment = Pos.CENTER) {
button("Close") { action { close() } }
}
paddingAll = 20.0
addClass(Controls.view)
}

override fun onDock() {
super.currentStage?.resizableProperty()?.set(false)
super.currentStage?.height = 300.0
super.currentStage?.width = 350.0
super.currentStage?.height = 350.0
super.currentStage?.width = 400.0
super.onDock()
}
}
9 changes: 9 additions & 0 deletions src/test/kotlin/helper/KotestConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package helper

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.test.TestCaseOrder

object KotestConfig : AbstractProjectConfig() {
override val parallelism = 1
override val testCaseOrder = TestCaseOrder.Random
}

0 comments on commit 5104ce1

Please sign in to comment.