refactor: use workspace.fs api
This commit is contained in:
parent
82dfef636b
commit
531fbaf66d
4 changed files with 43 additions and 39 deletions
|
@ -190,7 +190,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.7.1",
|
||||
"@types/vscode": "^1.36.0",
|
||||
"@types/vscode": "^1.37.0",
|
||||
"@typescript-eslint/eslint-plugin": "^1.13.0",
|
||||
"@typescript-eslint/parser": "^1.13.0",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
|
@ -203,7 +203,7 @@
|
|||
"webpack-cli": "^3.3.6"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.31.0"
|
||||
"vscode": "^1.37.0"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "marine/node"
|
||||
|
|
|
@ -33,9 +33,9 @@ export default class RPCClient implements Disposable {
|
|||
return this._rpc;
|
||||
}
|
||||
|
||||
public setActivity(workspaceElapsedTime: boolean = false): void {
|
||||
public async setActivity(workspaceElapsedTime: boolean = false): Promise<void> {
|
||||
if (!this._rpc) return;
|
||||
const activity = this._activity.generate(workspaceElapsedTime);
|
||||
const activity = await this._activity.generate(workspaceElapsedTime);
|
||||
Logger.log('Sending activity to Discord.');
|
||||
this._rpc.setActivity(activity);
|
||||
}
|
||||
|
@ -79,11 +79,11 @@ export default class RPCClient implements Disposable {
|
|||
setTimeout(() => this.statusBarIcon.text = '$(globe)', 5000);
|
||||
|
||||
if (activityTimer) clearInterval(activityTimer);
|
||||
this.setActivity();
|
||||
await this.setActivity();
|
||||
|
||||
activityTimer = setInterval(() => {
|
||||
activityTimer = setInterval(async () => {
|
||||
this.config = workspace.getConfiguration('discord');
|
||||
this.setActivity(this.config.get<boolean>('workspaceElapsedTime'));
|
||||
await this.setActivity(this.config.get<boolean>('workspaceElapsedTime'));
|
||||
}, 10000);
|
||||
|
||||
this._rpc.subscribe('ACTIVITY_SPECTATE', async ({ secret }: { secret: string }) => {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { statSync } from 'fs';
|
||||
import { basename, parse, sep } from 'path';
|
||||
import {
|
||||
debug,
|
||||
|
@ -50,16 +49,16 @@ export default class Activity implements Disposable {
|
|||
return this._state;
|
||||
}
|
||||
|
||||
public generate(workspaceElapsedTime: boolean = false): State | null {
|
||||
public async generate(workspaceElapsedTime: boolean = false): Promise<State | null> {
|
||||
let largeImageKey: any = 'vscode-big';
|
||||
if (window.activeTextEditor) {
|
||||
if (window.activeTextEditor.document.languageId === 'Log') return this._state;
|
||||
if (window.activeTextEditor.document.fileName === this._lastKnownFile) {
|
||||
return this._state = {
|
||||
...this._state,
|
||||
details: this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', this._state!.largeImageKey),
|
||||
details: await this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', this._state!.largeImageKey),
|
||||
smallImageKey: debug.activeDebugSession ? 'debug' : env.appName.includes('Insiders') ? 'vscode-insiders' : 'vscode',
|
||||
state: this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', this._state!.largeImageKey)
|
||||
state: await this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', this._state!.largeImageKey)
|
||||
};
|
||||
}
|
||||
this._lastKnownFile = window.activeTextEditor.document.fileName;
|
||||
|
@ -78,9 +77,9 @@ export default class Activity implements Disposable {
|
|||
|
||||
this._state = {
|
||||
...this._state,
|
||||
details: this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', largeImageKey),
|
||||
details: await this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', largeImageKey),
|
||||
startTimestamp: window.activeTextEditor && previousTimestamp && workspaceElapsedTime ? previousTimestamp : window.activeTextEditor ? new Date().getTime() : null,
|
||||
state: this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', largeImageKey),
|
||||
state: await this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', largeImageKey),
|
||||
largeImageKey: largeImageKey ? largeImageKey.image || largeImageKey : 'txt',
|
||||
largeImageText: window.activeTextEditor
|
||||
? this._config.get<string>('largeImage')!
|
||||
|
@ -202,7 +201,7 @@ export default class Activity implements Disposable {
|
|||
this._lastKnownFile = '';
|
||||
}
|
||||
|
||||
private _generateDetails(debugging: string, editing: string, idling: string, largeImageKey: any): string {
|
||||
private async _generateDetails(debugging: string, editing: string, idling: string, largeImageKey: any): Promise<string> {
|
||||
let raw: string = this._config.get<string>(idling)!.replace('{null}', empty);
|
||||
let filename = null;
|
||||
let dirname = null;
|
||||
|
@ -233,7 +232,7 @@ export default class Activity implements Disposable {
|
|||
raw = this._config.get<string>(editing)!;
|
||||
}
|
||||
|
||||
const { totalLines, size, currentLine, currentColumn } = this._generateFileDetails(raw);
|
||||
const { totalLines, size, currentLine, currentColumn } = await this._generateFileDetails(raw);
|
||||
raw = raw!
|
||||
.replace('{null}', empty)
|
||||
.replace('{filename}', filename)
|
||||
|
@ -252,7 +251,7 @@ export default class Activity implements Disposable {
|
|||
return raw;
|
||||
}
|
||||
|
||||
private _generateFileDetails(str?: string): FileDetail {
|
||||
private async _generateFileDetails(str?: string): Promise<FileDetail> {
|
||||
const fileDetail: FileDetail = {};
|
||||
if (!str) return fileDetail;
|
||||
|
||||
|
@ -271,7 +270,7 @@ export default class Activity implements Disposable {
|
|||
|
||||
if (str.includes('{filesize}')) {
|
||||
let currentDivision = 0;
|
||||
let { size } = statSync(window.activeTextEditor.document.fileName);
|
||||
let { size } = await workspace.fs.stat(window.activeTextEditor.document.uri);
|
||||
const originalSize = size;
|
||||
if (originalSize > 1000) {
|
||||
size /= 1000;
|
||||
|
|
49
yarn.lock
49
yarn.lock
|
@ -69,10 +69,10 @@
|
|||
dependencies:
|
||||
source-map "^0.6.1"
|
||||
|
||||
"@types/vscode@^1.36.0":
|
||||
version "1.36.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.36.0.tgz#ae60242e893d9eda9a0d96d51ef56f1a3fae14ed"
|
||||
integrity sha512-SbHR3Q5g/C3N+Ila3KrRf1rSZiyHxWdOZ7X3yFHXzw6HrvRLuVZrxnwEX0lTBMRpH9LkwZdqRTgXW+D075jxkg==
|
||||
"@types/vscode@^1.37.0":
|
||||
version "1.37.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.37.0.tgz#fb26ffabfabcd50ba70e8b454122a91b84548080"
|
||||
integrity sha512-PRfeuqYuzk3vjf+puzxltIUWC+AhEGYpFX29/37w30DQSQnpf5AgMVf7GDBAdmTbWTBou+EMFz/Ne6XCM/KxzQ==
|
||||
|
||||
"@types/webpack@^4.4.31":
|
||||
version "4.32.1"
|
||||
|
@ -454,9 +454,9 @@ balanced-match@^1.0.0:
|
|||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
|
||||
|
||||
base64-js@^1.0.2:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
|
||||
integrity sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
|
||||
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
|
||||
|
||||
base@^0.11.1:
|
||||
version "0.11.2"
|
||||
|
@ -1602,9 +1602,9 @@ globby@^6.1.0:
|
|||
pinkie-promise "^2.0.0"
|
||||
|
||||
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b"
|
||||
integrity sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==
|
||||
version "4.2.1"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.1.tgz#1c1f0c364882c868f5bff6512146328336a11b1d"
|
||||
integrity sha512-b9usnbDGnD928gJB3LrCmxoibr3VE4U2SMo5PBuBnokWyDADTqDPXg4YpwKF1trpH+UbGp7QLicO3+aWEy0+mw==
|
||||
|
||||
has-flag@^3.0.0:
|
||||
version "3.0.0"
|
||||
|
@ -2965,7 +2965,7 @@ rxjs@^6.4.0:
|
|||
dependencies:
|
||||
tslib "^1.9.0"
|
||||
|
||||
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2:
|
||||
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
|
||||
integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==
|
||||
|
@ -3230,11 +3230,11 @@ string-width@^3.0.0, string-width@^3.1.0:
|
|||
strip-ansi "^5.1.0"
|
||||
|
||||
string_decoder@^1.0.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d"
|
||||
integrity sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
|
||||
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
|
||||
dependencies:
|
||||
safe-buffer "~5.1.0"
|
||||
safe-buffer "~5.2.0"
|
||||
|
||||
string_decoder@~1.1.1:
|
||||
version "1.1.1"
|
||||
|
@ -3431,9 +3431,9 @@ tslib@^1.8.1, tslib@^1.9.0:
|
|||
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
|
||||
|
||||
tsutils@^3.7.0:
|
||||
version "3.14.1"
|
||||
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.14.1.tgz#f1d2b93d2a0876481f2f1f98c25ba42bbd7ee860"
|
||||
integrity sha512-kiuZzD1uUA5DxGj/uxbde+ymp6VVdAxdzOIlAFbYKrPyla8/uiJ9JLBm1QsPhOm4Muj0/+cWEDP99yoCUcSl6Q==
|
||||
version "3.17.1"
|
||||
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"
|
||||
integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==
|
||||
dependencies:
|
||||
tslib "^1.8.1"
|
||||
|
||||
|
@ -3547,11 +3547,16 @@ util@^0.11.0:
|
|||
dependencies:
|
||||
inherits "2.0.3"
|
||||
|
||||
v8-compile-cache@2.0.3, v8-compile-cache@^2.0.3:
|
||||
v8-compile-cache@2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.3.tgz#00f7494d2ae2b688cfe2899df6ed2c54bef91dbe"
|
||||
integrity sha512-CNmdbwQMBjwr9Gsmohvm0pbL954tJrNzf6gWL3K+QMQf00PF7ERGrEiLgjuU3mKreLC2MeGhUsNV9ybTbLgd3w==
|
||||
|
||||
v8-compile-cache@^2.0.3:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e"
|
||||
integrity sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==
|
||||
|
||||
vm-browserify@^1.0.1:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"
|
||||
|
@ -3589,9 +3594,9 @@ webpack-cli@^3.3.6:
|
|||
yargs "13.2.4"
|
||||
|
||||
webpack-sources@^1.4.0, webpack-sources@^1.4.1:
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.1.tgz#b91b2c5b1c4e890ff50d1d35b7fa3657040da1da"
|
||||
integrity sha512-XSz38193PTo/1csJabKaV4b53uRVotlMgqJXm3s3eje0Bu6gQTxYDqpD38CmQfDBA+gN+QqaGjasuC8I/7eW3Q==
|
||||
version "1.4.3"
|
||||
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
|
||||
integrity sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==
|
||||
dependencies:
|
||||
source-list-map "^2.0.0"
|
||||
source-map "~0.6.1"
|
||||
|
|
Loading…
Reference in a new issue