refactor: ts3.7
This commit is contained in:
parent
0be9fbdf5e
commit
685d10eb3b
6 changed files with 973 additions and 194 deletions
|
@ -185,7 +185,6 @@
|
|||
"bufferutil": "^4.0.1",
|
||||
"clipboardy": "^2.1.0",
|
||||
"discord-rpc": "discordjs/RPC",
|
||||
"register-scheme": "devsnek/node-register-scheme",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"vsls": "^0.3.1291"
|
||||
},
|
||||
|
@ -199,10 +198,10 @@
|
|||
"eslint-config-marine": "^5.3.2",
|
||||
"eslint-config-prettier": "^6.5.0",
|
||||
"eslint-plugin-prettier": "^3.1.1",
|
||||
"prettier": "^1.18.2",
|
||||
"prettier": "prettier/prettier",
|
||||
"terser-webpack-plugin": "^2.2.1",
|
||||
"ts-loader": "^6.2.1",
|
||||
"typescript": "^3.6.4",
|
||||
"typescript": "^3.7.1-rc",
|
||||
"webpack": "^4.41.2",
|
||||
"webpack-cli": "^3.3.10"
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as vsls from 'vsls';
|
|||
import Activity from '../structures/Activity';
|
||||
import Logger from '../structures/Logger';
|
||||
import { API } from '../git';
|
||||
const clipboardy = require('clipboardy'); // eslint-disable-line
|
||||
import * as clipboardy from 'clipboardy';
|
||||
|
||||
let activityTimer: NodeJS.Timer;
|
||||
|
||||
|
@ -73,7 +73,6 @@ export default class RPCClient implements Disposable {
|
|||
this.statusBarIcon.text = '$(globe) Connected to Discord';
|
||||
this.statusBarIcon.tooltip = 'Connected to Discord';
|
||||
|
||||
// @ts-ignore
|
||||
setTimeout(() => (this.statusBarIcon.text = '$(globe)'), 5000);
|
||||
|
||||
if (activityTimer) clearInterval(activityTimer);
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
import {
|
||||
commands,
|
||||
ExtensionContext,
|
||||
StatusBarAlignment,
|
||||
StatusBarItem,
|
||||
window,
|
||||
workspace,
|
||||
extensions
|
||||
} from 'vscode';
|
||||
import { commands, ExtensionContext, StatusBarAlignment, StatusBarItem, window, workspace, extensions } from 'vscode';
|
||||
import RPCClient from './client/RPCClient';
|
||||
import Logger from './structures/Logger';
|
||||
import { GitExtension } from './git';
|
||||
const { register } = require('discord-rpc'); // eslint-disable-line
|
||||
|
||||
const sleep = (wait: number) => new Promise(resolve => setTimeout(resolve, wait));
|
||||
let loginTimeout: NodeJS.Timer;
|
||||
|
@ -19,7 +10,6 @@ const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignme
|
|||
statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
||||
|
||||
const config = workspace.getConfiguration('discord');
|
||||
register(config.get<string>('clientID'));
|
||||
const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon);
|
||||
|
||||
export async function activate(context: ExtensionContext) {
|
||||
|
@ -39,7 +29,7 @@ export async function activate(context: ExtensionContext) {
|
|||
|
||||
let isWorkspaceExcluded = false;
|
||||
const excludePatterns = config.get<string[]>('workspaceExcludePatterns');
|
||||
if (excludePatterns && excludePatterns.length > 0) {
|
||||
if (excludePatterns?.length) {
|
||||
for (const pattern of excludePatterns) {
|
||||
const regex = new RegExp(pattern);
|
||||
const folders = workspace.workspaceFolders;
|
||||
|
|
16
src/git.d.ts
vendored
16
src/git.d.ts
vendored
|
@ -1,9 +1,9 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
*/
|
||||
|
||||
import { Uri, SourceControlInputBox, Event, CancellationToken } from 'vscode';
|
||||
import { Uri, Event } from 'vscode';
|
||||
|
||||
export interface Git {
|
||||
readonly path: string;
|
||||
|
@ -16,7 +16,7 @@ export interface InputBox {
|
|||
export const enum RefType {
|
||||
Head,
|
||||
RemoteHead,
|
||||
Tag
|
||||
Tag,
|
||||
}
|
||||
|
||||
export interface Ref {
|
||||
|
@ -74,7 +74,7 @@ export const enum Status {
|
|||
DELETED_BY_THEM,
|
||||
BOTH_ADDED,
|
||||
BOTH_DELETED,
|
||||
BOTH_MODIFIED
|
||||
BOTH_MODIFIED,
|
||||
}
|
||||
|
||||
export interface Change {
|
||||
|
@ -114,12 +114,12 @@ export interface Repository {
|
|||
readonly state: RepositoryState;
|
||||
readonly ui: RepositoryUIState;
|
||||
|
||||
getConfigs(): Promise<{ key: string; value: string; }[]>;
|
||||
getConfigs(): Promise<{ key: string; value: string }[]>;
|
||||
getConfig(key: string): Promise<string>;
|
||||
setConfig(key: string, value: string): Promise<string>;
|
||||
|
||||
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
|
||||
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
|
||||
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>;
|
||||
detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }>;
|
||||
buffer(ref: string, path: string): Promise<Buffer>;
|
||||
show(ref: string, path: string): Promise<string>;
|
||||
getCommit(ref: string): Promise<Commit>;
|
||||
|
|
|
@ -39,8 +39,9 @@ interface FileDetail {
|
|||
export default class Activity implements Disposable {
|
||||
private _state: State | null = null;
|
||||
|
||||
private _lastKnownFile: string = '';
|
||||
private _lastKnownFile = '';
|
||||
|
||||
// eslint-disable-next-line no-useless-constructor
|
||||
public constructor(public client: RPCClient) {}
|
||||
|
||||
public get state() {
|
||||
|
@ -91,7 +92,7 @@ export default class Activity implements Disposable {
|
|||
}
|
||||
|
||||
let previousTimestamp = null;
|
||||
if (this._state && this._state.startTimestamp) previousTimestamp = this._state.startTimestamp;
|
||||
if (this._state?.startTimestamp) previousTimestamp = this._state.startTimestamp;
|
||||
|
||||
this._state = {
|
||||
...this._state,
|
||||
|
@ -214,7 +215,7 @@ export default class Activity implements Disposable {
|
|||
|
||||
public increasePartySize(size?: number) {
|
||||
if (!this._state) return;
|
||||
if (this.state && this._state.partySize === 5) return;
|
||||
if (this._state.partySize === 5) return;
|
||||
this._state = {
|
||||
...this._state,
|
||||
partySize: this._state.partySize ? this._state.partySize + 1 : size,
|
||||
|
@ -225,7 +226,7 @@ export default class Activity implements Disposable {
|
|||
|
||||
public decreasePartySize(size?: number) {
|
||||
if (!this._state) return;
|
||||
if (this.state && this._state.partySize === 1) return;
|
||||
if (this._state.partySize === 1) return;
|
||||
this._state = {
|
||||
...this._state,
|
||||
partySize: this._state.partySize ? this._state.partySize - 1 : size,
|
||||
|
@ -240,7 +241,7 @@ export default class Activity implements Disposable {
|
|||
}
|
||||
|
||||
private async _generateDetails(debugging: string, editing: string, idling: string, largeImageKey: any) {
|
||||
let raw: string = this.client.config.get<string>(idling)!.replace('{null}', empty);
|
||||
let raw = this.client.config.get<string>(idling)!.replace('{null}', empty);
|
||||
let filename = null;
|
||||
let dirname = null;
|
||||
let checkState = false;
|
||||
|
@ -270,7 +271,9 @@ export default class Activity implements Disposable {
|
|||
raw = this.client.config.get<string>(editing)!;
|
||||
}
|
||||
|
||||
const { totalLines, size, currentLine, currentColumn, gitbranch, gitreponame } = await this._generateFileDetails(raw);
|
||||
const { totalLines, size, currentLine, currentColumn, gitbranch, gitreponame } = await this._generateFileDetails(
|
||||
raw,
|
||||
);
|
||||
raw = raw
|
||||
.replace('{null}', empty)
|
||||
.replace('{filename}', filename)
|
||||
|
@ -335,7 +338,7 @@ export default class Activity implements Disposable {
|
|||
|
||||
if (str.includes('{gitbranch}')) {
|
||||
if (this.client.git.repositories.length) {
|
||||
fileDetail.gitbranch = this.client.git.repositories.find((repo) => repo.ui.selected)!.state.HEAD!.name;
|
||||
fileDetail.gitbranch = this.client.git.repositories.find(repo => repo.ui.selected)!.state.HEAD!.name;
|
||||
} else {
|
||||
fileDetail.gitbranch = 'Unknown';
|
||||
}
|
||||
|
@ -343,7 +346,10 @@ export default class Activity implements Disposable {
|
|||
|
||||
if (str.includes('{gitreponame}')) {
|
||||
if (this.client.git.repositories.length) {
|
||||
fileDetail.gitreponame = this.client.git.repositories.find((repo) => repo.ui.selected)!.state.remotes[0].fetchUrl!.split('/')[1].replace('.git', '');
|
||||
fileDetail.gitreponame = this.client.git.repositories
|
||||
.find(repo => repo.ui.selected)!
|
||||
.state.remotes[0].fetchUrl!.split('/')[1]
|
||||
.replace('.git', '');
|
||||
} else {
|
||||
fileDetail.gitreponame = 'Unknown';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue