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:
parent
02bf6acfb1
commit
1a9dbc3023
2 changed files with 950 additions and 866 deletions
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,10 @@ import {
|
||||||
workspace,
|
workspace,
|
||||||
WorkspaceFolder
|
WorkspaceFolder
|
||||||
} from 'vscode';
|
} 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.
|
// Define the RPC variable and its type.
|
||||||
let rpc: Client;
|
let rpc: Client;
|
||||||
|
@ -92,12 +95,6 @@ function initRPC(clientID: string): void {
|
||||||
// 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'));
|
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.
|
// 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;
|
||||||
|
@ -110,7 +107,10 @@ function initRPC(clientID: string): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the user's activity to the `activity` variable.
|
// 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.
|
// 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;
|
lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null;
|
||||||
|
|
||||||
const fileName: string = window.activeTextEditor ? basename(window.activeTextEditor.document.fileName) : null;
|
const fileName: string = window.activeTextEditor ? basename(window.activeTextEditor.document.fileName) : null;
|
||||||
const largeImageKey = window.activeTextEditor
|
const largeImageKey: any = window.activeTextEditor
|
||||||
? languages[Object.keys(languages).find(key => {
|
? knownExtentions[Object.keys(knownExtentions).find(key => {
|
||||||
if (key.startsWith('.') && fileName.endsWith(key)) return true;
|
if (key.startsWith('.') && fileName.endsWith(key)) return true;
|
||||||
const match = key.match(/^\/(.*)\/([mgiy]+)$/);
|
const match = key.match(/^\/(.*)\/([mgiy]+)$/);
|
||||||
if (!match) return false;
|
if (!match) return false;
|
||||||
const regex = new RegExp(match[1], match[2]);
|
const regex = new RegExp(match[1], match[2]);
|
||||||
return regex.test(fileName);
|
return regex.test(fileName);
|
||||||
})]
|
})] || (knownLanguages.includes(window.activeTextEditor.document.languageId) ? window.activeTextEditor.document.languageId : null)
|
||||||
: 'vscode-big';
|
: 'vscode-big';
|
||||||
|
|
||||||
// Get the previous activity start timestamp (if available) to preserve workspace elapsed time
|
// 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,
|
startTimestamp: previousTimestamp && workspaceElapsedTime ? previousTimestamp : new Date().getTime() / 1000,
|
||||||
largeImageKey: largeImageKey
|
largeImageKey: largeImageKey
|
||||||
? largeImageKey.image
|
? largeImageKey.image
|
||||||
|| largeImageKey
|
|| largeImageKey
|
||||||
: 'txt',
|
: 'txt',
|
||||||
largeImageText: window.activeTextEditor
|
largeImageText: window.activeTextEditor
|
||||||
? config.get('largeImage')
|
? config.get('largeImage')
|
||||||
|
|
Loading…
Reference in a new issue