Skip to content

Commit

Permalink
Add message inviting user to Discord every 10 usages (metalbear-co#125)
Browse files Browse the repository at this point in the history
* Add message inviting user to Discord every 10 usages

* Change disable action to use unique identifier

* Change notification from every 10 uses to once
  • Loading branch information
gememma authored May 17, 2024
1 parent bcd4aed commit df49f7b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/114.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Users will be invited to join the Discord server after 10 usages
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Show a notification inviting the user to the Discord server."
},
"mirrord.promptAgentVersionMismatch": {
"type": "boolean",
Expand All @@ -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."
}
}
},
Expand Down Expand Up @@ -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"
}
],
Expand Down Expand Up @@ -246,4 +257,4 @@
"which": "^3.0.1",
"yaml": "^2.1.3"
}
}
}
32 changes: 32 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
pod: 'Pod',
deployment: 'Deployment',
Expand Down Expand Up @@ -378,6 +388,7 @@ export class MirrordAPI {
async binaryExecute(target: string | null, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise<MirrordExecution> {
tickMirrordForTeamsCounter();
tickFeedbackCounter();
tickDiscordCounter();

/// Create a promise that resolves when the mirrord process exits
return await vscode.window.withProgress({
Expand Down Expand Up @@ -543,3 +554,24 @@ function tickFeedbackCounter() {
.info();
}
}

/**
* Updates the global Discord counter.
* 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');
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('promptDiscord')
.info();
}
}

0 comments on commit df49f7b

Please sign in to comment.