diff --git a/changelog.d/268.added.md b/changelog.d/268.added.md new file mode 100644 index 00000000..278c3705 --- /dev/null +++ b/changelog.d/268.added.md @@ -0,0 +1 @@ +Add the option for mirrord to be enabled by default on startup in settings \ No newline at end of file diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordEnabler.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordEnabler.kt index 2568ca74..ff0b1e56 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordEnabler.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordEnabler.kt @@ -1,13 +1,17 @@ package com.metalbear.mirrord +import com.intellij.ide.ActivityTracker import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.ToggleAction import com.intellij.openapi.components.service import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.project.Project +import com.intellij.openapi.startup.StartupActivity +import com.metalbear.mirrord.MirrordSettingsState.Companion.instance import icons.MirrordIcons -class MirrordEnabler : ToggleAction(), DumbAware { +class MirrordEnabler : ToggleAction(), DumbAware, StartupActivity, StartupActivity.DumbAware { override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT override fun isSelected(e: AnActionEvent): Boolean { @@ -23,7 +27,16 @@ class MirrordEnabler : ToggleAction(), DumbAware { override fun update(e: AnActionEvent) { e.presentation.isVisible = true e.presentation.isEnabled = e.project != null + val state = e.project?.service()?.enabled ?: false + e.presentation.icon = if (state) MirrordIcons.enabled else MirrordIcons.disabled super.update(e) } + + override fun runActivity(project: Project) { + if (instance.mirrordState.enabledByDefault) { + project.service().enabled = true + ActivityTracker.getInstance().inc() + } + } } diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsComponent.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsComponent.kt index cf79733f..09c04ea5 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsComponent.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsComponent.kt @@ -17,6 +17,7 @@ class MirrordSettingsComponent { .associateWith { JBCheckBox(it.presentableName) } private val usageBannerEnabled = JBCheckBox("Show usage banner on startup") + private val enabledOnStartup = JBCheckBox("Enable mirrord on startup") private val mirrordVersionLabel = JBLabel("mirrord binary version:") private val mirrordVersion = with(JBTextField("", 10)) { @@ -41,6 +42,7 @@ class MirrordSettingsComponent { val panel: JPanel = FormBuilder .createFormBuilder() .addComponent(usageBannerEnabled) + .addComponent(enabledOnStartup) .addComponent(versionCheckEnabled) .addSeparator() .addComponent(autoUpdatePanel) @@ -64,6 +66,12 @@ class MirrordSettingsComponent { usageBannerEnabled.isSelected = value } + var enabledOnStartupStatus: Boolean + get() = enabledOnStartup.isSelected + set(value) { + enabledOnStartup.isSelected = value + } + var versionCheckEnabledStatus: Boolean get() = versionCheckEnabled.isSelected set(newStatus) { diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsConfigurable.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsConfigurable.kt index 05bcb0c3..2264d08f 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsConfigurable.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsConfigurable.kt @@ -19,7 +19,8 @@ class MirrordSettingsConfigurable : Configurable { (notificationsDisabledStatus != settings.disabledNotifications) || (usageBannerEnabledStatus != settings.showUsageBanner) || (autoUpdateEnabledStatus != settings.autoUpdate) || - (mirrordVersionStatus != settings.mirrordVersion) + (mirrordVersionStatus != settings.mirrordVersion) || + (enabledOnStartupStatus != settings.enabledByDefault) } } @@ -31,6 +32,7 @@ class MirrordSettingsConfigurable : Configurable { settings.showUsageBanner = usageBannerEnabledStatus settings.autoUpdate = autoUpdateEnabledStatus settings.mirrordVersion = mirrordVersionStatus + settings.enabledByDefault = enabledOnStartupStatus } } @@ -42,6 +44,7 @@ class MirrordSettingsConfigurable : Configurable { mirrordVersionStatus = settings.mirrordVersion notificationsDisabledStatus = settings.disabledNotifications.orEmpty() usageBannerEnabledStatus = settings.showUsageBanner + enabledOnStartupStatus = settings.enabledByDefault } } diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt index 632d59f4..ab928d6b 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt @@ -49,6 +49,7 @@ open class MirrordSettingsState : PersistentStateComponent +