diff --git a/package.json b/package.json index 385dad5..f1b6687 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": false, + "description": "Whether to display the live user count. Turning it on may slightly reduce 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..5355bc4 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..c865047 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,14 @@ 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 +652,11 @@ function Judge(props: { }} /> - {liveUserCount > 0 && ( + {window.showLiveUserCount && liveUserCount > 0 && (
{' '} - {liveUserCount} users online + {liveUserCount} {liveUserCount === 1 ? 'user' : 'users'}{' '} + online.
)}