From f7ab437fd4e5f2d2f8bb52489030061fc5fc7fc9 Mon Sep 17 00:00:00 2001 From: Gemma Tipper Date: Thu, 16 May 2024 18:19:26 +0100 Subject: [PATCH 1/3] Add message inviting user to Discord every 10 usages --- changelog.d/114.added.md | 1 + src/api.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 changelog.d/114.added.md diff --git a/changelog.d/114.added.md b/changelog.d/114.added.md new file mode 100644 index 00000000..349507fc --- /dev/null +++ b/changelog.d/114.added.md @@ -0,0 +1 @@ +Users will ocassionally be invited to join the Discord server \ No newline at end of file diff --git a/src/api.ts b/src/api.ts index e76a81ec..e70f6312 100644 --- a/src/api.ts +++ b/src/api.ts @@ -17,6 +17,16 @@ const FEEDBACK_COUNTER = 'mirrord-feedback-counter'; */ const FEEDBACK_COUNTER_REVIEW_AFTER = 100; +/** +* Key to access the feedback counter (see `tickDiscordCounter`) from the global user config. +*/ +const DISCORD_COUNTER = 'mirrord-discord-counter'; + +/** +* Amount of times we run mirrord before inviting the user to join the Discord server. +*/ +const DISCORD_COUNTER_PROMPT_AFTER = 10; + const TARGET_TYPE_DISPLAY: Record = { pod: 'Pod', deployment: 'Deployment', @@ -378,6 +388,7 @@ export class MirrordAPI { async binaryExecute(target: string | null, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise { tickMirrordForTeamsCounter(); tickFeedbackCounter(); + tickDiscordCounter(); /// Create a promise that resolves when the mirrord process exits return await vscode.window.withProgress({ @@ -543,3 +554,24 @@ function tickFeedbackCounter() { .info(); } } + +/** +* Updates the global Discord counter. +* After each `DISCORD_COUNTER_PROMPT_AFTER` mirrord runs, displays a message asking the user to join the discord. +*/ +function tickDiscordCounter() { + const previousRuns = parseInt(globalContext.globalState.get(DISCORD_COUNTER) ?? '0'); + const currentRuns = previousRuns + 1; + + globalContext.globalState.update(DISCORD_COUNTER, currentRuns); + + if ((currentRuns % DISCORD_COUNTER_PROMPT_AFTER) === 0) { + new NotificationBuilder() + .withMessage(`Need any help with mirrord? Come chat with our team on Discord!`) + .withGenericAction("Join us!", async () => { + vscode.commands.executeCommand(MirrordStatus.joinDiscordCommandId); + }) + .withDisableAction('promptReview') + .info(); + } +} \ No newline at end of file From e6e246d8b4825b8d5026fcf11de2172e12a5310e Mon Sep 17 00:00:00 2001 From: Gemma Tipper Date: Fri, 17 May 2024 10:59:58 +0100 Subject: [PATCH 2/3] Change disable action to use unique identifier --- package.json | 21 ++++++++++++++++----- src/api.ts | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 864e4d5e..4afe9f6b 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,12 @@ "mirrord.promptReview": { "type": "boolean", "default": true, - "description": "Occasionally show a notification asking for plugin review" + "description": "Occasionally show a notification asking for plugin review." + }, + "mirrord.promptDiscord": { + "type": "boolean", + "default": true, + "description": "Occasionally show a notification inviting to the Discord server." }, "mirrord.promptAgentVersionMismatch": { "type": "boolean", @@ -131,9 +136,12 @@ "description": "Path to local mirrord installation." }, "mirrord.autoUpdate": { - "type": ["string", "boolean"], + "type": [ + "string", + "boolean" + ], "default": true, - "description": "Automatically update mirrord binary." + "description": "Automatically update mirrord binary." } } }, @@ -163,7 +171,10 @@ }, "jsonValidation": [ { - "fileMatch": ["*mirrord.json", "*.mirrord/*.json"], + "fileMatch": [ + "*mirrord.json", + "*.mirrord/*.json" + ], "url": "https://raw.githubusercontent.com/metalbear-co/mirrord/latest/mirrord-schema.json" } ], @@ -246,4 +257,4 @@ "which": "^3.0.1", "yaml": "^2.1.3" } -} +} \ No newline at end of file diff --git a/src/api.ts b/src/api.ts index e70f6312..e1db6745 100644 --- a/src/api.ts +++ b/src/api.ts @@ -571,7 +571,7 @@ function tickDiscordCounter() { .withGenericAction("Join us!", async () => { vscode.commands.executeCommand(MirrordStatus.joinDiscordCommandId); }) - .withDisableAction('promptReview') + .withDisableAction('promptDiscord') .info(); } } \ No newline at end of file From 08dd5ebb769bbc9e45145283dff6978dde9cb397 Mon Sep 17 00:00:00 2001 From: Gemma Tipper Date: Fri, 17 May 2024 11:44:06 +0100 Subject: [PATCH 3/3] Change notification from every 10 uses to once --- changelog.d/114.added.md | 2 +- package.json | 2 +- src/api.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.d/114.added.md b/changelog.d/114.added.md index 349507fc..cf1ef1c5 100644 --- a/changelog.d/114.added.md +++ b/changelog.d/114.added.md @@ -1 +1 @@ -Users will ocassionally be invited to join the Discord server \ No newline at end of file +Users will be invited to join the Discord server after 10 usages \ No newline at end of file diff --git a/package.json b/package.json index 4afe9f6b..c59cda5f 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "mirrord.promptDiscord": { "type": "boolean", "default": true, - "description": "Occasionally show a notification inviting to the Discord server." + "description": "Show a notification inviting the user to the Discord server." }, "mirrord.promptAgentVersionMismatch": { "type": "boolean", diff --git a/src/api.ts b/src/api.ts index e1db6745..c8d1be8b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -557,7 +557,7 @@ function tickFeedbackCounter() { /** * Updates the global Discord counter. -* After each `DISCORD_COUNTER_PROMPT_AFTER` mirrord runs, displays a message asking the user to join the discord. +* After `DISCORD_COUNTER_PROMPT_AFTER` mirrord runs, displays a message asking the user to join the discord. */ function tickDiscordCounter() { const previousRuns = parseInt(globalContext.globalState.get(DISCORD_COUNTER) ?? '0'); @@ -565,7 +565,7 @@ function tickDiscordCounter() { globalContext.globalState.update(DISCORD_COUNTER, currentRuns); - if ((currentRuns % DISCORD_COUNTER_PROMPT_AFTER) === 0) { + if ((currentRuns - DISCORD_COUNTER_PROMPT_AFTER) === 0) { new NotificationBuilder() .withMessage(`Need any help with mirrord? Come chat with our team on Discord!`) .withGenericAction("Join us!", async () => {