2.1.1 • Published 2 years ago
@wecooperate/imonitor v2.1.1
@wecooperate/imonitor
@wecooperate/imonitor 是 iMonitor(冰镜)的TypeScript扩展声明库。
快速开始
import { MessageColumn, IMessageColumn, IMessage, MessageType, MessageMatcher, IMessageMatcher, MessageColumnAlign, Icon } from '@wecooperate/imonitor';
import * as path from 'path';
@MessageColumn("TypeScript.FileExt")
class FileExtColumn implements IMessageColumn {
align = MessageColumnAlign.Right;
GetString(msg: IMessage): string {
if (msg.Type > MessageType.RegCreateKey) {
return "";
}
return path.extname(msg.Path);
}
GetTextColor(msg: IMessage): number {
return 0x0000FF;
}
GetBackgroundColor(msg: IMessage): number {
return 0x554444;
}
GetIcon(msg: IMessage): Icon {
return msg.Process.Icon;
}
}
@MessageMatcher("TypeScript.FileExt.PE")
class FileExtMatcher implements IMessageMatcher {
IsMatch(msg: IMessage): boolean {
if (msg.Type > MessageType.RegCreateKey) {
return false;
}
let ext = path.extname(msg.Path).toLowerCase();
return ext === '.exe' || ext === ".dll" || ext === ".sys";
}
}
将上面的代码通过TypeScript的Playground功能,可以快速生成JavaScript代码。 TypeScript Playground
脚本加载后使用效果如下:
更多使用可以参考examples目录。
添加一个列
- 继承实现IMessageColumn
- 通过RegisterMessageColumn注册(如果使用typescript,可以用装饰器的方式 @MessageColumn)
export interface IMessageColumn {
align?: MessageColumnAlign;
width?: number;
description?: string;
GetString(msg: IMessage): string;
GetToolTips?(msg: IMessage): string;
GetTextColor?(msg: IMessage): number;
GetBackgroundColor?(msg: IMessage): number;
GetIcon?(msg: IMessage): Icon;
}
成员 | 说明 | 是否必须 |
---|---|---|
GetString | 返回列显示的字符串 | 是 |
GetToolTips | 返回鼠标hover到列显示的ToolTips | 否 |
GetBackgroundColor | 返回列的背景颜色 | 否 |
GetTextColor | 返回列的文字颜色 | 否 |
GetIcon | 返回列的图标(Icon目前只支持获取进程Icon,未来会添加加载文件Icon) | 否 |
align | 列对齐方式(靠左、居中、靠右),默认靠左对齐 | 否 |
width | 列初始化的宽度 | |
description | 列信息描述说明 |
添加一个自定义规则匹配器
- 继承实现IMessageMatcher
- 通过RegisterMessageMatcher注册(如果使用typescript,可以用装饰器的方式 @MessageMatcher)
export interface IMessageMatcher {
description?: string;
IsMatch(msg: IMessage): boolean;
}
成员 | 说明 | 是否必须 |
---|---|---|
IsMatch | 返回是否匹配 | 是 |
description | 匹配器的描述说明 | 否 |