Skip to content

Commit e8263c9

Browse files
authored
fix webview command to execute (#557)
Signed-off-by: Yan Zhang <[email protected]>
1 parent 6d9abe6 commit e8263c9

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export function initialize(context: vscode.ExtensionContext) {
2626
context.subscriptions.push(vscode.commands.registerCommand("java.gettingStarted", instrumentCommand(context, "java.gettingStarted", javaGettingStartedCmdHandler)));
2727
context.subscriptions.push(vscode.commands.registerCommand("java.extGuide", instrumentCommand(context, "java.extGuide", javaExtGuideCmdHandler)));
2828
context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.webview.runCommand", webviewCmdLinkHandler));
29-
context.subscriptions.push(vscode.commands.registerCommand("java.welcome", (args) => showWelcomeWebview(context, args)));
29+
context.subscriptions.push(vscode.commands.registerCommand("java.welcome", (options) => showWelcomeWebview(context, options)));
3030
}

src/utils/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ export async function webviewCmdLinkHandler(obj: { webview: string, identifier:
5858
webview,
5959
identifier
6060
});
61-
await vscode.commands.executeCommand(command, args);
61+
62+
if (args !== undefined) {
63+
await vscode.commands.executeCommand(command, ...args);
64+
} else {
65+
await vscode.commands.executeCommand(command);
66+
}
6267
}

src/welcome/assets/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ export function encodeCommandUri(command: string, args?: string[]) {
99
return ret;
1010
}
1111

12+
/**
13+
* URL for webview commands.
14+
* By executing the retured command, telemetry is sent before finally executing {command} {args}.
15+
*
16+
* @param identifier will be record in telemetry
17+
* @param command command to execute
18+
* @param args must be an array, if provided
19+
* @returns
20+
*/
1221
export function encodeCommandUriWithTelemetry(identifier: string, command: string, args?: any[]) {
1322
const helperCommand = "java.webview.runCommand";
1423
const wrappedArgs = {

src/welcome/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const KEY_SHOW_WHEN_USING_JAVA = "showWhenUsingJava";
1010
const KEY_IS_WELCOME_PAGE_VIEWED = "isWelcomePageViewed";
1111
let welcomeView: vscode.WebviewPanel | undefined;
1212

13-
export async function showWelcomeWebview(context: vscode.ExtensionContext, args?: any[]) {
13+
export async function showWelcomeWebview(context: vscode.ExtensionContext, options?: any) {
1414
if (welcomeView) {
15-
const firstTimeRun = args?.[0]?.firstTimeRun;
15+
const firstTimeRun = options?.firstTimeRun;
1616
if (firstTimeRun === undefined) {
1717
welcomeView.reveal();
1818
} else {
@@ -37,7 +37,7 @@ export async function showWelcomeWebview(context: vscode.ExtensionContext, args?
3737
retainContextWhenHidden: true
3838
}
3939
);
40-
let firstTimeRun = args?.[0]?.firstTimeRun || context.globalState.get(KEY_IS_WELCOME_PAGE_VIEWED) !== true;
40+
let firstTimeRun = options?.firstTimeRun || context.globalState.get(KEY_IS_WELCOME_PAGE_VIEWED) !== true;
4141
await initializeWelcomeView(context, welcomeView, firstTimeRun, onDidDisposeWebviewPanel);
4242
}
4343

0 commit comments

Comments
 (0)