Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve live user count #520

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export type prefSection =
| 'general.retainWebviewContext'
| 'general.autoShowJudge'
| 'general.defaultLanguageTemplateFileLocation'
| 'general.remoteServerAddress';
| 'general.remoteServerAddress'
| 'general.showLiveUserCount';

export type Language = {
name: LangNames;
Expand Down
4 changes: 4 additions & 0 deletions src/webview/JudgeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import runTestCases from '../runTestCases';
import {
getAutoShowJudgePref,
getRemoteServerAddressPref,
getLiveUserCountPref,
getRetainWebviewContextPref,
} from '../preferences';
import { setOnlineJudgeEnv } from '../compiler';
Expand Down Expand Up @@ -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'),
);
Expand Down Expand Up @@ -261,6 +264,7 @@ class JudgeViewProvider implements vscode.WebviewViewProvider {
window.remoteMessage = '${remoteMessage}';
window.generatedJsonUri = '${generatedJsonUri}';
window.remoteServerAddress = '${remoteServerAddress}';
window.showLiveUserCount = ${showLiveUserCount};

document.addEventListener(
'DOMContentLoaded',
Expand Down
26 changes: 17 additions & 9 deletions src/webview/frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
generatedJsonUri: string;
remoteMessage: string | null;
remoteServerAddress: string;
showLiveUserCount: boolean;
console: Console;
}
declare const window: CustomWindow;
Expand Down Expand Up @@ -95,10 +96,13 @@
const [extLogs, setExtLogs] = useState<string>('');

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);
}, []);

Expand Down Expand Up @@ -554,9 +558,13 @@
<h3>License</h3>
<pre className="selectable">{generatedJson.licenseString}</pre>
<hr />
<h3>Live user count</h3>
{liveUserCount} user(s) online.
<hr />
{window.showLiveUserCount && (
<>
<h3>Live user count</h3>
{liveUserCount} {liveUserCount === 1 ? 'user' : 'users'} online.

Check failure on line 564 in src/webview/frontend/App.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `{'·'}⏎·······················`
<hr />
</>
)}
<h3>UI Logs</h3>
<pre className="selectable">{logs}</pre>
<hr />
Expand Down Expand Up @@ -643,10 +651,10 @@
}}
/>
</div>
{liveUserCount > 0 && (
{window.showLiveUserCount && liveUserCount > 0 && (
<div className="liveUserCount">
<i className="codicon codicon-circle-filled color-green"></i>{' '}
{liveUserCount} users online
{liveUserCount} {liveUserCount === 1 ? 'user' : 'users'} online.

Check failure on line 657 in src/webview/frontend/App.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `{'·'}⏎·······················`
</div>
)}
</div>
Expand Down
Loading