Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ICommandService } from '../../../../platform/commands/common/commands.j
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
import { URI } from '../../../../base/common/uri.js';
import { IProductService } from '../../../../platform/product/common/productService.js';
// import { IEnvironmentService } from '../../../../platform/environment/common/environment.js';

const auxiliaryBarRightIcon = registerIcon('auxiliarybar-right-layout-icon', Codicon.layoutSidebarRight, localize('toggleAuxiliaryIconRight', 'Icon to toggle the auxiliary bar off in its right position.'));
const auxiliaryBarRightOffIcon = registerIcon('auxiliarybar-right-off-layout-icon', Codicon.layoutSidebarRightOff, localize('toggleAuxiliaryIconRightOn', 'Icon to toggle the auxiliary bar on in its right position.'));
Expand Down Expand Up @@ -309,15 +310,59 @@ class OpenPearAIDocsAction extends Action2 {
}
}

registerAction2(OpenPearAIDocsAction);
// registerAction2(OpenPearAIDocsAction);

// MenuRegistry.appendMenuItems([
// {
// id: MenuId.CommandCenter,
// item: {
// command: {
// id: OpenPearAIDocsAction.ID,
// title: 'Docs',
// },
// order: 20000,
// },
// },
// ]);


class LoginToPearAIAction extends Action2 {
static readonly ID = 'workbench.action.loginToPearAI';
static readonly LABEL = localize2(
"loginToPearAI",
"Login To PearAI App",
);

constructor() {
super({
id: LoginToPearAIAction.ID,
title: LoginToPearAIAction.LABEL,
category: Categories.Help,
f1: true,
});
}

override async run(accessor: ServicesAccessor): Promise<void> {
const openerService = accessor.get(IOpenerService);
const callbackUri = URI.parse('pearai://pearai.pearai/auth');

await openerService.open(
URI.parse(
`https://trypear.ai/signin?callback=${callbackUri.toString()}`
)
);
}
}

registerAction2(LoginToPearAIAction);

MenuRegistry.appendMenuItems([
{
id: MenuId.CommandCenter,
item: {
command: {
id: OpenPearAIDocsAction.ID,
title: 'Docs',
id: LoginToPearAIAction.ID,
title: 'Login To PearAI',
},
order: 20000,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { URI } from 'vs/base/common/uri';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { IURLHandler, IURLService } from 'vs/platform/url/common/url';
import { ISecretStorageService } from 'vs/platform/secrets/common/secrets';
import { IDisposable } from 'vs/base/common/lifecycle';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';

const PEAR_AUTH_STORAGE_KEY = 'pearai.auth';

export class PearAuthenticationUriHandler implements IWorkbenchContribution, IURLHandler {
private urlHandler: IDisposable;

constructor(
@IURLService urlService: IURLService,
@IStorageService private readonly storageService: IStorageService,
@ISecretStorageService private readonly secretStorageService: ISecretStorageService,
@INotificationService private readonly notificationService: INotificationService
) {
this.urlHandler = urlService.registerHandler(this);
}

async handleURL(uri: URI): Promise<boolean> {
if (uri.authority === 'pearai.pearai') {
if (uri.path === '/ping') {
this.notificationService.info('PearAI received a custom URI!');
return true;
} else if (uri.path === '/auth') {
const queryParams = new URLSearchParams(uri.query);
const data = {
accessToken: queryParams.get('accessToken'),
refreshToken: queryParams.get('refreshToken'),
};
if (data.accessToken && data.refreshToken) {
// Store tokens in secret storage
await this.secretStorageService.set('pearai.accessToken', data.accessToken);
await this.secretStorageService.set('pearai.refreshToken', data.refreshToken);

// Store auth state in storage service
this.storageService.store(
PEAR_AUTH_STORAGE_KEY,
{ isAuthenticated: true },
StorageScope.APPLICATION,
StorageTarget.MACHINE
);

this.notificationService.info('Successfully logged in to PearAI');
}
return true;
}
}
return false;
}

dispose(): void {
this.urlHandler.dispose();
}
}

// TODO: I think file isnt beeing registered, idk why

console.dir("I AM A REGISTERED OFFENDER")
// Register the URI handler as a workbench contribution
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(PearAuthenticationUriHandler, LifecyclePhase.Restored);
Loading