|
| 1 | +package com.vk.admstorm.startup |
| 2 | + |
| 3 | +import com.intellij.ide.util.PropertiesComponent |
| 4 | +import com.intellij.openapi.diagnostic.logger |
| 5 | +import com.intellij.openapi.options.advanced.AdvancedSettings |
| 6 | +import com.intellij.openapi.project.Project |
| 7 | +import com.intellij.ssh.config.SshConnectionConfigService |
| 8 | +import com.vk.admstorm.notifications.AdmNotification |
| 9 | + |
| 10 | +object ChangeSshBackendStartup { |
| 11 | + private val LOG = logger<ChangeSshBackendStartup>() |
| 12 | + |
| 13 | + private const val SSH_NOTIFICATOR_OPTION = "sshLegacyChanges" |
| 14 | + private const val SSH_CONFIG_BACKEND = "ssh.config.backend" |
| 15 | + |
| 16 | + private fun changeSshConfiguration(configValue: SshConnectionConfigService.Kind) { |
| 17 | + AdvancedSettings.setEnum(SSH_CONFIG_BACKEND, configValue) |
| 18 | + } |
| 19 | + |
| 20 | + fun changeConfigurationProcess(project: Project) { |
| 21 | + val dntShow = PropertiesComponent.getInstance(project).getBoolean(SSH_NOTIFICATOR_OPTION) |
| 22 | + if (dntShow) { |
| 23 | + LOG.info("LEGACY SSH option was enabled") |
| 24 | + return |
| 25 | + } |
| 26 | + |
| 27 | + val sshSettingValue = AdvancedSettings.getEnum(SSH_CONFIG_BACKEND, SshConnectionConfigService.Kind::class.java) |
| 28 | + if (sshSettingValue == SshConnectionConfigService.Kind.LEGACY) { |
| 29 | + PropertiesComponent.getInstance(project).setValue(SSH_NOTIFICATOR_OPTION, true) |
| 30 | + LOG.info("LEGACY SSH option was enabled before") |
| 31 | + return |
| 32 | + } |
| 33 | + |
| 34 | + changeSshConfiguration(SshConnectionConfigService.Kind.LEGACY) |
| 35 | + LOG.info("LEGACY SSH has been changed") |
| 36 | + |
| 37 | + AdmNotification("We changed your ssh type to LEGACY") |
| 38 | + .withActions( |
| 39 | + AdmNotification.Action("Don`t show it again") { _, notification -> |
| 40 | + LOG.info("LEGACY SSH option has been set") |
| 41 | + notification.expire() |
| 42 | + } |
| 43 | + ).withActions( |
| 44 | + AdmNotification.Action("Rollback and turn off this notification") { _, notification -> |
| 45 | + changeSshConfiguration(SshConnectionConfigService.Kind.OPENSSH) |
| 46 | + LOG.info("SSH option changed to OpenSSH") |
| 47 | + notification.expire() |
| 48 | + } |
| 49 | + ).show(project) |
| 50 | + |
| 51 | + PropertiesComponent.getInstance(project).setValue(SSH_NOTIFICATOR_OPTION, true) |
| 52 | + } |
| 53 | +} |
0 commit comments