From c25e5999cae6397fcda0e18c7cd4f885ab547ed9 Mon Sep 17 00:00:00 2001 From: AksLolCoding <95454315+AksLolCoding@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:41:59 -0500 Subject: [PATCH 1/3] Improve live user count Adds option to show/hide user count and improves its display --- package.json | 5 +++++ src/preferences.ts | 3 +++ src/types.ts | 3 ++- src/webview/JudgeView.ts | 4 ++++ src/webview/frontend/App.tsx | 26 +++++++++++++++++--------- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 385dad5..e16c0f0 100644 --- a/package.json +++ b/package.json @@ -360,6 +360,11 @@ "type": "string", "default": "http://20.244.105.138:4546", "description": "The address of the remote server to which the extension will send requests. (Currently used for live user count)" + }, + "cph.general.showLiveUserCount": { + "type": "boolean", + "default": true, + "description": "Whether to show the live user count or not. Turning it off may improve performance." } } } diff --git a/src/preferences.ts b/src/preferences.ts index 9010349..44e6faf 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -86,6 +86,9 @@ export const getFirstTimePref = (): boolean => export const getRemoteServerAddressPref = (): string => getPreference('general.remoteServerAddress') || ''; +export const getLiveUserCountPref = (): boolean => + getPreference('general.showLiveUserCount') || 'true'; + export const getDefaultLangPref = (): string | null => { const pref = getPreference('general.defaultLanguage'); if (pref === 'none' || pref == ' ' || !pref) { diff --git a/src/types.ts b/src/types.ts index 9162378..66a3f8f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,7 +47,8 @@ export type prefSection = | 'general.retainWebviewContext' | 'general.autoShowJudge' | 'general.defaultLanguageTemplateFileLocation' - | 'general.remoteServerAddress'; + | 'general.remoteServerAddress' + | 'general.showLiveUserCount'; export type Language = { name: LangNames; diff --git a/src/webview/JudgeView.ts b/src/webview/JudgeView.ts index f9fcdea..1c55830 100644 --- a/src/webview/JudgeView.ts +++ b/src/webview/JudgeView.ts @@ -10,6 +10,7 @@ import runTestCases from '../runTestCases'; import { getAutoShowJudgePref, getRemoteServerAddressPref, + getLiveUserCountPref, getRetainWebviewContextPref, } from '../preferences'; import { setOnlineJudgeEnv } from '../compiler'; @@ -213,6 +214,8 @@ class JudgeViewProvider implements vscode.WebviewViewProvider { const remoteServerAddress = getRemoteServerAddressPref(); + const showLiveUserCount = getLiveUserCountPref(); + const codiconsUri = webview.asWebviewUri( vscode.Uri.joinPath(this._extensionUri, 'dist', 'codicon.css'), ); @@ -261,6 +264,7 @@ class JudgeViewProvider implements vscode.WebviewViewProvider { window.remoteMessage = '${remoteMessage}'; window.generatedJsonUri = '${generatedJsonUri}'; window.remoteServerAddress = '${remoteServerAddress}'; + window.showLiveUserCount = ${showLiveUserCount}; document.addEventListener( 'DOMContentLoaded', diff --git a/src/webview/frontend/App.tsx b/src/webview/frontend/App.tsx index a147b0e..53ff2c3 100644 --- a/src/webview/frontend/App.tsx +++ b/src/webview/frontend/App.tsx @@ -40,6 +40,7 @@ interface CustomWindow extends Window { generatedJsonUri: string; remoteMessage: string | null; remoteServerAddress: string; + showLiveUserCount: boolean; console: Console; } declare const window: CustomWindow; @@ -95,10 +96,13 @@ function Judge(props: { const [extLogs, setExtLogs] = useState(''); useEffect(() => { - getLiveUserCount().then((count) => setLiveUserCount(count)); - const interval = setInterval(() => { - getLiveUserCount().then((count) => setLiveUserCount(count)); - }, 30000); + const updateLiveUserCount = (): void => { + if (window.showLiveUserCount) { + getLiveUserCount().then((count) => setLiveUserCount(count)); + } + }; + updateLiveUserCount(); + const interval = setInterval(updateLiveUserCount, 30000); return () => clearInterval(interval); }, []); @@ -554,9 +558,13 @@ function Judge(props: {

License

{generatedJson.licenseString}

-

Live user count

- {liveUserCount} user(s) online. -
+ {window.showLiveUserCount && ( + <> +

Live user count

+ {liveUserCount} {liveUserCount === 1 ? "user" : "users"} online. +
+ + )}

UI Logs

{logs}

@@ -643,10 +651,10 @@ function Judge(props: { }} /> - {liveUserCount > 0 && ( + {window.showLiveUserCount && liveUserCount > 0 && (
{' '} - {liveUserCount} users online + {liveUserCount} {liveUserCount === 1 ? "user" : "users"} online.
)} From 585606392d08604923d82d3c855bd1f01f6481c9 Mon Sep 17 00:00:00 2001 From: AksLolCoding <95454315+AksLolCoding@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:46:44 -0500 Subject: [PATCH 2/3] fix eslint issue --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 66a3f8f..5355bc4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -48,7 +48,7 @@ export type prefSection = | 'general.autoShowJudge' | 'general.defaultLanguageTemplateFileLocation' | 'general.remoteServerAddress' - | 'general.showLiveUserCount'; + | 'general.showLiveUserCount'; export type Language = { name: LangNames; From 8851cdf6f848d7ac412eb4eca8933a53c6c2be5a Mon Sep 17 00:00:00 2001 From: AksLolCoding <95454315+AksLolCoding@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:47:50 -0500 Subject: [PATCH 3/3] fix eslint 2 --- src/webview/frontend/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webview/frontend/App.tsx b/src/webview/frontend/App.tsx index 53ff2c3..3b5dbb9 100644 --- a/src/webview/frontend/App.tsx +++ b/src/webview/frontend/App.tsx @@ -561,7 +561,7 @@ function Judge(props: { {window.showLiveUserCount && ( <>

Live user count

- {liveUserCount} {liveUserCount === 1 ? "user" : "users"} online. + {liveUserCount} {liveUserCount === 1 ? 'user' : 'users'} online.
)} @@ -654,7 +654,7 @@ function Judge(props: { {window.showLiveUserCount && liveUserCount > 0 && (
{' '} - {liveUserCount} {liveUserCount === 1 ? "user" : "users"} online. + {liveUserCount} {liveUserCount === 1 ? 'user' : 'users'} online.
)}