Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uri handler multiple windows #152

Merged
merged 12 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const activate = async (context: ExtensionContext) => {
console.log('Activating Extension...');
const rootPath = getRootPath();

registerCommands(context);
registerCommands(context, rootPath);
registerEvents(context);
registerURIHandler(context, rootPath);
registerURIHandler(context);

initializeProviders(context);
initializeTerminal(context);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { registerCommands as registerTerminalCommands } from './commands/termina
import { registerCommands as registerModuleCommands } from './commands/module';
import { registerCommands as registerServerlessFunctionCommands } from './commands/serverlessFunction';

export const registerCommands = (context: ExtensionContext) => {
export const registerCommands = (
context: ExtensionContext,
rootPath: string
) => {
registerConfigCommands(context);
registerAuthCommands(context);
registerAuthCommands(context, rootPath);
registerTerminalCommands(context);
registerModuleCommands(context);
registerServerlessFunctionCommands(context);
Expand Down
8 changes: 5 additions & 3 deletions src/lib/commands/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { commands, env, ExtensionContext, Uri } from 'vscode';
import { COMMANDS } from '../constants';

export const registerCommands = (context: ExtensionContext) => {
export const registerCommands = (
context: ExtensionContext,
rootPath: string
) => {
context.subscriptions.push(
commands.registerCommand(COMMANDS.AUTHORIZE_ACCOUNT, async () => {
const authUrl =
'https://app.hubspot.com/l/personal-access-key/auth/vscode';
const authUrl = `https://app.hubspot.com/l/personal-access-key/auth/vscode${rootPath}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't fully test the flow on Windows but since rootPath uses fsPath, this path contains the windows style path which looks like .../auth/vscodec:\folder which causes a 404

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to using path instead of fsPath and also added a fix for the value of rootPath that is returned from personal-access-key-ui, which is something like /C:/Folder. The fix slices off the leading /.

Let me know if you see any issues with this.


const callableUri = await env.asExternalUri(Uri.parse(authUrl));
await env.openExternal(callableUri);
Expand Down
13 changes: 4 additions & 9 deletions src/lib/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ const getQueryObject = (uri: Uri) => {
return new URLSearchParams(uri.query);
};

const handleAuthRequest = async (
rootPath: string,
authParams: URLSearchParams
) => {
const handleAuthRequest = async (authParams: URLSearchParams) => {
const rootPath = authParams.get('rootPath') || '';
const personalAccessKeyResp = authParams.get('personalAccessKeyResp') || '';
const env = authParams.get('env') || 'prod';
const name = authParams.get('name');
Expand Down Expand Up @@ -68,10 +66,7 @@ const handleAuthRequest = async (
return updatedConfig;
};

export const registerURIHandler = (
context: ExtensionContext,
rootPath: string
) => {
export const registerURIHandler = (context: ExtensionContext) => {
// https://github.com/microsoft/vscode-extension-samples/blob/main/uri-handler-sample/package.json
window.registerUriHandler({
handleUri(uri: Uri): ProviderResult<void> {
Expand All @@ -80,7 +75,7 @@ export const registerURIHandler = (
const queryObject = getQueryObject(uri);

console.log('queryObject: ', queryObject);
handleAuthRequest(rootPath, queryObject);
handleAuthRequest(queryObject);
}
},
});
Expand Down