Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil42Russia committed Feb 9, 2024
1 parent a8dfb28 commit 6a48860
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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.startup.ChangeSshBackendStartup
import com.vk.admstorm.utils.MyUtils.measureTime
import com.vk.admstorm.utils.ServerNameProvider
import com.vk.admstorm.utils.extensions.pluginEnabled
Expand All @@ -42,6 +42,9 @@ class AdmStormStartupActivity : ProjectActivity {
return
}

ChangeSshBackendStartup.changeConfigurationProcess(project)
checkUpdates(project)

measureTime(LOG, "patch cpp highlight") {
val cppType = FileTypeChooser.getKnownFileTypeOrAssociate(".c") as AbstractFileType
CppTypeHighlightPatcher.patch(cppType)
Expand All @@ -53,9 +56,6 @@ class AdmStormStartupActivity : ProjectActivity {
}
}

changeConfigurationProcess(project)
checkUpdates(project)

// Это необходимо чтобы для бенчмарков показывались все пункты в списке
// который открывается при клике на иконку рядом с классом или методом.
val key = Registry.get("suggest.all.run.configurations.from.context")
Expand Down
53 changes: 53 additions & 0 deletions src/main/kotlin/com/vk/admstorm/startup/ChangeSshBackendStartup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.vk.admstorm.startup

import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.options.advanced.AdvancedSettings
import com.intellij.openapi.project.Project
import com.intellij.ssh.config.SshConnectionConfigService
import com.vk.admstorm.notifications.AdmNotification

object ChangeSshBackendStartup {
private val LOG = logger<ChangeSshBackendStartup>()

private const val SSH_NOTIFICATOR_OPTION = "sshLegacyChanges"
private const val SSH_CONFIG_BACKEND = "ssh.config.backend"

private fun changeSshConfiguration(configValue: SshConnectionConfigService.Kind) {
AdvancedSettings.setEnum(SSH_CONFIG_BACKEND, configValue)
}

fun changeConfigurationProcess(project: Project) {
val dntShow = PropertiesComponent.getInstance(project).getBoolean(SSH_NOTIFICATOR_OPTION)
if (dntShow) {
LOG.info("LEGACY SSH option was enabled")
return
}

val sshSettingValue = AdvancedSettings.getEnum(SSH_CONFIG_BACKEND, SshConnectionConfigService.Kind::class.java)
if (sshSettingValue == SshConnectionConfigService.Kind.LEGACY) {
PropertiesComponent.getInstance(project).setValue(SSH_NOTIFICATOR_OPTION, true)
LOG.info("LEGACY SSH option was enabled before")
return
}

changeSshConfiguration(SshConnectionConfigService.Kind.LEGACY)
LOG.info("LEGACY SSH has been changed")

AdmNotification("We changed your ssh type to LEGACY")
.withActions(
AdmNotification.Action("Don`t show it again") { _, notification ->
PropertiesComponent.getInstance(project).setValue(SSH_NOTIFICATOR_OPTION, true)
LOG.info("LEGACY SSH option has been set")
notification.expire()
}
).withActions(
AdmNotification.Action("Rollback and turn off this notification") { _, notification ->
changeSshConfiguration(SshConnectionConfigService.Kind.OPENSSH)
PropertiesComponent.getInstance(project).setValue(SSH_NOTIFICATOR_OPTION, true)
LOG.info("SSH option changed to OpenSSH")
notification.expire()
}
).show(project)
}
}
48 changes: 0 additions & 48 deletions src/main/kotlin/com/vk/admstorm/utils/MyUtils.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.vk.admstorm.utils

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
Expand All @@ -20,8 +17,6 @@ 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.notifications.AdmNotification
import com.vk.admstorm.utils.extensions.toHex
import org.apache.commons.io.input.ReversedLinesFileReader
import java.awt.Toolkit
Expand Down Expand Up @@ -234,47 +229,4 @@ object MyUtils {
}
}, delay)
}

fun changeSshConfiguration(configValue: Enum<SshConnectionConfigService.Kind>) {
AdvancedSettings.setEnum("ssh.config.backend", configValue)
}

fun changeConfigurationProcess(project: Project) {
val sshSettingValue =
AdvancedSettings.getEnum("ssh.config.backend", SshConnectionConfigService.Kind::class.java)
if (sshSettingValue == SshConnectionConfigService.Kind.LEGACY) {
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)
}
}
}

0 comments on commit 6a48860

Please sign in to comment.