Skip to content

Commit 474dd80

Browse files
author
JimmyDaddy
committed
fix: use global user settings and fix input event scroll trigger
1 parent 5ef3209 commit 474dd80

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"configuration": {
8282
"title": "vscode bard",
8383
"properties": {
84-
"vscode-bard.cookies": {
84+
"vscode-bard.cookie": {
8585
"type": "string",
8686
"default": ""
8787
}

src/bard/bard.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DEFAULT_RESPONSE_MESSAGE } from "../isomorphic/consts";
1111
const BARD_HOST = 'https://bard.google.com';
1212

1313
export default class Bard {
14-
private cookies: string;
14+
private cookie: string;
1515
private axios: AxiosInstance;
1616
public locale: string = 'en';
1717
private at: string = '';
@@ -28,8 +28,8 @@ export default class Bard {
2828

2929
private context: vscode.ExtensionContext;
3030

31-
constructor(context: vscode.ExtensionContext, cookies: string) {
32-
this.cookies = cookies;
31+
constructor(context: vscode.ExtensionContext, cookie: string) {
32+
this.cookie = cookie;
3333
this.axios = axios.create({
3434
baseURL: BARD_HOST,
3535
headers: {
@@ -83,12 +83,12 @@ export default class Bard {
8383
this.context.workspaceState.update('data', this.conversationData);
8484
}
8585

86-
public setCookies(cookies: string) {
87-
if (cookies !== this.cookies) {
86+
public setCookies(cookie: string) {
87+
if (cookie !== this.cookie) {
8888
this.at = '';
8989
this.bl = '';
9090
}
91-
this.cookies = cookies;
91+
this.cookie = cookie;
9292
}
9393

9494
/**
@@ -98,7 +98,7 @@ export default class Bard {
9898
private async getVerifyParams() {
9999
const response = await this.axios.get(BARD_HOST, {
100100
headers: {
101-
Cookie: this.cookies,
101+
Cookie: this.cookie,
102102
},
103103
});
104104
let responseData = load(response.data);
@@ -175,7 +175,7 @@ export default class Bard {
175175
}),
176176
{
177177
headers: {
178-
Cookie: this.cookies,
178+
Cookie: this.cookie,
179179
},
180180
params,
181181
}

src/bard/chat_provider.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export default class ChatProvider implements vscode.WebviewViewProvider {
1515
this.context = context;
1616
const config = vscode.workspace.getConfiguration('vscode-bard');
1717

18-
let cookies = config.get('cookies') as string;
19-
this.bot = new Bard(this.context, cookies);
18+
let cookie = config.get('cookie') as string;
19+
this.bot = new Bard(this.context, cookie);
20+
console.log(cookie, 'cookie');
2021
this.promptHistory = this.context.workspaceState.get('promptHistory') as string[] || [];
2122
}
2223
// 实现 resolveWebviewView 方法,用于处理 WebviewView 的创建和设置
@@ -33,10 +34,10 @@ export default class ChatProvider implements vscode.WebviewViewProvider {
3334

3435
this.context.subscriptions.push(
3536
vscode.workspace.onDidChangeConfiguration((event) => {
36-
if (event.affectsConfiguration('vscode-bard.cookies')) {
37+
if (event.affectsConfiguration('vscode-bard.cookie')) {
3738
const config = vscode.workspace.getConfiguration('vscode-bard');
38-
const cookies = config.get('cookies') as string;
39-
logger.info('set cookies');
39+
const cookies = config.get('cookie') as string;
40+
logger.info('set cookie');
4041
this.bot.setCookies(cookies);
4142
}
4243
})

src/bard/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export function activate(context: vscode.ExtensionContext) {
88
context.subscriptions.push(
99
vscode.commands.registerCommand("vscode-bard.setCookie", async () => {
1010
const cookie = await vscode.window.showInputBox({
11-
prompt: "Enter your Google cookies",
11+
prompt: "Enter your Google cookie",
1212
});
1313

1414
if (cookie) {
1515
// 获取配置对象
1616
const config = vscode.workspace.getConfiguration("vscode-bard");
1717
// 更新配置项
18-
config.update("cookies", cookie, vscode.ConfigurationTarget.Workspace);
18+
config.update("cookie", cookie, vscode.ConfigurationTarget.Global);
1919
}
2020
}),
2121
vscode.commands.registerCommand("vscode-bard.cleanConversation", async () => {

src/view/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ function App() {
4040

4141
useEffect(() => {
4242
list.current?.recomputeRowHeights();
43-
list.current?.scrollToRow(data.length);
43+
requestAnimationFrame(() => {
44+
list.current?.scrollToPosition(list.current?.getOffsetForRow({ alignment: 'end', index: data.length - 1 }));
45+
});
4446
}, [data]);
4547

4648
function onCLick() {

0 commit comments

Comments
 (0)