Skip to content

Commit 0517862

Browse files
authored
Merge pull request #10 from aliyun/feat/launch-experience-questionnaire
Launch experience satisfaction questionnaire survey
2 parents 93ea0dc + 118e0dc commit 0517862

File tree

4 files changed

+90
-29
lines changed

4 files changed

+90
-29
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
"command": "alicloud.api.removeSubscriptions",
7878
"icon": "$(notebook-delete-cell)",
7979
"title": "取消订阅"
80+
},
81+
{
82+
"command": "alicloud.api.updateCloseQuestionnaire",
83+
"title": "刷新体验问卷弹出设置"
8084
}
8185
],
8286
"keybindings": [

src/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ export class AlicloudApiCommands {
245245
new AlicloudAPIWebview().openTab(context.extensionUri, config);
246246
});
247247

248+
// 刷新问卷调查弹窗过期设置
249+
vscode.commands.registerCommand("alicloud.api.updateCloseQuestionnaire", () => {
250+
const lastPromptKey = "lastPromptTime";
251+
const globalState = context.globalState;
252+
globalState.update(lastPromptKey, undefined);
253+
console.log("update last prompt key to",globalState.get(lastPromptKey))
254+
});
255+
248256
vscode.commands.registerCommand("alicloud.api.restart", async () => {
249257
await vscode.window.withProgress(
250258
{

src/explorer.ts

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class PontAPITreeItem extends vscode.TreeItem {
2121
}
2222

2323
export class PontAPIExplorer {
24-
static getProductItems(products:Array<Product>, element:PontAPITreeItem = null){
25-
return products?.map(product=>{
24+
static getProductItems(products: Array<Product>, element: PontAPITreeItem = null) {
25+
return products?.map((product) => {
2626
return {
2727
specName: product.code,
2828
modName: "",
@@ -38,12 +38,12 @@ export class PontAPIExplorer {
3838
{
3939
specName: product.code,
4040
modName: "clickItem",
41-
label: product.name
41+
label: product.name,
4242
},
4343
],
4444
},
4545
};
46-
})
46+
});
4747
}
4848
static getDirItems(spec: PontSpec, element = null) {
4949
const dirs = element?.children || spec?.ext?.directories || [];
@@ -230,19 +230,19 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
230230
stagedDiffs: any[] = [];
231231
allDiffs: any[] = [];
232232

233-
getCNNameOfProduct(products: Array<Product>, code:string){
233+
getCNNameOfProduct(products: Array<Product>, code: string) {
234234
const findProduct = products?.find((product) => product.code === code);
235235
return `${findProduct?.name ? findProduct?.name : findProduct?.code}`;
236236
}
237237

238238
getAPIManagerChildren(element?: PontAPITreeItem): vscode.ProviderResult<PontAPITreeItem[]> {
239-
if(element.contextValue === "alicloudProducts"){
239+
if (element.contextValue === "alicloudProducts") {
240240
const productExplorer = getProductRequestInstance();
241-
const productGroups = _.groupBy(productExplorer?.products, (product) => product.group)
242-
return (Object.keys(productGroups || {}))?.map((group) => {
241+
const productGroups = _.groupBy(productExplorer?.products, (product) => product.group);
242+
return Object.keys(productGroups || {})?.map((group) => {
243243
return {
244244
specName: group,
245-
contextValue: 'productGroup',
245+
contextValue: "productGroup",
246246
label: `${group}`,
247247
modName: group,
248248
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
@@ -258,8 +258,8 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
258258
const productExplorer = getProductRequestInstance();
259259

260260
return this.pontManager.localPontSpecs.map((spec) => {
261-
const [specName, version] = spec.name.split("::")
262-
261+
const [specName, version] = spec.name.split("::");
262+
263263
return {
264264
specName: spec.name,
265265
contextValue: "Spec",
@@ -306,12 +306,11 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
306306
});
307307
} else if (element.contextValue === "Dir" && spec) {
308308
return PontAPIExplorer.getDirItems(spec, element);
309-
} else if (element.contextValue === "productGroup"){
309+
} else if (element.contextValue === "productGroup") {
310310
const productExplorer = getProductRequestInstance();
311-
const productGroups = _.groupBy(productExplorer?.products, (product) => product.group)
312-
return PontAPIExplorer.getProductItems(productGroups[element?.modName?.toString()],element)
313-
}
314-
else {
311+
const productGroups = _.groupBy(productExplorer?.products, (product) => product.group);
312+
return PontAPIExplorer.getProductItems(productGroups[element?.modName?.toString()], element);
313+
} else {
315314
return PontAPIExplorer.getDirItems(spec);
316315
}
317316
}
@@ -364,10 +363,42 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
364363
this.updatePontManager(newManager);
365364
this.updateDiffs();
366365
vscode.window.showInformationMessage("订阅成功");
366+
this.launchExperienceQuestionnaire();
367367
}
368368
}
369369
}
370370

371+
async launchExperienceQuestionnaire() {
372+
const globalState = this.context.globalState;
373+
const lastPromptKey = "lastPromptTime";
374+
const experienceQuestionnaireKey = "questionnaireExpiration";
375+
const questionnaireExpiration = globalState.get(experienceQuestionnaireKey) as any;
376+
// 检查上次提示的时间
377+
const lastPromptTime = globalState.get(lastPromptKey) as any;
378+
// 选择关闭 1天 后执行订阅相关操作会再次触发,选择去反馈或30天内不再弹出则 30 天后才会再次触发
379+
if (!lastPromptTime || Date.now() - lastPromptTime > (questionnaireExpiration || 0) * 24 * 60 * 60 * 1000) {
380+
// 显示信息弹窗
381+
let result = await vscode.window.showInformationMessage(
382+
"您在使用插件期间是否遇到问题?欢迎吐槽或点赞,您的反馈对我们十分重要!",
383+
"去反馈",
384+
"关闭",
385+
"30天内不再弹出",
386+
);
387+
if (result === "去反馈") {
388+
vscode.env.openExternal(
389+
vscode.Uri.parse("https://g.alicdn.com/aes/tracker-survey-preview/0.0.13/survey.html?pid=fePxMy&id=3486"),
390+
);
391+
globalState.update(experienceQuestionnaireKey, 30);
392+
}
393+
else if (result === "30天内不再弹出") {
394+
globalState.update(experienceQuestionnaireKey, 30);
395+
}else {
396+
globalState.update(experienceQuestionnaireKey, 1);
397+
}
398+
globalState.update(lastPromptKey, Date.now());
399+
}
400+
}
401+
371402
async removeSubscriptions(specName: string) {
372403
const pontxConfig = await findAlicloudAPIConfig(this.context);
373404
const newOrigins = pontxConfig?.origins?.filter((item) => item.name !== specName) || [];
@@ -388,6 +419,7 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
388419

389420
await this.updatePontManager(newManager);
390421
vscode.window.showInformationMessage("取消订阅成功");
422+
this.launchExperienceQuestionnaire();
391423
}
392424
}
393425

@@ -409,17 +441,17 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
409441
this.updateDiffs();
410442
}
411443
const service = alicloudAPIMessageService;
412-
vscode.commands.registerCommand("alicloud.api.addSubscription", async (element)=>{
413-
if (element.modName === 'clickItem') {
444+
vscode.commands.registerCommand("alicloud.api.addSubscription", async (element) => {
445+
if (element.modName === "clickItem") {
414446
// 取消订阅
415447
let result = await vscode.window.showInformationMessage(`是否订阅${element.label}?`, "Yes", "No");
416448
if (result === "No") {
417-
return
449+
return;
418450
}
419451
}
420-
const productExplorer = getProductRequestInstance()
452+
const productExplorer = getProductRequestInstance();
421453
const selectedProduct = productExplorer?.products?.find((item) => item?.code === element?.specName);
422-
const pickItem = AlicloudApiCommands.getPickProductItems(selectedProduct)
454+
const pickItem = AlicloudApiCommands.getPickProductItems(selectedProduct);
423455
if (pickItem.versions?.length > 1) {
424456
vscode.window
425457
.showQuickPick(pickItem.versions, {
@@ -432,11 +464,12 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
432464
} else {
433465
this.subscribeProduct(pickItem.code, (pickItem.versions[0] as any).key);
434466
}
435-
})
467+
});
436468
vscode.commands.registerCommand("alicloud.api.addSubscriptions", async () => {
437469
// 搜索+订阅功能
438-
const productExplorer = getProductRequestInstance()
439-
const items = productExplorer?.products?.map((item) => {
470+
const productExplorer = getProductRequestInstance();
471+
const items = productExplorer?.products
472+
?.map((item) => {
440473
return AlicloudApiCommands.getPickProductItems(item);
441474
})
442475
.reduce((pre, next) => pre.concat(next), []);
@@ -467,8 +500,9 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
467500

468501
vscode.commands.registerCommand("alicloud.api.searchProducts", async () => {
469502
// 搜索+订阅功能
470-
const productExplorer = getProductRequestInstance()
471-
const items = productExplorer?.products?.map((item) => {
503+
const productExplorer = getProductRequestInstance();
504+
const items = productExplorer?.products
505+
?.map((item) => {
472506
return AlicloudApiCommands.getPickProductItems(item);
473507
})
474508
.reduce((pre, next) => pre.concat(next), []);
@@ -496,7 +530,7 @@ export class AlicloudApiExplorer implements vscode.TreeDataProvider<PontChangeTr
496530
}
497531
});
498532
});
499-
533+
500534
vscode.commands.registerCommand("alicloud.api.removeSubscriptions", async (meta) => {
501535
if (meta.specName) {
502536
// 取消订阅

src/extension.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { AlicloudAPIPontParserPlugin } from "./plugins/parser";
1212

1313
import { AlicloudApiMetaGeneratePlugin } from "./plugins/generate";
1414
import { getProductRequestInstance } from "./productExplorer";
15-
import autoCompletion from './provider/autoCompletion'
15+
import autoCompletion from "./provider/autoCompletion";
1616
import autofix from "./provider/autofix";
1717

1818
export async function activate(context: vscode.ExtensionContext) {
@@ -46,6 +46,21 @@ export async function activate(context: vscode.ExtensionContext) {
4646
},
4747
};
4848

49+
const globalState = context.globalState;
50+
const lastPromptKey = "lastPromptTime";
51+
const currentVersion = vscode.extensions.getExtension("alibabacloud-openapi.vscode-alicloud-api").packageJSON.version
52+
const storedVersion = globalState.get("extensionVersion");
53+
const experienceQuestionnaireKey = "questionnaireExpiration";
54+
// 检查是否是第一次启动新版本,新版本更新后,需要重新开启问卷调查
55+
if (storedVersion !== currentVersion) {
56+
// 刷新问卷调查弹窗过期设置
57+
globalState.update(lastPromptKey, undefined);
58+
// 问卷调查弹窗弹出频率初始化为 1 天
59+
globalState.update(experienceQuestionnaireKey, 1);
60+
// 更新 globalState 中的版本号
61+
globalState.update("extensionVersion", currentVersion);
62+
}
63+
4964
try {
5065
const pontManager = await PontManager.constructorFromPontConfigAndPlugins(
5166
pontxConfig,
@@ -65,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext) {
6580
// 自动补全
6681
autoCompletion(context);
6782
// 自动修复
68-
autofix(context);
83+
autofix(context);
6984
}
7085
} catch (e) {
7186
vscode.window.showErrorMessage(e.message);

0 commit comments

Comments
 (0)