From 43fc6d4c38a590edba7831645ab5b8739bc0ad06 Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Thu, 8 Feb 2024 21:22:51 +0300 Subject: [PATCH] base solution --- .../vk/admstorm/AdmStormStartupActivity.kt | 2 + .../kotlin/com/vk/admstorm/utils/MyUtils.kt | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt b/src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt index fb4393ed..6b74d6af 100644 --- a/src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt +++ b/src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt @@ -17,6 +17,7 @@ import com.vk.admstorm.notifications.AdmNotification import com.vk.admstorm.services.SentryService import com.vk.admstorm.settings.AdmStormSettingsState import com.vk.admstorm.ssh.SshConnectionService +import com.vk.admstorm.utils.MyUtils.changeConfigurationProcess import com.vk.admstorm.utils.MyUtils.measureTime import com.vk.admstorm.utils.ServerNameProvider import com.vk.admstorm.utils.extensions.pluginEnabled @@ -52,6 +53,7 @@ class AdmStormStartupActivity : ProjectActivity { } } + changeConfigurationProcess(project) checkUpdates(project) // Это необходимо чтобы для бенчмарков показывались все пункты в списке diff --git a/src/main/kotlin/com/vk/admstorm/utils/MyUtils.kt b/src/main/kotlin/com/vk/admstorm/utils/MyUtils.kt index 419fee0e..884026ee 100644 --- a/src/main/kotlin/com/vk/admstorm/utils/MyUtils.kt +++ b/src/main/kotlin/com/vk/admstorm/utils/MyUtils.kt @@ -1,10 +1,14 @@ package com.vk.admstorm.utils +import com.intellij.ide.BrowserUtil +import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.PathManager import com.intellij.openapi.application.invokeAndWaitIfNeeded +import com.intellij.openapi.application.invokeLater import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.logger +import com.intellij.openapi.options.advanced.AdvancedSettings import com.intellij.openapi.progress.PerformInBackgroundOption import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager @@ -17,6 +21,11 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager +import com.intellij.ssh.config.SshConnectionConfigService +import com.vk.admstorm.env.Env +import com.vk.admstorm.env.getByKey +import com.vk.admstorm.notifications.AdmNotification +import com.vk.admstorm.notifications.AdmWarningNotification import com.vk.admstorm.utils.extensions.toHex import org.apache.commons.io.input.ReversedLinesFileReader import java.awt.Toolkit @@ -229,4 +238,58 @@ object MyUtils { } }, delay) } + + fun changeSshConfiguration(configValue: Enum) { + AdvancedSettings.setEnum("ssh.config.backend", configValue) + } + + fun changeConfigurationProcess(project: Project) { + val sshSettingValue = + AdvancedSettings.getEnum("ssh.config.backend", SshConnectionConfigService.Kind::class.java) + if (sshSettingValue.name.length == 6) { // is LEGACY, OPENSSH == 7 + return + } + + val docLink = Env.data.services.getByKey("sshLegacyWhy")?.url ?: return + + val dntShow = PropertiesComponent.getInstance(project).getBoolean("dntShowSshLegacy") + if (dntShow) { + return + } else { + val isSshLegacy = PropertiesComponent.getInstance(project).getBoolean("isSshLegacy") + if (isSshLegacy) { + return + } + + changeSshConfiguration(SshConnectionConfigService.Kind.LEGACY) + + AdmNotification("We changed your ssh type to LEGACY") + .withActions( + AdmNotification.Action("Don`t show it again") { _, notification -> + invokeLater { + PropertiesComponent.getInstance(project).setValue("dntShowSshLegacy", true) + notification.expire() + } + } + ).withActions( + AdmNotification.Action("Rollback and turn off this notification") { _, notification -> + invokeLater { + changeSshConfiguration(SshConnectionConfigService.Kind.OPENSSH) + PropertiesComponent.getInstance(project).setValue("dntShowSshLegacy", true) + notification.expire() + } + } + ) + .show(project) + + AdmWarningNotification("We changed your ssh type to LEGACY", true).withActions( + AdmNotification.Action("Why do we need this?") { _, notification -> + invokeLater { + BrowserUtil.browse(docLink) + notification.expire() + } + } + ).show(project) + } + } }