-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support survey popup * fix lint
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as vscode from 'vscode'; | ||
import { config } from './vscodeUtils'; | ||
|
||
export async function ShouldShowSurvey(): Promise<boolean> { | ||
let currentConfig: any = config('azapi').get('survey'); | ||
Check warning on line 5 in src/survey.ts
|
||
if ( | ||
currentConfig == undefined || | ||
currentConfig.surveyPromptDate == undefined || | ||
currentConfig.surveyPromptDate == 'none' | ||
) { | ||
currentConfig = {}; | ||
// first time, remind after 10 days | ||
const promptDate = new Date(); | ||
promptDate.setDate(promptDate.getDate() + 10); | ||
currentConfig.surveyPromptDate = promptDate.toISOString(); | ||
currentConfig.surveyPromptIgnoredCount = 0; | ||
await config('azapi').update('survey', currentConfig, vscode.ConfigurationTarget.Global); | ||
return false; | ||
} | ||
|
||
if (currentConfig.surveyPromptDate == 'never') { | ||
return false; | ||
} | ||
|
||
const currentDate = new Date(); | ||
const promptDate = new Date(currentConfig.surveyPromptDate); | ||
if (currentDate >= promptDate) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export async function ShowSurvey(): Promise<void> { | ||
const reloadMsg = | ||
'Looks like you are using Terraform AzAPI Provider. We’d love to hear from you! Could you help us improve product usability by filling out a 2-3 minute survey about your experience with it?'; | ||
const selected = await vscode.window.showInformationMessage(reloadMsg, 'Yes', 'Not Now', 'Never'); | ||
let currentConfig: any = config('azapi').get('survey'); | ||
Check warning on line 38 in src/survey.ts
|
||
if (currentConfig == undefined) { | ||
currentConfig = {}; | ||
currentConfig.surveyPromptDate = 'none'; | ||
currentConfig.surveyPromptIgnoredCount = 0; | ||
} | ||
|
||
const nextPromptDate = new Date(); | ||
|
||
switch (selected) { | ||
case 'Yes': | ||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://aka.ms/AzAPI2025')); | ||
// reset the survey prompt date and ignored count, remind after 180 days | ||
currentConfig.surveyPromptIgnoredCount = 0; | ||
nextPromptDate.setDate(nextPromptDate.getDate() + 180); | ||
currentConfig.surveyPromptDate = nextPromptDate.toISOString(); | ||
break; | ||
case 'Never': | ||
currentConfig.surveyPromptDate = 'never'; | ||
currentConfig.surveyPromptIgnoredCount = 0; | ||
break; | ||
case 'Not Now': | ||
case undefined: | ||
currentConfig.surveyPromptIgnoredCount++; | ||
if (currentConfig.surveyPromptIgnoredCount == 1) { | ||
// first time ignore, remind after 7 days | ||
nextPromptDate.setDate(nextPromptDate.getDate() + 7); | ||
currentConfig.surveyPromptDate = nextPromptDate.toISOString(); | ||
} else { | ||
// second time ignore, remind after 30 days | ||
nextPromptDate.setDate(nextPromptDate.getDate() + 30); | ||
currentConfig.surveyPromptDate = nextPromptDate.toISOString(); | ||
} | ||
break; | ||
} | ||
await config('azapi').update('survey', currentConfig, vscode.ConfigurationTarget.Global); | ||
} |