-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ask user to rate the Spell Checker. (#3570)
- Loading branch information
Showing
7 changed files
with
177 additions
and
41 deletions.
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,111 @@ | ||
import { commands, Uri, window } from 'vscode'; | ||
|
||
import { getExtensionContext } from '../di.mjs'; | ||
import { openExternalUrl } from '../util/openUrl.mjs'; | ||
import { openNegativeFeedbackIssue } from './openIssue.mjs'; | ||
|
||
export async function about(): Promise<void> { | ||
const uriReadme = Uri.joinPath(getExtensionContext().extensionUri, 'resources/pages/About the Spell Checker.md'); | ||
return commands.executeCommand('markdown.showPreview', null, [uriReadme], { lock: true }); | ||
} | ||
|
||
export function supportRequest(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Support Request.md'); | ||
} | ||
|
||
export function reportIssue(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Report Issue.md'); | ||
} | ||
|
||
export function sponsor(): Promise<boolean> { | ||
return openExternalUrl('https://streetsidesoftware.com/sponsor/'); | ||
} | ||
|
||
export async function rateTheSpellChecker(): Promise<void> { | ||
const ratings = ['⭐️⭐️⭐️⭐️', '⭐️⭐️⭐️', '⭐️⭐️', '⭐️']; | ||
const choice = await window.showInformationMessage('How would you rate the Spell Checker?', ...ratings); | ||
if (!choice) { | ||
// register that it was dismissed and reschedule. | ||
return; | ||
} | ||
const idx = ratings.indexOf(choice); | ||
const rating = 4 - idx; | ||
if (rating === 1) { | ||
const result = await window.showInformationMessage( | ||
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?', | ||
'Open Issue', | ||
'Not Now', | ||
); | ||
if (result === 'Open Issue') { | ||
return openNegativeFeedbackIssue(); | ||
} | ||
return; | ||
} | ||
if (rating === 2) { | ||
await window.showInformationMessage('Thank you for your feedback.', 'Close'); | ||
return; | ||
} | ||
const resultGTD = await window.showInformationMessage( | ||
'Does the Spell Checker help you avoid spelling mistakes and get things done?', | ||
'Yes', | ||
'No', | ||
); | ||
|
||
switch (resultGTD) { | ||
case 'Yes': { | ||
const result = await window.showInformationMessage( | ||
'Thank you for your feedback. The Spell Checker needs your support to continue to improve. Would you consider sponsoring the Spell Checker?', | ||
'Open Sponsor Page', | ||
'Ask me Later', | ||
'No', | ||
); | ||
switch (result) { | ||
case 'Open Sponsor Page': | ||
await sponsor(); | ||
return; | ||
case 'Ask me Later': | ||
// register that it was dismissed and reschedule. | ||
await window.showInformationMessage('Thank you. We will ask again in about a month.', 'Close'); | ||
return; | ||
case 'No': { | ||
const result = await window.showInformationMessage('Are you already a sponsor?', 'Yes', 'No'); | ||
if (result === 'Yes') { | ||
// register response and do not ask again. | ||
await window.showInformationMessage('Thank you for your support!', 'Close'); | ||
return; | ||
} | ||
await window.showInformationMessage( | ||
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?', | ||
'Open Issue', | ||
'Not Now', | ||
); | ||
return; | ||
} | ||
} | ||
return; | ||
} | ||
case 'No': { | ||
const result = await window.showInformationMessage( | ||
'Thank you for your feedback. Would you provide more detail on how the Spell Checker can be improved by opening an issue on GitHub?', | ||
'Open Issue', | ||
'Not Now', | ||
); | ||
if (result === 'Open Issue') { | ||
return openNegativeFeedbackIssue(); | ||
} | ||
return; | ||
} | ||
} | ||
await window.showInformationMessage('Thank you for your feedback.', 'Close'); | ||
} | ||
|
||
export function releaseNotes(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Release Notes.md'); | ||
} | ||
|
||
async function openMarkdown(uri: Uri | string): Promise<void> { | ||
if (typeof uri === 'string') { | ||
uri = Uri.joinPath(getExtensionContext().extensionUri, uri); | ||
} | ||
return commands.executeCommand('markdown.showPreview', null, [uri], { lock: true }); | ||
} |
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 |
---|---|---|
@@ -1,35 +1 @@ | ||
import { commands, Uri } from 'vscode'; | ||
|
||
import { getExtensionContext } from '../di.mjs'; | ||
|
||
export async function about(): Promise<void> { | ||
const uriReadme = Uri.joinPath(getExtensionContext().extensionUri, 'resources/pages/About the Spell Checker.md'); | ||
return commands.executeCommand('markdown.showPreview', null, [uriReadme], { lock: true }); | ||
} | ||
|
||
export function supportRequest(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Support Request.md'); | ||
} | ||
|
||
export function reportIssue(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Report Issue.md'); | ||
} | ||
|
||
export function sponsor(): Promise<void> { | ||
return openMarkdown('resources/pages/Sponsor the Spell Checker.md'); | ||
} | ||
|
||
export function callForSponsors(): Promise<void> { | ||
return openMarkdown('resources/pages/Sponsor the Spell Checker.md'); | ||
} | ||
|
||
export function releaseNotes(): Promise<void> { | ||
return openMarkdown('resources/pages/Spell Checker Release Notes.md'); | ||
} | ||
|
||
async function openMarkdown(uri: Uri | string): Promise<void> { | ||
if (typeof uri === 'string') { | ||
uri = Uri.joinPath(getExtensionContext().extensionUri, uri); | ||
} | ||
return commands.executeCommand('markdown.showPreview', null, [uri], { lock: true }); | ||
} | ||
export { about, rateTheSpellChecker, releaseNotes, reportIssue, sponsor, supportRequest } from './commands.mjs'; |
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,40 @@ | ||
import { openExternalUrl } from '../util/openUrl.mjs'; | ||
|
||
const feedbackBody = `\ | ||
# Feedback | ||
Thank you for providing feedback on the Spell Checker. Your feedback is important to us. | ||
## How can the Spell Checker be improved? | ||
<!-- Please provide details on how the Spell Checker can be improved. --> | ||
## What issues are you experiencing? | ||
<!-- Please provide details on the issues you are experiencing. --> | ||
`; | ||
|
||
export async function openNegativeFeedbackIssue(): Promise<void> { | ||
await openExternalUrl(createNegativeFeedbackIssueURL()); | ||
} | ||
|
||
export function createNegativeFeedbackIssueURL(): URL { | ||
return formatGitHubIssueUrl({ title: 'Feedback', body: feedbackBody, labels: ['feedback'] }); | ||
} | ||
|
||
interface GitHubIssue { | ||
title?: string; | ||
body?: string; | ||
labels?: string[]; | ||
} | ||
|
||
export function formatGitHubIssueUrl(issue?: GitHubIssue): URL { | ||
const url = new URL('https://github.com/streetsidesoftware/vscode-spell-checker/issues/new'); | ||
|
||
const params = url.searchParams; | ||
if (issue?.title) params.set('title', issue.title); | ||
if (issue?.body) params.set('body', issue.body); | ||
if (issue?.labels) params.set('labels', issue.labels.join(',')); | ||
return url; | ||
} |
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,12 @@ | ||
import { describe, expect, test, vi } from 'vitest'; | ||
|
||
import { createNegativeFeedbackIssueURL } from './openIssue.mjs'; | ||
|
||
vi.mock('vscode'); | ||
|
||
describe('openIssue', () => { | ||
test('createNegativeFeedbackIssueUri', () => { | ||
const url = createNegativeFeedbackIssueURL(); | ||
expect(url.href).toContain('issues/new'); | ||
}); | ||
}); |
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,7 @@ | ||
import type { Uri } from 'vscode'; | ||
import { env } from 'vscode'; | ||
|
||
export async function openExternalUrl(url: string | URL): Promise<boolean> { | ||
// Hack to work around bug in VSCode see: https://github.com/microsoft/vscode/issues/85930 | ||
return env.openExternal(url.toString() as unknown as Uri); | ||
} |