Skip to content

Commit

Permalink
Merge pull request #163 from zqjimlove/feature/update-leek-home
Browse files Browse the repository at this point in the history
Feature: 升级韭菜中心
  • Loading branch information
giscafer committed Jan 17, 2021
2 parents a8cc17e + 47219f6 commit 4d1ce0b
Show file tree
Hide file tree
Showing 90 changed files with 19,639 additions and 1,462 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ node_modules
yarn.lock
package-lock.json
demo/donate.html
demo/api.html
demo/api.html

.DS_Store

template/leek-center/build
template-packages/leek-center/.eslintcache
!template-packages/leek-center/yarn.lock
57 changes: 27 additions & 30 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}",
"env": {
"NODE_ENV": "development"
}
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vscode-test/**
out/test/**
src/**
template-packages
demo/
screenshot/
.gitignore
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,13 @@
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"postcompile": "yarn --cwd ./template-packages/leek-center run build",
"lint": "eslint src --ext ts --ignore-path .gitignore",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"test": "node ./out/_test/runTest.js",
"deploy": "vsce publish --yarn",
"package": "vsce package --yarn -o ./",
"commitmsg": "commitlint -e $GIT_PARAMS"
},
"config": {
Expand Down
2 changes: 2 additions & 0 deletions src/explorer/fundService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class FundService extends LeekService {
code: FCODE,
price: GSZ, // 今日估值
percent: isNaN(Number(GSZZL)) ? NAVCHGRT : GSZZL, // 当日估值没有取前日(海外基)
yestpercent: NAVCHGRT,
yestclose: NAV, // 昨日净值
showLabel: this.showLabel,
earnings: toFixed(earnings), // 盈亏
Expand All @@ -78,6 +79,7 @@ export default class FundService extends LeekService {
t2: GSZZL === '--' ? true : false, // 海外基金t2
time: GSZZL === '--' ? PDATE : GZTIME, // 更新时间
showEarnings: keyLength > 0 && amount !== 0,
yestPriceDate: PDATE,
};
updateTime = obj.time;
totalAmount += amount;
Expand Down
1 change: 1 addition & 0 deletions src/explorer/stockService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default class StockService extends LeekService {
high: formatNumber(high, fixedNumber, false),
volume: formatNumber(params[8], 2),
amount: formatNumber(params[9], 2),
time:`${params[30]} ${params[31]}`,
percent: '',
};
aStockCount += 1;
Expand Down
15 changes: 10 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ import { StatusBar } from './statusbar/statusBar';
import { ProfitStatusBar } from './statusbar/Profit';
import { cacheStocksRemindData } from './webview/leekCenterView';
import { cacheFundAmountData, updateAmount } from './webview/setAmount';
import { events } from './shared/utils';
import FlashNewsOutputServer from './output/flash-news/FlashNewsOutputServer';

let loopTimer: NodeJS.Timer | null = null;
let binanceLoopTimer: NodeJS.Timer | null = null;
let fundTreeView: TreeView<any> | null = null;
let stockTreeView: TreeView<any> | null = null;
let binanceTreeView: TreeView<any> | null = null;

let flashNewsDaemon: FlashNewsDaemon | null = null;
let flashNewsOutputServer: FlashNewsOutputServer | null = null;
let profitBar: ProfitStatusBar | null = null;

export function activate(context: ExtensionContext) {
console.log('🐥Congratulations, your extension "leek-fund" is now active!');

globalState.isDevelopment = process.env.NODE_ENV === 'development';
globalState.context = context;

const telemetry = new Telemetry();
Expand All @@ -52,7 +56,7 @@ export function activate(context: ExtensionContext) {
setGlobalVariable();
updateAmount();

flashNewsDaemon = new FlashNewsDaemon();
flashNewsOutputServer = new FlashNewsOutputServer();

const fundService = new FundService(context);
const stockService = new StockService(context);
Expand Down Expand Up @@ -163,7 +167,8 @@ export function activate(context: ExtensionContext) {
nodeStockProvider.refresh();
newsProvider.refresh();
binanceProvider.refresh();
flashNewsDaemon?.reload();
flashNewsOutputServer?.reload();
events.emit('onDidChangeConfiguration');
profitBar?.reload();
});

Expand All @@ -175,7 +180,7 @@ export function activate(context: ExtensionContext) {
nodeFundProvider,
nodeStockProvider,
newsProvider,
flashNewsDaemon,
flashNewsOutputServer,
binanceProvider
);

Expand Down Expand Up @@ -207,7 +212,7 @@ function setGlobalVariable() {
// this method is called when your extension is deactivated
export function deactivate() {
console.log('🐥deactivate');
flashNewsDaemon?.destory();
FlashNewsDaemon.KillAllServer();
profitBar?.destroy();
if (loopTimer) {
clearInterval(loopTimer);
Expand Down
3 changes: 3 additions & 0 deletions src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ let isHolidayChina = false; // 初始化状态,默认是false,免得API有
let showStockErrorInfo = true; // 控制只显示一次错误弹窗(临时处理)
let immersiveBackground = true; // 基金图表是否沉浸式背景

let isDevelopment = false; // 是否开发环境

export default {
context,
telemetry,
Expand All @@ -51,4 +53,5 @@ export default {
labelFormat,
showStockErrorInfo,
immersiveBackground,
isDevelopment,
};
116 changes: 60 additions & 56 deletions src/output/flash-news/FlashNewsDaemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,84 @@ import { LeekFundConfig } from '../../shared/leekConfig';
import { events } from '../../shared/utils';
import Jin10FlushService from './impl/Jin10FlushService';
import XuanGuBaoFlushService from './impl/XuanGuBaoFLushServices';
import NewsFlushServiceAbstractClass, {
FlashNewsServerInterface,
} from './NewsFlushServiceAbstractClass';

const throttle = require('lodash.throttle');
let instance: FlashNewsDaemon | undefined;

export default class FlashNewsDaemon {
public op: OutputChannel | undefined;
public newsCount: number = 0;
public depServers = new Set<FlashNewsServerInterface>();
public flushServices = new Set<NewsFlushServiceAbstractClass>();
public caches: any[][] = [];

newsCache: string[] = [];

isEnable: boolean = false;
// private services: NewsFlushServiceAbstractClass[] = [];

flashNewsBarItem: StatusBarItem | undefined;
isDestory = false;

constructor() {
this.updateNewsBarItem = throttle(this.updateNewsBarItem, 1000);
this.isEnable = LeekFundConfig.getConfig('leek-fund.flash-news');
if (this.isEnable) {
this.initServices();
this.initServices();
}

static KillAllServer() {
if (instance) {
instance.depServers.forEach((dep) => {
dep.destory();
instance?.depServers.delete(dep);
});
instance.destory();
}
}

initServices() {
this.op = window.createOutputChannel('韭菜盒子 - 快讯');
this.flashNewsBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 3);
this.flashNewsBarItem.text = `⚡️️ ${this.newsCount}`;
this.flashNewsBarItem.command = 'leek-fund.flash-news-show';
this.flashNewsBarItem.show();
static registerServer(dep: FlashNewsServerInterface) {
if (!instance) {
instance = new FlashNewsDaemon();
}

new Jin10FlushService(this);
new XuanGuBaoFlushService(this);
}
instance.depServers.add(dep);
instance.caches.reverse().forEach((params) => {
return dep.print.apply(dep, [params[0], params[1]]);
});

updateNewsBarItem() {
if (this.flashNewsBarItem) {
this.flashNewsBarItem.text = `⚡️️ ${this.newsCount}`;
this.flashNewsBarItem.tooltip = `${this.newsCache.join(
'\r\n-----------------------------\r\n'
)}`;
this.flashNewsBarItem.show();
if (instance.isDestory) {
instance.initServices();
}
return function cancelServer() {
instance?.depServers.delete(dep);
instance?.tryDestory();
};
}

print(news: string) {
this.newsCount++;
this.newsCache.push(news);
this.newsCache = this.newsCache.slice(-5);
this.updateNewsBarItem();
this.op?.appendLine(`${news}\r\n-----------------------------`);
initServices() {
// 暂时不要金十快讯,金十更适合期货。
this.flushServices.add(new Jin10FlushService(this));
this.flushServices.add(new XuanGuBaoFlushService(this));
this.isDestory = false;
}
destory() {
events.emit('FlashNewsServices#destory');
this.newsCache.length = 0;
this.newsCount = 0;
this.flashNewsBarItem?.dispose();
this.op?.dispose();

print(news: string, source?: { type: string; data: any; time: number }) {
this.caches.unshift([news, source]);
this.caches.slice(0, 30);
this.depServers.forEach((dep) => {
dep.print(news, source);
});
}
reload() {
const _enable: boolean = LeekFundConfig.getConfig('leek-fund.flash-news');
if (this.isEnable !== _enable) {
this.isEnable = _enable;
if (!_enable) {
this.destory();
} else {
this.initServices();
}

tryDestory() {
if (this.depServers.size < 1) {
this.destory();
}
}
showOutput() {
this.op?.show();
this.newsCount = 0;
if (this.flashNewsBarItem) {
this.flashNewsBarItem.text = `⚡️️ ${this.newsCount}`;
this.flashNewsBarItem.show();
}

/**
* 销毁
*/
destory() {
this.caches.length = 0
this.flushServices.forEach((service) => {
service.destory();
});
this.isDestory = true;
}

reload() {}
}
Loading

0 comments on commit 4d1ce0b

Please sign in to comment.