fix: Desync issues with config updates (#38)

* Fix desync issues with config updates
requireing a reload

* Update the config before setting the activity
This commit is contained in:
Frangu Vlad 2018-02-04 18:13:09 +02:00 committed by Crawl
parent e83619ae37
commit 5685bfc522

View file

@ -112,7 +112,6 @@ function initRPC(clientID: string, loud?: boolean): 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);
const workspaceElapsedTime = Boolean(config.get('workspaceElapsedTime'));
// Make sure to listen to the close event and dispose and destroy everything accordingly. // Make sure to listen to the close event and dispose and destroy everything accordingly.
rpc.transport.once('close', async () => { rpc.transport.once('close', async () => {
if (!config.get('enabled')) return; if (!config.get('enabled')) return;
@ -127,7 +126,9 @@ function initRPC(clientID: string, loud?: boolean): void {
// Update the user's activity to the `activity` variable. // Update the user's activity to the `activity` variable.
activityTimer = setInterval(() => { activityTimer = setInterval(() => {
setActivity(workspaceElapsedTime); // Update the config before updating the activity
config = workspace.getConfiguration('discord');
setActivity(Boolean(config.get('workspaceElapsedTime')));
rpc.setActivity(activity); rpc.setActivity(activity);
}, 15000); }, 15000);
}); });
@ -218,6 +219,7 @@ async function destroyRPC(): Promise<void> {
function setActivity(workspaceElapsedTime: boolean = false): 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;
lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null; lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null;