Skip to content

Commit

Permalink
show error at duplicate of login
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed May 2, 2021
1 parent 1dee778 commit 695dc82
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 12 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 16 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand All @@ -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;
}
}

0 comments on commit 695dc82

Please sign in to comment.