Add workspace elapsed time feature (#19)
* Add workspace elapsed time feature * Clean up workspaceElapsedTime setting check
This commit is contained in:
parent
47e57f9d81
commit
e38d62da47
2 changed files with 14 additions and 5 deletions
|
@ -108,6 +108,11 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Decides if error messages are shown to the user"
|
"description": "Decides if error messages are shown to the user"
|
||||||
|
},
|
||||||
|
"discord.workspaceElapsedTime": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "Decides whether to display elapsed time for a workspace or a single file"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,9 +93,10 @@ function initRPC(clientID: string): void {
|
||||||
setActivity();
|
setActivity();
|
||||||
// Set the activity once on ready
|
// Set the activity once on ready
|
||||||
setTimeout(() => rpc.setActivity(activity), 500);
|
setTimeout(() => rpc.setActivity(activity), 500);
|
||||||
eventHandlers.add(workspace.onDidChangeTextDocument(() => setActivity()))
|
const workspaceElapsedTime = Boolean(config.get('workspaceElapsedTime'));
|
||||||
.add(workspace.onDidOpenTextDocument(() => setActivity()))
|
eventHandlers.add(workspace.onDidChangeTextDocument(() => setActivity(workspaceElapsedTime)))
|
||||||
.add(workspace.onDidCloseTextDocument(() => setActivity()))
|
.add(workspace.onDidOpenTextDocument(() => setActivity(workspaceElapsedTime)))
|
||||||
|
.add(workspace.onDidCloseTextDocument(() => setActivity(workspaceElapsedTime)))
|
||||||
.add(debug.onDidChangeActiveDebugSession(() => setActivity()))
|
.add(debug.onDidChangeActiveDebugSession(() => setActivity()))
|
||||||
.add(debug.onDidStartDebugSession(() => setActivity()))
|
.add(debug.onDidStartDebugSession(() => setActivity()))
|
||||||
.add(debug.onDidTerminateDebugSession(() => setActivity()));
|
.add(debug.onDidTerminateDebugSession(() => setActivity()));
|
||||||
|
@ -151,7 +152,7 @@ function destroyRPC(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function updates the activity (The Client's Rich Presence status).
|
// This function updates the activity (The Client's Rich Presence status).
|
||||||
function setActivity(): void {
|
function setActivity(workspaceElapsedTime: boolean = false): void {
|
||||||
// Do not continue if RPC isn't initalized.
|
// Do not continue if RPC isn't initalized.
|
||||||
if (!rpc) return;
|
if (!rpc) return;
|
||||||
if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return;
|
if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return;
|
||||||
|
@ -168,11 +169,14 @@ function setActivity(): void {
|
||||||
})]
|
})]
|
||||||
: 'vscode-big';
|
: 'vscode-big';
|
||||||
|
|
||||||
|
// Get the previous activity start timestamp (if available) to preserve workspace elapsed time
|
||||||
|
let previousTimestamp = null;
|
||||||
|
if (activity) previousTimestamp = activity['startTimestamp'];
|
||||||
// Create a JSON Object with the user's activity information.
|
// Create a JSON Object with the user's activity information.
|
||||||
activity = {
|
activity = {
|
||||||
details: generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle'),
|
details: generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle'),
|
||||||
state: generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle'),
|
state: generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle'),
|
||||||
startTimestamp: new Date().getTime() / 1000,
|
startTimestamp: !previousTimestamp && !workspaceElapsedTime ? new Date().getTime() / 1000 : previousTimestamp,
|
||||||
largeImageKey: largeImageKey
|
largeImageKey: largeImageKey
|
||||||
? largeImageKey.image
|
? largeImageKey.image
|
||||||
|| largeImageKey
|
|| largeImageKey
|
||||||
|
|
Loading…
Reference in a new issue