Skip to content

Commit c25e599

Browse files
authored
Improve live user count
Adds option to show/hide user count and improves its display
1 parent db6d83a commit c25e599

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@
360360
"type": "string",
361361
"default": "http://20.244.105.138:4546",
362362
"description": "The address of the remote server to which the extension will send requests. (Currently used for live user count)"
363+
},
364+
"cph.general.showLiveUserCount": {
365+
"type": "boolean",
366+
"default": true,
367+
"description": "Whether to show the live user count or not. Turning it off may improve performance."
363368
}
364369
}
365370
}

src/preferences.ts

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export const getFirstTimePref = (): boolean =>
8686
export const getRemoteServerAddressPref = (): string =>
8787
getPreference('general.remoteServerAddress') || '';
8888

89+
export const getLiveUserCountPref = (): boolean =>
90+
getPreference('general.showLiveUserCount') || 'true';
91+
8992
export const getDefaultLangPref = (): string | null => {
9093
const pref = getPreference('general.defaultLanguage');
9194
if (pref === 'none' || pref == ' ' || !pref) {

src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export type prefSection =
4747
| 'general.retainWebviewContext'
4848
| 'general.autoShowJudge'
4949
| 'general.defaultLanguageTemplateFileLocation'
50-
| 'general.remoteServerAddress';
50+
| 'general.remoteServerAddress'
51+
| 'general.showLiveUserCount';
5152

5253
export type Language = {
5354
name: LangNames;

src/webview/JudgeView.ts

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import runTestCases from '../runTestCases';
1010
import {
1111
getAutoShowJudgePref,
1212
getRemoteServerAddressPref,
13+
getLiveUserCountPref,
1314
getRetainWebviewContextPref,
1415
} from '../preferences';
1516
import { setOnlineJudgeEnv } from '../compiler';
@@ -213,6 +214,8 @@ class JudgeViewProvider implements vscode.WebviewViewProvider {
213214

214215
const remoteServerAddress = getRemoteServerAddressPref();
215216

217+
const showLiveUserCount = getLiveUserCountPref();
218+
216219
const codiconsUri = webview.asWebviewUri(
217220
vscode.Uri.joinPath(this._extensionUri, 'dist', 'codicon.css'),
218221
);
@@ -261,6 +264,7 @@ class JudgeViewProvider implements vscode.WebviewViewProvider {
261264
window.remoteMessage = '${remoteMessage}';
262265
window.generatedJsonUri = '${generatedJsonUri}';
263266
window.remoteServerAddress = '${remoteServerAddress}';
267+
window.showLiveUserCount = ${showLiveUserCount};
264268
265269
document.addEventListener(
266270
'DOMContentLoaded',

src/webview/frontend/App.tsx

+17-9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface CustomWindow extends Window {
4040
generatedJsonUri: string;
4141
remoteMessage: string | null;
4242
remoteServerAddress: string;
43+
showLiveUserCount: boolean;
4344
console: Console;
4445
}
4546
declare const window: CustomWindow;
@@ -95,10 +96,13 @@ function Judge(props: {
9596
const [extLogs, setExtLogs] = useState<string>('');
9697

9798
useEffect(() => {
98-
getLiveUserCount().then((count) => setLiveUserCount(count));
99-
const interval = setInterval(() => {
100-
getLiveUserCount().then((count) => setLiveUserCount(count));
101-
}, 30000);
99+
const updateLiveUserCount = (): void => {
100+
if (window.showLiveUserCount) {
101+
getLiveUserCount().then((count) => setLiveUserCount(count));
102+
}
103+
};
104+
updateLiveUserCount();
105+
const interval = setInterval(updateLiveUserCount, 30000);
102106
return () => clearInterval(interval);
103107
}, []);
104108

@@ -554,9 +558,13 @@ function Judge(props: {
554558
<h3>License</h3>
555559
<pre className="selectable">{generatedJson.licenseString}</pre>
556560
<hr />
557-
<h3>Live user count</h3>
558-
{liveUserCount} user(s) online.
559-
<hr />
561+
{window.showLiveUserCount && (
562+
<>
563+
<h3>Live user count</h3>
564+
{liveUserCount} {liveUserCount === 1 ? "user" : "users"} online.
565+
<hr />
566+
</>
567+
)}
560568
<h3>UI Logs</h3>
561569
<pre className="selectable">{logs}</pre>
562570
<hr />
@@ -643,10 +651,10 @@ function Judge(props: {
643651
}}
644652
/>
645653
</div>
646-
{liveUserCount > 0 && (
654+
{window.showLiveUserCount && liveUserCount > 0 && (
647655
<div className="liveUserCount">
648656
<i className="codicon codicon-circle-filled color-green"></i>{' '}
649-
{liveUserCount} users online
657+
{liveUserCount} {liveUserCount === 1 ? "user" : "users"} online.
650658
</div>
651659
)}
652660
</div>

0 commit comments

Comments
 (0)