From 9898c664a13ae367bc73480aa8a32fdd33eef03d Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Tue, 24 Dec 2024 19:30:18 +0530 Subject: [PATCH] Add about cph page. --- .vscode/settings.json | 6 ++- package.json | 4 +- src/utils.ts | 3 +- src/webview/JudgeView.ts | 11 ++++ src/webview/frontend/App.tsx | 96 +++++++++++++++++++++++++++++++---- src/webview/frontend/Page.tsx | 22 ++++++++ src/webview/frontend/app.css | 29 ++++++++++- static/remote-message.txt | 2 +- webpack.config.js | 23 +++++++++ 9 files changed, 181 insertions(+), 15 deletions(-) create mode 100644 src/webview/frontend/Page.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json index a6fb976..bbb550d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "eslint.enable": true + "eslint.enable": true, + "files.associations": { + "iostream": "cpp" + }, + "editor.formatOnSave": true } \ No newline at end of file diff --git a/package.json b/package.json index 5d3da2c..27a2564 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "GPL-3.0-or-later", "icon": "icon.png", "publisher": "DivyanshuAgrawal", - "version": "2024.6.1717519178", + "version": "2077.0.0", "engines": { "vscode": "^1.52.0" }, @@ -405,4 +405,4 @@ "type": "git", "url": "https://github.com/agrawal-d/competitive-programming-helper/" } -} +} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 43ad313..9b87503 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -182,9 +182,10 @@ export const checkUnsupported = (srcPath: string): boolean => { export const deleteProblemFile = (srcPath: string) => { globalThis.reporter.sendTelemetryEvent(telmetry.DELETE_ALL_TESTCASES); const probPath = getProbSaveLocation(srcPath); + console.log('Deleting problem file', probPath); try { if (platform() === 'win32') { - spawn('del', [probPath]); + spawn('cmd.exe', ['/c', 'del', probPath]); } else { spawn('rm', [probPath]); } diff --git a/src/webview/JudgeView.ts b/src/webview/JudgeView.ts index b19e129..4f59ebd 100644 --- a/src/webview/JudgeView.ts +++ b/src/webview/JudgeView.ts @@ -200,6 +200,15 @@ class JudgeViewProvider implements vscode.WebviewViewProvider { vscode.Uri.joinPath(this._extensionUri, 'dist', 'codicon.css'), ); + const generatedJsonUri = webview.asWebviewUri( + vscode.Uri.joinPath( + this._extensionUri, + 'dist', + 'static', + 'generated.json', + ), + ); + const scriptUri = webview.asWebviewUri( vscode.Uri.joinPath( this._extensionUri, @@ -233,6 +242,8 @@ class JudgeViewProvider implements vscode.WebviewViewProvider { // So, for the initial request, ask for it again. window.vscodeApi = acquireVsCodeApi(); window.remoteMessage = '${remoteMessage}'; + window.generatedJsonUri = '${generatedJsonUri}'; + document.addEventListener( 'DOMContentLoaded', (event) => { diff --git a/src/webview/frontend/App.tsx b/src/webview/frontend/App.tsx index 6af6fa3..8515ce1 100644 --- a/src/webview/frontend/App.tsx +++ b/src/webview/frontend/App.tsx @@ -11,12 +11,20 @@ import { WebViewpersistenceState, } from '../../types'; import CaseView from './CaseView'; +import Page from './Page'; + declare const vscodeApi: { postMessage: (message: WebviewToVSEvent) => void; getState: () => WebViewpersistenceState | undefined; setState: (state: WebViewpersistenceState) => void; }; +interface CustomWindow extends Window { + generatedJsonUri: string; + remoteMessage: string | null; +} +declare const window: CustomWindow; + // Original: www.paypal.com/ncp/payment/CMLKCFEJEMX5L const payPalUrl = 'https://rb.gy/5iiorz'; @@ -37,6 +45,18 @@ function Judge(props: { const [notification, setNotification] = useState(null); const [waitingForSubmit, setWaitingForSubmit] = useState(false); const [onlineJudgeEnv, setOnlineJudgeEnv] = useState(false); + const [showInfoPage, setShowInfoPage] = useState(false); + const [generatedJson, setGeneratedJson] = useState(null); + + useEffect(() => { + fetch(window.generatedJsonUri) + .then((res) => res.json()) + .then((data) => setGeneratedJson(data)) + .catch((err) => + console.error('Failed to fetch generated JSON', err), + ); + }, []); + const [webviewState, setWebviewState] = useState( () => { const vscodeState = vscodeApi.getState(); @@ -415,10 +435,73 @@ function Judge(props: { ); }; + const renderInfoPage = () => { + if (showInfoPage === false) { + return null; + } + + if (generatedJson === null) { + return ( + setShowInfoPage(false)} + /> + ); + } + const contents = ( +
+

🤖 Enable AI compilation

+ Get 100x faster compilation using AI, please opt-in below. Your + data will be used to train cats to write JavaScript. +
+
+ +
+

Get Help

+ + User guide + +
+

Commit

+
{generatedJson.gitCommitHash}
+
+

Build Time

+ {generatedJson.dateTime} +
+

License

+
{generatedJson.licenseString}
+
+ Created by Divyanshu Agrawal +
+
+ ); + + return ( + setShowInfoPage(false)} + /> + ); + }; + return (
{notification &&
{notification}
} {renderDonateButton()} + {renderInfoPage()}

{problem.name}{' '} @@ -520,18 +603,13 @@ function Judge(props: {