fix free trial reminder popup buttons

This commit is contained in:
Nate 2024-08-29 14:51:01 -07:00
parent 48f4940dd4
commit 69baac9993
4 changed files with 40 additions and 19 deletions

View file

@ -8,6 +8,8 @@ import { ConfigHandler } from "core/config/ConfigHandler";
import { v4 as uuidv4 } from "uuid";
import * as vscode from "vscode";
import type { TabAutocompleteModel } from "../util/loadAutocompleteModel";
import { showFreeTrialLoginMessage } from "../util/messages";
import { VsCodeWebviewProtocol } from "../webviewProtocol";
import { getDefinitionsFromLsp } from "./lsp";
import { RecentlyEditedTracker } from "./recentlyEdited";
import {
@ -31,6 +33,15 @@ export class ContinueCompletionProvider
if (e.message.includes("https://ollama.ai")) {
options.push("Download Ollama");
}
if (e.message.includes("Please sign in with GitHub")) {
showFreeTrialLoginMessage(
e.message,
this.configHandler.reloadConfig.bind(this.configHandler),
() => this.webviewProtocol.request("openOnboarding", undefined),
);
return;
}
vscode.window.showErrorMessage(e.message, ...options).then((val) => {
if (val === "Documentation") {
vscode.env.openExternal(
@ -51,6 +62,7 @@ export class ContinueCompletionProvider
private readonly configHandler: ConfigHandler,
private readonly ide: IDE,
private readonly tabAutocompleteModel: TabAutocompleteModel,
private readonly webviewProtocol: VsCodeWebviewProtocol,
) {
this.completionProvider = new CompletionProvider(
this.configHandler,

View file

@ -177,6 +177,7 @@ export class VsCodeExtension {
this.configHandler,
this.ide,
this.tabAutocompleteModel,
this.sidebar.webviewProtocol,
),
),
);

View file

@ -0,0 +1,23 @@
import * as vscode from "vscode";
export function showFreeTrialLoginMessage(
message: string,
reloadConfig: () => void,
openOnboarding: () => void,
) {
vscode.window
.showInformationMessage(message, "Sign In", "Use API key / local model")
.then((selection) => {
if (selection === "Sign In") {
vscode.authentication
.getSession("github", [], {
createIfNone: true,
})
.then(() => {
reloadConfig();
});
} else if (selection === "Use API key / local model") {
openOnboarding();
}
});
}

View file

@ -8,6 +8,7 @@ import path from "path";
import { v4 as uuidv4 } from "uuid";
import * as vscode from "vscode";
import { IMessenger } from "../../../core/util/messenger";
import { showFreeTrialLoginMessage } from "./util/messages";
import { getExtensionUri } from "./util/vscode";
export async function showTutorial() {
@ -140,25 +141,9 @@ export class VsCodeWebviewProtocol
}
});
} else if (message.includes("Please sign in with GitHub")) {
vscode.window
.showInformationMessage(
message,
"Sign In",
"Use API key / local model",
)
.then((selection) => {
if (selection === "Sign In") {
vscode.authentication
.getSession("github", [], {
createIfNone: true,
})
.then(() => {
this.reloadConfig();
});
} else if (selection === "Use API key / local model") {
this.request("openOnboarding", undefined);
}
});
showFreeTrialLoginMessage(message, this.reloadConfig, () =>
this.request("openOnboarding", undefined),
);
} else {
Telemetry.capture(
"webview_protocol_error",