Fixed language and Dropped updates (#23)

* Fixed language and updating problems

* Fixed language and Dropped updates

* renovation

* also, once again forgot to remove the debugging
This commit is contained in:
Zachary Kohnen 2018-01-03 13:11:21 -05:00 committed by Crawl
parent 02bf6acfb1
commit 1a9dbc3023
2 changed files with 950 additions and 866 deletions

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,10 @@ import {
workspace,
WorkspaceFolder
} from 'vscode';
const languages = require('./data/languages.json');
const lang = require('./data/languages.json');
const knownExtentions: { [x: string]: {image: string}} = lang.knownExtentions;
const knownLanguages: string[] = lang.knownLanguages;
// Define the RPC variable and its type.
let rpc: Client;
@ -92,12 +95,6 @@ function initRPC(clientID: string): void {
// Set the activity once on ready
setTimeout(() => rpc.setActivity(activity), 500);
const workspaceElapsedTime = Boolean(config.get('workspaceElapsedTime'));
eventHandlers.add(workspace.onDidChangeTextDocument(() => setActivity(workspaceElapsedTime)))
.add(workspace.onDidOpenTextDocument(() => setActivity(workspaceElapsedTime)))
.add(workspace.onDidCloseTextDocument(() => setActivity(workspaceElapsedTime)))
.add(debug.onDidChangeActiveDebugSession(() => setActivity()))
.add(debug.onDidStartDebugSession(() => setActivity()))
.add(debug.onDidTerminateDebugSession(() => setActivity()));
// Make sure to listen to the close event and dispose and destroy everything accordingly.
rpc.transport.once('close', async () => {
if (!config.get('enabled')) return;
@ -110,7 +107,10 @@ function initRPC(clientID: string): void {
});
// Update the user's activity to the `activity` variable.
activityTimer = setInterval(() => rpc.setActivity(activity), 15000);
activityTimer = setInterval(() => {
setActivity(workspaceElapsedTime);
rpc.setActivity(activity);
}, 15000);
});
// Log in to the RPC Client, and check whether or not it errors.
@ -157,14 +157,14 @@ function setActivity(workspaceElapsedTime: boolean = false): void {
lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null;
const fileName: string = window.activeTextEditor ? basename(window.activeTextEditor.document.fileName) : null;
const largeImageKey = window.activeTextEditor
? languages[Object.keys(languages).find(key => {
const largeImageKey: any = window.activeTextEditor
? knownExtentions[Object.keys(knownExtentions).find(key => {
if (key.startsWith('.') && fileName.endsWith(key)) return true;
const match = key.match(/^\/(.*)\/([mgiy]+)$/);
if (!match) return false;
const regex = new RegExp(match[1], match[2]);
return regex.test(fileName);
})]
})] || (knownLanguages.includes(window.activeTextEditor.document.languageId) ? window.activeTextEditor.document.languageId : null)
: 'vscode-big';
// Get the previous activity start timestamp (if available) to preserve workspace elapsed time
@ -177,7 +177,7 @@ function setActivity(workspaceElapsedTime: boolean = false): void {
startTimestamp: previousTimestamp && workspaceElapsedTime ? previousTimestamp : new Date().getTime() / 1000,
largeImageKey: largeImageKey
? largeImageKey.image
|| largeImageKey
|| largeImageKey
: 'txt',
largeImageText: window.activeTextEditor
? config.get('largeImage')