Skip to content

Commit f7ab437

Browse files
committed
Add message inviting user to Discord every 10 usages
1 parent bcd4aed commit f7ab437

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

changelog.d/114.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Users will ocassionally be invited to join the Discord server

src/api.ts

+32
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ const FEEDBACK_COUNTER = 'mirrord-feedback-counter';
1717
*/
1818
const FEEDBACK_COUNTER_REVIEW_AFTER = 100;
1919

20+
/**
21+
* Key to access the feedback counter (see `tickDiscordCounter`) from the global user config.
22+
*/
23+
const DISCORD_COUNTER = 'mirrord-discord-counter';
24+
25+
/**
26+
* Amount of times we run mirrord before inviting the user to join the Discord server.
27+
*/
28+
const DISCORD_COUNTER_PROMPT_AFTER = 10;
29+
2030
const TARGET_TYPE_DISPLAY: Record<string, string> = {
2131
pod: 'Pod',
2232
deployment: 'Deployment',
@@ -378,6 +388,7 @@ export class MirrordAPI {
378388
async binaryExecute(target: string | null, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise<MirrordExecution> {
379389
tickMirrordForTeamsCounter();
380390
tickFeedbackCounter();
391+
tickDiscordCounter();
381392

382393
/// Create a promise that resolves when the mirrord process exits
383394
return await vscode.window.withProgress({
@@ -543,3 +554,24 @@ function tickFeedbackCounter() {
543554
.info();
544555
}
545556
}
557+
558+
/**
559+
* Updates the global Discord counter.
560+
* After each `DISCORD_COUNTER_PROMPT_AFTER` mirrord runs, displays a message asking the user to join the discord.
561+
*/
562+
function tickDiscordCounter() {
563+
const previousRuns = parseInt(globalContext.globalState.get(DISCORD_COUNTER) ?? '0');
564+
const currentRuns = previousRuns + 1;
565+
566+
globalContext.globalState.update(DISCORD_COUNTER, currentRuns);
567+
568+
if ((currentRuns % DISCORD_COUNTER_PROMPT_AFTER) === 0) {
569+
new NotificationBuilder()
570+
.withMessage(`Need any help with mirrord? Come chat with our team on Discord!`)
571+
.withGenericAction("Join us!", async () => {
572+
vscode.commands.executeCommand(MirrordStatus.joinDiscordCommandId);
573+
})
574+
.withDisableAction('promptReview')
575+
.info();
576+
}
577+
}

0 commit comments

Comments
 (0)