Skip to content

Commit

Permalink
format // more version check revert
Browse files Browse the repository at this point in the history
  • Loading branch information
meowjesty committed Oct 16, 2023
1 parent dd189de commit 7ad3d24
Showing 1 changed file with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class MirrordBinaryManager {
* Should be false if wslDistribution is unknown
*/
private class UpdateTask(
private val project: Project,
private val product: String?,
private val wslDistribution: WSLDistribution?,
private val checkInPath: Boolean
private val project: Project,
private val product: String?,
private val wslDistribution: WSLDistribution?,
private val checkInPath: Boolean
) : Task.Backgroundable(project, "mirrord", true), DumbAware {
companion object State {
/**
Expand All @@ -76,8 +76,7 @@ class MirrordBinaryManager {

val manager = service<MirrordBinaryManager>()

// val autoUpdate = MirrordSettingsState.instance.mirrordState.autoUpdate
val autoUpdate = false
val autoUpdate = MirrordSettingsState.instance.mirrordState.autoUpdate
val userSelectedMirrordVersion = MirrordSettingsState.instance.mirrordState.mirrordVersion

val version = when {
Expand All @@ -87,10 +86,10 @@ class MirrordBinaryManager {
userSelectedMirrordVersion
} else {
project
.service<MirrordProjectService>()
.notifier
.notification("mirrord version format is invalid!", NotificationType.WARNING)
.fire()
.service<MirrordProjectService>()
.notifier
.notification("mirrord version format is invalid!", NotificationType.WARNING)
.fire()
return
}
}
Expand All @@ -113,8 +112,8 @@ class MirrordBinaryManager {
}

manager.latestSupportedVersion = version
// auto update -> false -> mirrordVersion is empty -> no cli found locally -> fetch latest version
?: manager.fetchLatestSupportedVersion(product, indicator)
// auto update -> false -> mirrordVersion is empty -> no cli found locally -> fetch latest version
?: manager.fetchLatestSupportedVersion(product, indicator)

if (downloadInProgress.compareAndExchange(false, true)) {
return
Expand All @@ -128,8 +127,8 @@ class MirrordBinaryManager {
MirrordLogger.logger.debug("binary update task failed", error)

project.service<MirrordProjectService>()
.notifier
.notifyRichError("failed to update the mirrord binary: ${error.message ?: error.toString()}")
.notifier
.notifyRichError("failed to update the mirrord binary: ${error.message ?: error.toString()}")
}

override fun onFinished() {
Expand All @@ -141,12 +140,12 @@ class MirrordBinaryManager {
override fun onSuccess() {
downloadingVersion?.let {
project
.service<MirrordProjectService>()
.notifier
.notifySimple(
"downloaded mirrord binary version $downloadingVersion",
NotificationType.INFORMATION
)
.service<MirrordProjectService>()
.notifier
.notifySimple(
"downloaded mirrord binary version $downloadingVersion",
NotificationType.INFORMATION
)
}
}

Expand All @@ -161,8 +160,8 @@ class MirrordBinaryManager {

private fun fetchLatestSupportedVersion(product: String?, indicator: ProgressIndicator): String {
val pluginVersion = if (
System.getenv("CI_BUILD_PLUGIN") == "true" ||
System.getenv("PLUGIN_TESTING_ENVIRONMENT") == "true"
System.getenv("CI_BUILD_PLUGIN") == "true" ||
System.getenv("PLUGIN_TESTING_ENVIRONMENT") == "true"
) {
"test"
} else {
Expand All @@ -172,18 +171,18 @@ class MirrordBinaryManager {
indicator.text = "mirrord is checking the latest supported binary version..."

val url = StringBuilder(VERSION_ENDPOINT)
.append("?source=3")
.append("&version=")
.append(URLEncoder.encode(pluginVersion, Charset.defaultCharset()))
.append("&platform=")
.append(URLEncoder.encode(SystemInfo.OS_NAME, Charset.defaultCharset()))
.toString()
.append("?source=3")
.append("&version=")
.append(URLEncoder.encode(pluginVersion, Charset.defaultCharset()))
.append("&platform=")
.append(URLEncoder.encode(SystemInfo.OS_NAME, Charset.defaultCharset()))
.toString()

val client = HttpClient.newHttpClient()
val builder = HttpRequest
.newBuilder(URI(url))
.timeout(Duration.ofSeconds(10L))
.GET()
.newBuilder(URI(url))
.timeout(Duration.ofSeconds(10L))
.GET()

product?.let { builder.header("user-agent", it) }

Expand Down Expand Up @@ -261,7 +260,7 @@ class MirrordBinaryManager {
/**
* @return executable found with `which mirrord`
*/
private fun findBinaryInPath(requiredVersion: String?, wslDistribution: WSLDistribution?): MirrordBinary? {
private fun findBinaryInPath(requiredVersion: String?, wslDistribution: WSLDistribution?): MirrordBinary {
try {
val output = if (wslDistribution == null) {
val child = Runtime.getRuntime().exec(arrayOf("which", "mirrord"))
Expand Down Expand Up @@ -335,18 +334,18 @@ class MirrordBinaryManager {
} ?: "using a possibly outdated local installation with version ${it.version}"

project
.service<MirrordProjectService>()
.notifier
.notification(message, NotificationType.WARNING)
.withDontShowAgain(MirrordSettingsState.NotificationId.POSSIBLY_OUTDATED_BINARY_USED)
.fire()
.service<MirrordProjectService>()
.notifier
.notification(message, NotificationType.WARNING)
.withDontShowAgain(MirrordSettingsState.NotificationId.POSSIBLY_OUTDATED_BINARY_USED)
.fire()

return it.command
}

throw MirrordError(
"no local installation of mirrord binary was found",
"mirrord binary will be downloaded in the background"
"no local installation of mirrord binary was found",
"mirrord binary will be downloaded in the background"
)
}
}

0 comments on commit 7ad3d24

Please sign in to comment.