Skip to content

Commit 9e2734c

Browse files
committed
hotfix: windows fix argument reading
1 parent 0a59f9b commit 9e2734c

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "assistant-cli",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "A command line tool to easily integrate OpenAI Chat GPT service",
55
"main": "./bin/cli",
66
"engines": {

src/app.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { commands, loadingSpinner, runSandbox, unnecessaryClientCommand } from './core';
2-
3-
2+
const os = require('os');
43

54
(async () => {
65
if(parseInt(process.versions.node.split(".")[0], 10) < 16) {
76
console.error('You are using a node version earlier than 16, please update it and retry');
87
return;
98
}
10-
const args = process.argv.slice(4);
9+
let argumentIndex = 4;
10+
if(os.platform() === 'win32') {
11+
argumentIndex++;
12+
}
13+
const args = process.argv.slice(argumentIndex);
1114
const noClientDef = unnecessaryClientCommand[args.join(' ')];
1215
if(noClientDef) {
1316
noClientDef();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BrowserWindow } from "electron";
2+
3+
export const conversationLoaded = async (win: BrowserWindow): Promise<boolean> => {
4+
return new Promise((resolve) => {
5+
win.webContents.on('did-finish-load', async () => {
6+
let code = `(!!document.querySelector('meta[content="ChatGPT"]') && !!document.getElementsByTagName("textarea").item(0));`;
7+
const executionResult = await win.webContents.executeJavaScript(code);
8+
if(executionResult) {
9+
win.webContents.debugger.attach('1.3');
10+
let requestId;
11+
return new Promise((resolve) => {
12+
win.webContents.debugger.on('message', async (event, method, params) => {
13+
if (method === 'Network.responseReceived') {
14+
const { response } = params;
15+
const {url} = response;
16+
if (url.indexOf("/conversations") > -1) {
17+
requestId = params.requestId;
18+
win.close();
19+
}
20+
}
21+
if(requestId === params.requestId && (method === 'Network.loadingFinished' || method === 'Network.loadingFailed')) {
22+
resolve(true);
23+
}
24+
})
25+
win.webContents.debugger.sendCommand('Network.enable');
26+
});
27+
}
28+
});
29+
})
30+
};

0 commit comments

Comments
 (0)