From 695dc824e3ffb04c5288f62c78545c48c7574499 Mon Sep 17 00:00:00 2001 From: takayama Date: Sun, 2 May 2021 17:28:44 +0900 Subject: [PATCH] show error at duplicate of login --- CHANGELOG.md | 4 ++++ README.md | 1 - package-lock.json | 2 +- package.json | 2 +- src/client.ts | 12 ++++++++++++ src/extension.ts | 17 ++++++++++++++++- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1632cd6..1e38317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # VS Code QQ Extension Change Log +## Version 1.2.2: 2021/5/2 + +* 增加账号重复登录检测,以避免出现多个Code中重复登录的情况 + ## Version 1.2.1: 2021/4/27 * [default-theme] 头像和图片使用 `https` url diff --git a/README.md b/README.md index 7e6c2d5..82d8a1a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ ## 其他 -* 注意:不同Code之间暂时无法检测到是否有登录,如果你打开了多个Code,切勿重复登录。 * [清除登录信息](https://github.com/takayama-lily/vscode-qq/wiki/%E6%B8%85%E9%99%A4%E7%99%BB%E5%BD%95%E4%BF%A1%E6%81%AF) * [外网被限制无法登录的解决方法](https://github.com/takayama-lily/vscode-qq/wiki/%E6%88%91%E7%9A%84%E6%9C%BA%E5%99%A8%E6%B2%A1%E6%9C%89%E5%A4%96%E7%BD%91%E6%80%8E%E4%B9%88%E5%8A%9E) diff --git a/package-lock.json b/package-lock.json index 87a5ae0..70be213 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-qq", - "version": "1.2.1", + "version": "1.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 86211a9..c984143 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-qq", "displayName": "QQ", "description": "lite qq for chat in working", - "version": "1.2.1", + "version": "1.2.2", "engines": { "vscode": "^1.53.0" }, diff --git a/src/client.ts b/src/client.ts index f222a19..a62067f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,3 +1,5 @@ +import * as fs from 'fs'; +import * as path from 'path'; import * as crypto from 'crypto'; import * as vscode from 'vscode'; import * as oicq from 'oicq'; @@ -26,6 +28,16 @@ const statusMap: { [k: number]: string } = { */ function createClient(uin: number) { const c = oicq.createClient(uin, genClientConfig()); + + try { + const stat = fs.statSync(path.join(c.dir, "online.lock"), { bigint: true }); + const diff = Date.now() - Number(stat.mtimeMs); + if (diff >= 0 && diff < 10000) { + vscode.window.showErrorMessage("你已经在另一个Code中登录了此账号。"); + return; + } + } catch { } + setClient(c); client.on("system.login.error", function (data) { diff --git a/src/extension.ts b/src/extension.ts index b344660..e7813fd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,6 +6,8 @@ import * as path from 'path'; import * as global from "./global"; import * as client from "./client"; +let timer: NodeJS.Timeout | undefined; + // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { @@ -19,6 +21,14 @@ export function activate(context: vscode.ExtensionContext) { fs.mkdirSync(path.join(context.globalStoragePath, "tmp")); } + if (!timer) { + timer = setInterval(() => { + if (global.client?.isOnline()) { + fs.writeFile(path.join(global.client.dir, "online.lock"), "114514", () => { }); + } + }, 5000); + } + // creat status bar item const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); statusBarItem.text = "QQ"; @@ -28,4 +38,9 @@ export function activate(context: vscode.ExtensionContext) { } // this method is called when your extension is deactivated -export function deactivate() { } +export function deactivate() { + if (timer) { + clearInterval(timer); + timer = undefined; + } +}