From 906c52158ee14c01d2ae20e498602363ed174f8e Mon Sep 17 00:00:00 2001 From: Gemma Tipper Date: Mon, 20 May 2024 13:48:05 +0100 Subject: [PATCH] Add message inviting user to Discord after 10 usages --- changelog.d/250.added.md | 1 + .../com/metalbear/mirrord/MirrordApi.kt | 20 +++++++++++++++++++ .../metalbear/mirrord/MirrordSettingsState.kt | 1 + 3 files changed, 22 insertions(+) create mode 100644 changelog.d/250.added.md diff --git a/changelog.d/250.added.md b/changelog.d/250.added.md new file mode 100644 index 00000000..cf1ef1c5 --- /dev/null +++ b/changelog.d/250.added.md @@ -0,0 +1 @@ +Users will be invited to join the Discord server after 10 usages \ No newline at end of file diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt index ed66656a..559262b8 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt @@ -122,6 +122,12 @@ private class SafeParser { */ private const val FEEDBACK_COUNTER_REVIEW_AFTER = 100 +/** + * How many times mirrord can be run before inviting the user to Discord. + */ +private const val DISCORD_COUNTER_INVITE_AFTER = 10 + + /** * Interact with mirrord CLI using this API. */ @@ -273,6 +279,7 @@ class MirrordApi(private val service: MirrordProjectService, private val project */ fun exec(cli: String, target: String?, configFile: String?, executable: String?, wslDistribution: WSLDistribution?): MirrordExecution { bumpFeedbackCounter() + checkDiscordCounter() val task = MirrordExtTask(cli, projectEnvVars).apply { this.target = target @@ -302,6 +309,19 @@ class MirrordApi(private val service: MirrordProjectService, private val project service.notifier.notification("Enjoying mirrord? Don't forget to leave a review or star us on GitHub!", NotificationType.INFORMATION).withLink("Review", "https://plugins.jetbrains.com/plugin/19772-mirrord/reviews").withLink("Star us on GitHub", GITHUB_URL).withDontShowAgain(MirrordSettingsState.NotificationId.PLUGIN_REVIEW).fire() } + + /** + * Invite user to MetalBear Discord server after a few usages. + */ + private fun checkDiscordCounter() { + val currentRuns = MirrordSettingsState.instance.mirrordState.runsCounter + + if ((currentRuns - DISCORD_COUNTER_INVITE_AFTER) != 0) { + return + } + + service.notifier.notification("Need any help with mirrord? Come chat with our team on Discord!", NotificationType.INFORMATION).withLink("Join us", "https://discord.gg/metalbear").withDontShowAgain(MirrordSettingsState.NotificationId.DISCORD_INVITE).fire() + } } /** 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 5433f991..c9538a2a 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordSettingsState.kt @@ -33,6 +33,7 @@ open class MirrordSettingsState : PersistentStateComponent