utools-api-types 4.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -17
- package/electron.d.ts +66 -0
- package/package.json +8 -5
- package/resource/utools.schema.json +159 -0
- package/tsconfig.json +21 -0
- package/ubw.d.ts +211 -0
- package/utools.api.d.ts +79 -47
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# uTools 官方类型辅助文件
|
|
2
|
+
|
|
3
|
+
## 提供代码提示文件
|
|
4
|
+
|
|
5
|
+
- [utools.api.d.ts](./utools.api.d.ts) `window.utools` 对象类型提示
|
|
6
|
+
- [electron.d.ts](./electron.d.ts) preload 内 `electron` 模块导入提示
|
|
7
|
+
- [resource/utools.schema](./resource/utools.schema.json) 配置文件 JSON Schema
|
|
8
|
+
|
|
9
|
+
## `window.utools` 对象类型提示
|
|
10
|
+
|
|
11
|
+
目前将 utools 挂载到全局 window 下,提供在渲染层跟 preload 层的群体代码提示
|
|
12
|
+
|
|
13
|
+
第一步
|
|
2
14
|
|
|
3
|
-
第一步
|
|
4
15
|
```bash
|
|
5
16
|
npm install utools-api-types --save-dev
|
|
6
17
|
```
|
|
@@ -10,38 +21,82 @@ npm install utools-api-types --save-dev
|
|
|
10
21
|
```json
|
|
11
22
|
{
|
|
12
23
|
"compilerOptions": {
|
|
13
|
-
"types": [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
"types": ["utools-api-types"]
|
|
25
|
+
},
|
|
26
|
+
"includes": [
|
|
27
|
+
// 如果使用ts或者框架,请添加需要类型提示的文件范围
|
|
28
|
+
// 案例:
|
|
29
|
+
// src/**/*.ts
|
|
30
|
+
// preload.js
|
|
31
|
+
]
|
|
17
32
|
}
|
|
18
33
|
```
|
|
19
34
|
|
|
20
|
-
|
|
35
|
+
### API 代码示例
|
|
21
36
|
|
|
22
37
|
```javascript
|
|
23
38
|
// 默认浏览器打开网页
|
|
24
|
-
window.utools.shellOpenExternal(
|
|
39
|
+
window.utools.shellOpenExternal("https://u.tools");
|
|
25
40
|
|
|
26
41
|
// 在资源管理器中显示文件
|
|
27
|
-
window.utools.shellShowItemInFolder(
|
|
42
|
+
window.utools.shellShowItemInFolder("d:\\test");
|
|
28
43
|
|
|
29
44
|
// ubrowser 网页自动化
|
|
30
|
-
window.utools.ubrowser
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
.
|
|
45
|
+
window.utools.ubrowser
|
|
46
|
+
.goto("https://cn.bing.com")
|
|
47
|
+
.value("#sb_form_q", "uTools")
|
|
48
|
+
.click("#sb_form_go")
|
|
49
|
+
.run({ width: 1000, height: 600 });
|
|
34
50
|
|
|
35
51
|
// 值键对方式存储数据
|
|
36
|
-
window.utools.dbStorage.setItem(
|
|
52
|
+
window.utools.dbStorage.setItem("key", "value");
|
|
37
53
|
|
|
38
54
|
// 执行截图
|
|
39
55
|
window.utools.screenCapture((imagebase64) => {
|
|
40
56
|
// 截图完的回调
|
|
41
|
-
})
|
|
57
|
+
});
|
|
42
58
|
|
|
43
59
|
// 执行取色
|
|
44
60
|
window.utools.screenColorPick(({ hex, rgb }) => {
|
|
45
61
|
// 取色完的回调
|
|
46
|
-
})
|
|
47
|
-
```
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## `electron` 模块代码提示
|
|
66
|
+
|
|
67
|
+
引入此类型文件后,支持在 cjs 模式下也提供定制化的 `electron` 模块 api 提示
|
|
68
|
+
|
|
69
|
+
> 在 uTools 中,可以通过 cjs 的形式直接使用部分 `electron` 的 api ,但是此部分支持是直接通过 uTools 内置的 nodejs 实现,因此请勿下载额外的 `electron` 依赖。
|
|
70
|
+
|
|
71
|
+
### API 代码示例
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// preload.js
|
|
75
|
+
|
|
76
|
+
const { ipcRenderer } = require("electron");
|
|
77
|
+
|
|
78
|
+
window.onMyChannel = (callback) => {
|
|
79
|
+
ipcRenderer.on("myChannel", (e, data) => {
|
|
80
|
+
callback?.({
|
|
81
|
+
...data,
|
|
82
|
+
senderId: e.senderId,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
window.ipc = ipcRenderer;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 配置文件 JSON Schema
|
|
91
|
+
|
|
92
|
+
通过 JSON Schema 实现了在 `plugin.json` 内的代码提示
|
|
93
|
+
|
|
94
|
+
引入 JSON Schema 需要在 `plugin.json` 的第一行添加 `$schema` 字段:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"$schema": "./node_modules/utools-api-types/resource/utools.schema.json"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
> 添加 `$schema` 时,需要注意跟 `plugin.json` 所在的文件位置有关系,必须是相对于 `plugin.json` 的位置
|
package/electron.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
declare module "electron" {
|
|
2
|
+
type ClipboardType = 'selection' | 'clipboard'
|
|
3
|
+
module clipboard {
|
|
4
|
+
function availableFormats(type?: ClipboardType): void
|
|
5
|
+
function clear(type?: ClipboardType): void
|
|
6
|
+
function has(fmt: string, type?: ClipboardType): boolean
|
|
7
|
+
function read(fmt: string): string
|
|
8
|
+
function readBookmark(): {
|
|
9
|
+
title: string
|
|
10
|
+
url: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function readBuffer(fmt: string): Uint8Array
|
|
14
|
+
function readHTML(type?: ClipboardType): string
|
|
15
|
+
function readImage(type?: ClipboardType): BrowserWindow.NativeImage
|
|
16
|
+
function readRTF(type?: ClipboardType): string
|
|
17
|
+
function readText(type?: ClipboardType): string
|
|
18
|
+
function write(data: {
|
|
19
|
+
text?: string
|
|
20
|
+
html?: string
|
|
21
|
+
image?: BrowserWindow.NativeImage
|
|
22
|
+
rtf?: string
|
|
23
|
+
bookmark?: string
|
|
24
|
+
}, type?: ClipboardType): void
|
|
25
|
+
function writeBookmark(title: string, url: string, type?: ClipboardType): void
|
|
26
|
+
function writeBuffer(fmt: string, buffer: Uint8Array, type?: ClipboardType): void
|
|
27
|
+
function writeHTML(markup: string, type?: ClipboardType): void
|
|
28
|
+
function writeImage(img: BrowserWindow.NativeImage, type?: ClipboardType): void
|
|
29
|
+
function writeRTF(text: string, type?: ClipboardType): void
|
|
30
|
+
function writeText(text: string, type?: ClipboardType): void
|
|
31
|
+
}
|
|
32
|
+
interface UIpcSendEventInit {
|
|
33
|
+
senderId: number
|
|
34
|
+
}
|
|
35
|
+
type UIpcSendEventListener<T extends any[]> = (event: UIpcSendEventInit, ...args: T) => void
|
|
36
|
+
module ipcRenderer {
|
|
37
|
+
function on<T extends any[] = any[]>(channel: string, listener: UIpcSendEventListener<T>): void
|
|
38
|
+
function once<T extends any[] = any[]>(channel: string, listener: UIpcSendEventListener<T>): void
|
|
39
|
+
function off<T extends any[] = any[]>(channel: string, listener: UIpcSendEventListener<T>): void
|
|
40
|
+
function sendTo<T extends any[] = any[]>(id: number, channel: string, ...args: T): void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module contextBridge { }
|
|
44
|
+
|
|
45
|
+
module webFrame { }
|
|
46
|
+
|
|
47
|
+
module shell { }
|
|
48
|
+
|
|
49
|
+
module nativeImage {
|
|
50
|
+
type NativeImage = BrowserWindow.NativeImage
|
|
51
|
+
function createEmpty(): NativeImage
|
|
52
|
+
function createFromPath(path: string): NativeImage
|
|
53
|
+
function createFromBitmap(buffer: Uint8Array, options: {
|
|
54
|
+
width: number
|
|
55
|
+
height: number
|
|
56
|
+
scaleFator?: number
|
|
57
|
+
}): NativeImage
|
|
58
|
+
function createFromBuffer(buffer: Uint8Array, options?: {
|
|
59
|
+
width?: number
|
|
60
|
+
height?: number
|
|
61
|
+
scaleFator?: number
|
|
62
|
+
}): NativeImage
|
|
63
|
+
function createFromDataURL(dataURL: string): NativeImage
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utools-api-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "TypeScript definitions for uTools API",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/uTools-Labs/utools-api-types
|
|
7
|
+
"url": "https://github.com/uTools-Labs/utools-api-types"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"uTools"
|
|
11
11
|
],
|
|
12
|
-
"author": "utools-
|
|
12
|
+
"author": "utools-core",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/uTools-Labs/utools-api-types/issues"
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/uTools-Labs/utools-api-types#readme",
|
|
18
|
-
"
|
|
19
|
-
|
|
18
|
+
"exports": {
|
|
19
|
+
"default": {
|
|
20
|
+
"types": "./utools.api.d.ts"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
20
23
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://u.tools/docs/plugin.json",
|
|
4
|
+
"title": "uTools 插件配置文件",
|
|
5
|
+
"description": "uTools 插件配置文件,用于描述插件的基本信息,以及插件的入口文件。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"main": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "入口文件,当该配置为空时,表示插件应用为模板插件应用。 main 与 preload 至少存在其一。"
|
|
11
|
+
},
|
|
12
|
+
"preload": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "这是一个关键文件,你可以在此文件内调用 uTools、 nodejs、 electron 提供的 api。 main 与 preload 至少存在其一。"
|
|
15
|
+
},
|
|
16
|
+
"logo": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "插件图标,支持png,jpg格式"
|
|
19
|
+
},
|
|
20
|
+
"platform": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"description": "插件支持的平台,默认为所有平台。",
|
|
23
|
+
"items": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"enum": [
|
|
26
|
+
"win32",
|
|
27
|
+
"darwin",
|
|
28
|
+
"linux"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"development": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"properties": {
|
|
35
|
+
"main": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "入口文件,当该配置为空时,表示插件应用为模板插件应用。 main 与 preload 至少存在其一。"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"pluginSetting": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"properties": {
|
|
44
|
+
"single": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"description": "插件应用是否允许多开(默认不允许)。多开方式:分离插件应用后,再次创建。"
|
|
47
|
+
},
|
|
48
|
+
"height": {
|
|
49
|
+
"type": "number",
|
|
50
|
+
"description": "插件应用高度。可动态修改(参考),该项被设置后,用户则不能再调整高度。最小值为 1 。"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"features": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"description": "features 描述了当 uTools 主输入框内容产生变化时,此插件应用是否显示在搜索结果列表中,一个插件应用可以有多个功能,一个功能可以提供多个命令供用户搜索。",
|
|
57
|
+
"items": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"properties": {
|
|
60
|
+
"code": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "插件应用提供的某个功能的唯一标示,此为必选项,且插件应用内不可重复。"
|
|
63
|
+
},
|
|
64
|
+
"explain": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "对此功能的说明,将在搜索列表对应位置中显示。"
|
|
67
|
+
},
|
|
68
|
+
"icon": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"description": "此功能的图标,支持png,jpg,svg格式。"
|
|
71
|
+
},
|
|
72
|
+
"mainPush": {
|
|
73
|
+
"type": "boolean"
|
|
74
|
+
},
|
|
75
|
+
"platform": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"description": "此功能的支持平台,默认为所有平台。",
|
|
78
|
+
"items": {
|
|
79
|
+
"type": "string",
|
|
80
|
+
"enum": [
|
|
81
|
+
"win32",
|
|
82
|
+
"darwin",
|
|
83
|
+
"linux"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"cmds": {
|
|
88
|
+
"type": "array",
|
|
89
|
+
"description": "该功能下可响应的命令集,支持 6 种类型,由 cmds 的类型或 cmds.type 决定。",
|
|
90
|
+
"items": {
|
|
91
|
+
"type": [
|
|
92
|
+
"string",
|
|
93
|
+
"object"
|
|
94
|
+
],
|
|
95
|
+
"properties": {
|
|
96
|
+
"type": {
|
|
97
|
+
"type": "string",
|
|
98
|
+
"description": "类型",
|
|
99
|
+
"enum": [
|
|
100
|
+
"regex",
|
|
101
|
+
"over",
|
|
102
|
+
"img",
|
|
103
|
+
"files",
|
|
104
|
+
"window"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"label": {
|
|
108
|
+
"type": "string",
|
|
109
|
+
"description": "关键字"
|
|
110
|
+
},
|
|
111
|
+
"match": {
|
|
112
|
+
"type": [
|
|
113
|
+
"string",
|
|
114
|
+
"object"
|
|
115
|
+
],
|
|
116
|
+
"description": "匹配模式",
|
|
117
|
+
"properties": {
|
|
118
|
+
"app": {
|
|
119
|
+
"type": "array"
|
|
120
|
+
},
|
|
121
|
+
"title": {
|
|
122
|
+
"type": "string"
|
|
123
|
+
},
|
|
124
|
+
"class": {
|
|
125
|
+
"type": "array"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"minLength": {
|
|
130
|
+
"type": "number",
|
|
131
|
+
"description": "最小匹配长度",
|
|
132
|
+
"minimum": 1
|
|
133
|
+
},
|
|
134
|
+
"maxLength": {
|
|
135
|
+
"type": "number",
|
|
136
|
+
"description": "最大匹配长度",
|
|
137
|
+
"minimum": 1,
|
|
138
|
+
"maximum": 10000
|
|
139
|
+
},
|
|
140
|
+
"fileType": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"description": "文件类型",
|
|
143
|
+
"enum": [
|
|
144
|
+
"file",
|
|
145
|
+
"directory"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"mainHide":{
|
|
152
|
+
"type":"boolean",
|
|
153
|
+
"description": "设置为 `true` 时,启动对应的 `feature` 不会弹出主面板"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "CommonJS",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES6",
|
|
6
|
+
"DOM"
|
|
7
|
+
],
|
|
8
|
+
"target": "ES6",
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"noImplicitThis": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"strictFunctionTypes": true,
|
|
13
|
+
"types": [],
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.d.ts",
|
|
19
|
+
"utools.api.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/ubw.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
declare module BrowserWindow {
|
|
2
|
+
interface WebPreferences {
|
|
3
|
+
devTools?: boolean
|
|
4
|
+
preload?: string
|
|
5
|
+
zoomFactor: number
|
|
6
|
+
[key: string]: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface InitOptions {
|
|
10
|
+
width?: number,
|
|
11
|
+
height?: number,
|
|
12
|
+
webPreferences: WebPreferences
|
|
13
|
+
show?: boolean
|
|
14
|
+
title?: string
|
|
15
|
+
x?: number
|
|
16
|
+
y?: number
|
|
17
|
+
center?: boolean
|
|
18
|
+
resizable?: boolean
|
|
19
|
+
fullscreen?: boolean
|
|
20
|
+
fullscreenable?: boolean
|
|
21
|
+
skipTaskbar?: true
|
|
22
|
+
closable?: boolean
|
|
23
|
+
frame?: boolean
|
|
24
|
+
alwayOnTop?: boolean
|
|
25
|
+
[key: string]: any
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface NativeImage {
|
|
29
|
+
toPng: (options?: { scaleFator?: number }) => Uint8Array
|
|
30
|
+
toJPEG: (options?: { quality?: number }) => Uint8Array
|
|
31
|
+
isEmpty: () => boolean
|
|
32
|
+
[key: string]: any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface PrinterSync {
|
|
36
|
+
description: string
|
|
37
|
+
displayName: string
|
|
38
|
+
isDefault: boolean
|
|
39
|
+
status: number
|
|
40
|
+
options?: {
|
|
41
|
+
'printer-location'?: string
|
|
42
|
+
'printer-make-and-model'?: string
|
|
43
|
+
'system_driverinfo'?: string
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type WebRTCIPHandlingPolicy =
|
|
48
|
+
| 'default'
|
|
49
|
+
| 'default_public_interface_only'
|
|
50
|
+
| 'default_public_and_private_interfaces'
|
|
51
|
+
| 'disable_non_proxied_udp'
|
|
52
|
+
|
|
53
|
+
interface WebContents {
|
|
54
|
+
id: number
|
|
55
|
+
capturePage: () => Promise<NativeImage>
|
|
56
|
+
closeDevTools: () => void
|
|
57
|
+
copy: () => void
|
|
58
|
+
copyImageAt: (x: number, y: number) => void
|
|
59
|
+
cut: () => void
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated
|
|
62
|
+
*/
|
|
63
|
+
decrementCapturerCount: () => any
|
|
64
|
+
delete: () => void
|
|
65
|
+
disableDeviceEmulation: () => void
|
|
66
|
+
enableDeviceEmulation: () => void
|
|
67
|
+
executeJavaScript: <T>(code: string, userGesture?: boolean) => Promise<T>
|
|
68
|
+
findInPage: (text: string, options?: {
|
|
69
|
+
forward?: boolean
|
|
70
|
+
findNext?: boolean
|
|
71
|
+
matchCase?: boolean
|
|
72
|
+
}) => number
|
|
73
|
+
focus: () => void
|
|
74
|
+
getBackgroundThrottling: () => boolean
|
|
75
|
+
getFrameRate: () => number
|
|
76
|
+
getOSProcessId: () => number
|
|
77
|
+
getPrinters: () => PrinterSync[]
|
|
78
|
+
getProcessId: () => number
|
|
79
|
+
getUserAgent: () => string
|
|
80
|
+
getWebRTCIPHandlingPolicy: () => WebRTCIPHandlingPolicy
|
|
81
|
+
getZoomFactor: () => number
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated
|
|
84
|
+
*/
|
|
85
|
+
incrementCapturerCount: () => any
|
|
86
|
+
insertCSS: (css: string, options?: {
|
|
87
|
+
/**
|
|
88
|
+
* @default 'author'
|
|
89
|
+
*/
|
|
90
|
+
cssOrigin?: 'user' | 'author'
|
|
91
|
+
}) => Promise<string>
|
|
92
|
+
insertText: (text: string) => Promise<void>
|
|
93
|
+
invalidate: () => void
|
|
94
|
+
isAudioMuted: () => boolean
|
|
95
|
+
isBeingCaptured: () => boolean
|
|
96
|
+
isCrashed: () => boolean
|
|
97
|
+
isCurrentlyAudible: () => boolean
|
|
98
|
+
isDestroyed: () => boolean
|
|
99
|
+
isDevToolsFocused: () => boolean
|
|
100
|
+
isDevToolsOpened: () => boolean
|
|
101
|
+
isFocused: () => boolean
|
|
102
|
+
isLoading: () => boolean
|
|
103
|
+
isLoadingMainFrame: () => boolean
|
|
104
|
+
isOffscreen: () => boolean
|
|
105
|
+
isPainting: () => void
|
|
106
|
+
isWaitingForResponse: () => boolean
|
|
107
|
+
openDevTools: (options?: {
|
|
108
|
+
mode: 'left' | 'right' | 'bottom' | 'undocked' | 'detach'
|
|
109
|
+
activate?: boolean
|
|
110
|
+
title?: string
|
|
111
|
+
}) => void
|
|
112
|
+
paste: () => void
|
|
113
|
+
pasteAndMatchStyle: () => void
|
|
114
|
+
print: (options?: Record<string, any>, callback?: (success: boolean, errorType?: string) => void) => void
|
|
115
|
+
printToPDF: (options: Record<string, any>) => Promise<Uint8Array>
|
|
116
|
+
redo: () => void
|
|
117
|
+
removeInsertedCSS: (key: string) => Promise<void>
|
|
118
|
+
replace: (text: string) => void
|
|
119
|
+
replaceMisspelling: (text: string) => void
|
|
120
|
+
savePage: (fullPath: string, saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML') => Promise<void>
|
|
121
|
+
selectAll: () => void
|
|
122
|
+
sendInputEvent: (e: any) => void
|
|
123
|
+
setAudioMuted: (muted: boolean) => void
|
|
124
|
+
setBackgroundThrottling: (allowed: boolean) => void
|
|
125
|
+
setFrameRate: (fps: number) => void
|
|
126
|
+
setIgnoreMenuShortcuts: (ignore: boolean) => void
|
|
127
|
+
setUserAgent: (userAgent: string) => void
|
|
128
|
+
setWebRTCIPHandlingPolicy: (policy: WebRTCIPHandlingPolicy) => void
|
|
129
|
+
setZoomFactor: (factor: number) => void
|
|
130
|
+
startPainting: () => void
|
|
131
|
+
stopFindInPage: (action: 'clearSelection' | 'keepSelection' | 'activateSelection') => void
|
|
132
|
+
stopPainting: () => void
|
|
133
|
+
takeHeapSnapshot: (filePath: string) => Promise<void>
|
|
134
|
+
toggleDevTools: () => void
|
|
135
|
+
undo: () => void
|
|
136
|
+
unselect: () => void
|
|
137
|
+
|
|
138
|
+
[key: string]: any
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface Rectangle {
|
|
142
|
+
x: number
|
|
143
|
+
y: number
|
|
144
|
+
width: number
|
|
145
|
+
height: number
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface WindowInstance {
|
|
149
|
+
id: number
|
|
150
|
+
webContents: WebContents
|
|
151
|
+
show: () => void
|
|
152
|
+
hide: () => void
|
|
153
|
+
destory: () => void
|
|
154
|
+
close: () => void
|
|
155
|
+
isFocused: () => boolean
|
|
156
|
+
isDestroyed: () => boolean
|
|
157
|
+
setResizable: (resizable: boolean) => void
|
|
158
|
+
setSize: (width: number, height: number) => void
|
|
159
|
+
getSize: () => [width: number, height: number]
|
|
160
|
+
isVisible: () => boolean
|
|
161
|
+
maximize: () => void
|
|
162
|
+
unmaximize: () => void
|
|
163
|
+
isMaximized: () => void
|
|
164
|
+
minimize: () => void
|
|
165
|
+
restore: () => void
|
|
166
|
+
isMinimized: () => boolean
|
|
167
|
+
setFullScreen: (flag: boolean) => void
|
|
168
|
+
isFullScreen: () => boolean
|
|
169
|
+
isNormal: () => boolean
|
|
170
|
+
setAspectRatio: (aspectiRotio: number) => void
|
|
171
|
+
setBackgroundColor: (backgroundColor: string) => void
|
|
172
|
+
getBounds: () => Rectangle
|
|
173
|
+
getBackgroundColor: () => string
|
|
174
|
+
setContentBounds: (bounds: Rectangle) => void
|
|
175
|
+
getContentBounds: () => Rectangle
|
|
176
|
+
getNormalBounds: () => Rectangle
|
|
177
|
+
setEnabled: (enable: boolean) => void
|
|
178
|
+
isEnabled: () => boolean
|
|
179
|
+
setContentSize: (width: number, height: number) => void
|
|
180
|
+
getContentSize: () => [width: number, height: number]
|
|
181
|
+
setMinimumSize: (width: number, height: number) => void
|
|
182
|
+
getMinimumSize: () => [width: number, height: number]
|
|
183
|
+
setMaximumSize: (width: number, height: number) => void
|
|
184
|
+
getMaximumSize: () => [width: number, height: number]
|
|
185
|
+
isResizable: () => boolean
|
|
186
|
+
setFullScreenable: (fullscreenable: boolean) => void
|
|
187
|
+
isFullScreenable: () => boolean
|
|
188
|
+
setClosable: (closable: boolean) => void
|
|
189
|
+
isClosable: () => boolean
|
|
190
|
+
setAlwaysOnTop: (flag: boolean) => void
|
|
191
|
+
isAlwaysOnTop: () => boolean
|
|
192
|
+
moveTop: () => void
|
|
193
|
+
setPosition: (x: number, y: number) => void
|
|
194
|
+
getPosition: () => [x: number, y: number]
|
|
195
|
+
setTitle: (title: string) => void
|
|
196
|
+
getTitle: () => string
|
|
197
|
+
flashFrame: (flag: boolean) => void
|
|
198
|
+
setKiosk: (flag: boolean) => void
|
|
199
|
+
isKiosk: () => boolean
|
|
200
|
+
focusOnWebView: () => void
|
|
201
|
+
blurWebView: () => void
|
|
202
|
+
capturePage: (rect?: Rectangle, options?: {
|
|
203
|
+
stayHidden?: boolean
|
|
204
|
+
stayAwake?: boolean
|
|
205
|
+
}) => Promise<NativeImage>
|
|
206
|
+
reload: () => void
|
|
207
|
+
|
|
208
|
+
[key: string]: any
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
package/utools.api.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference path="ubw.d.ts"/>
|
|
2
|
+
/// <reference path="electron.d.ts"/>
|
|
1
3
|
interface UBrowser {
|
|
2
4
|
/**
|
|
3
5
|
* 设置 User-Agent
|
|
@@ -82,7 +84,7 @@ interface UBrowser {
|
|
|
82
84
|
* @param func 在目标网页中执行
|
|
83
85
|
* @param params 传到 func 中的参数
|
|
84
86
|
*/
|
|
85
|
-
evaluate(func: (...params:
|
|
87
|
+
evaluate<T extends any[]>(func: (...params: T) => any, ...params: T): this;
|
|
86
88
|
/**
|
|
87
89
|
* 等待时间
|
|
88
90
|
* @param ms 毫秒
|
|
@@ -100,7 +102,7 @@ interface UBrowser {
|
|
|
100
102
|
* @param timeout 超时 默认60000 ms(60秒)
|
|
101
103
|
* @param params 传到 func 中的参数
|
|
102
104
|
*/
|
|
103
|
-
wait(func: (...params:
|
|
105
|
+
wait<T extends any[]>(func: (...params: T) => boolean, timeout?: number, ...params: T): this;
|
|
104
106
|
/**
|
|
105
107
|
* 当元素存在时执行直到碰到 end
|
|
106
108
|
* @param selector DOM元素
|
|
@@ -111,7 +113,7 @@ interface UBrowser {
|
|
|
111
113
|
* @param func 执行的JS函数
|
|
112
114
|
* @param params 传到 func 中的参数
|
|
113
115
|
*/
|
|
114
|
-
when(func: (...params:
|
|
116
|
+
when<T extends any[]>(func: (...params: T) => boolean, ...params: T): this;
|
|
115
117
|
/**
|
|
116
118
|
* 配合 when 使用
|
|
117
119
|
*/
|
|
@@ -167,7 +169,7 @@ interface UBrowser {
|
|
|
167
169
|
* 当运行结束后,窗口如果为隐藏状态将自动销毁窗口
|
|
168
170
|
* @param options
|
|
169
171
|
*/
|
|
170
|
-
run(options: {
|
|
172
|
+
run<T extends any = any[]>(options: {
|
|
171
173
|
show?: boolean,
|
|
172
174
|
width?: number,
|
|
173
175
|
height?: number,
|
|
@@ -187,12 +189,12 @@ interface UBrowser {
|
|
|
187
189
|
fullscreenable?: boolean,
|
|
188
190
|
enableLargerThanScreen?: boolean,
|
|
189
191
|
opacity?: number
|
|
190
|
-
}): Promise<
|
|
192
|
+
}): Promise<T>;
|
|
191
193
|
/**
|
|
192
194
|
* 运行在闲置的 ubrowser 上
|
|
193
195
|
* @param ubrowserId 1. run(options) 运行结束后, 当 ubrowser 实例窗口仍然显示时返回 2. utools.getIdleUBrowsers() 中获得
|
|
194
196
|
*/
|
|
195
|
-
run(ubrowserId: number): Promise<
|
|
197
|
+
run<T extends any = any[]>(ubrowserId: number): Promise<T>;
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
interface Display {
|
|
@@ -212,11 +214,10 @@ interface Display {
|
|
|
212
214
|
workAreaSize: { width: number, height: number };
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
type DbDoc<T extends {} = Record<string, any>> = {
|
|
216
218
|
_id: string,
|
|
217
219
|
_rev?: string,
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
+
} & T
|
|
220
221
|
|
|
221
222
|
interface DbReturn {
|
|
222
223
|
id: string,
|
|
@@ -227,15 +228,38 @@ interface DbReturn {
|
|
|
227
228
|
message?: string
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
interface PluginFeature {
|
|
232
|
+
code: string,
|
|
233
|
+
explain?: string,
|
|
234
|
+
platform?: ('darwin' | 'win32' | 'linux') | (Array<'darwin' | 'win32' | 'linux'>),
|
|
235
|
+
icon?: string,
|
|
236
|
+
cmds: (string | {
|
|
237
|
+
type: 'img' | 'files' | 'regex' | 'over' | 'window',
|
|
238
|
+
label: string
|
|
239
|
+
})[]
|
|
240
|
+
/**
|
|
241
|
+
* @version >= 5.2.0
|
|
242
|
+
* 设置为 `true` 时,启动对应的 `feature` 不会弹出主面板
|
|
243
|
+
*/
|
|
244
|
+
mainHide?: boolean
|
|
245
|
+
mainPush?: boolean
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
type PluginEnterFrom =
|
|
249
|
+
| 'main'
|
|
250
|
+
| 'panel'
|
|
251
|
+
| 'hotkey'
|
|
252
|
+
| 'redirect'
|
|
253
|
+
|
|
230
254
|
interface UToolsApi {
|
|
231
255
|
/**
|
|
232
256
|
* 插件应用进入时触发
|
|
233
257
|
*/
|
|
234
|
-
onPluginEnter(callback: (action: {code: string, type: string, payload:
|
|
258
|
+
onPluginEnter<T = any, L = any>(callback: (action: { code: string, type: string, payload: T, option: L, from?: PluginEnterFrom }) => void): void;
|
|
235
259
|
/**
|
|
236
260
|
* 向搜索面板推送消息
|
|
237
261
|
*/
|
|
238
|
-
onMainPush(callback: (action: {code: string, type: string, payload:
|
|
262
|
+
onMainPush<T = any>(callback: (action: { code: string, type: string, payload: T }) => { icon?: string, text: string, title?: string }[], selectCallback: (action: { code: string, type: string, payload: any, option: { icon?: string, text: string, title?: string } }) => void): void;
|
|
239
263
|
/**
|
|
240
264
|
* 插件应用隐藏后台或完全退出时触发
|
|
241
265
|
*/
|
|
@@ -247,7 +271,7 @@ interface UToolsApi {
|
|
|
247
271
|
/**
|
|
248
272
|
* 插件应用从云端拉取到数据时触发
|
|
249
273
|
*/
|
|
250
|
-
onDbPull
|
|
274
|
+
onDbPull<T extends {} = Record<string, any>>(callback: (docs: DbDoc<T>[]) => void): void;
|
|
251
275
|
/**
|
|
252
276
|
* 隐藏主窗口
|
|
253
277
|
* @param isRestorePreWindow 是否焦点回归到前面的活动窗口,默认 true
|
|
@@ -267,7 +291,7 @@ interface UToolsApi {
|
|
|
267
291
|
* @param placeholder 占位符, 默认为空
|
|
268
292
|
* @param isFocus 是否获得焦点,默认为 true
|
|
269
293
|
*/
|
|
270
|
-
setSubInput(onChange: (text: string) => void, placeholder?: string, isFocus?: boolean): boolean;
|
|
294
|
+
setSubInput(onChange: (input: { text: string }) => void, placeholder?: string, isFocus?: boolean): boolean;
|
|
271
295
|
/**
|
|
272
296
|
* 移除子输入框
|
|
273
297
|
*/
|
|
@@ -294,11 +318,12 @@ interface UToolsApi {
|
|
|
294
318
|
* @param options 参考 https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions
|
|
295
319
|
* @param callback url 加载完成时的回调
|
|
296
320
|
*/
|
|
297
|
-
createBrowserWindow(url: string, options:
|
|
321
|
+
createBrowserWindow(url: string, options: BrowserWindow.InitOptions, callback?: () => void): BrowserWindow.WindowInstance;
|
|
298
322
|
/**
|
|
299
323
|
* 隐藏插件应用到后台
|
|
324
|
+
* @param {boolean|undefined} isKill 设置为 `true` 时,会将插件进程杀死
|
|
300
325
|
*/
|
|
301
|
-
outPlugin(): boolean;
|
|
326
|
+
outPlugin(isKill?: boolean): boolean;
|
|
302
327
|
/**
|
|
303
328
|
* 是否深色模式
|
|
304
329
|
*/
|
|
@@ -334,7 +359,7 @@ interface UToolsApi {
|
|
|
334
359
|
attach?: string
|
|
335
360
|
}, callback?: () => void): void;
|
|
336
361
|
/**
|
|
337
|
-
* 打开支付 (
|
|
362
|
+
* 打开支付 (付费)
|
|
338
363
|
* @param callback 支付成功触发
|
|
339
364
|
*/
|
|
340
365
|
openPayment(options: {
|
|
@@ -358,16 +383,7 @@ interface UToolsApi {
|
|
|
358
383
|
/**
|
|
359
384
|
* 设置插件应用动态功能
|
|
360
385
|
*/
|
|
361
|
-
setFeature(feature:
|
|
362
|
-
code: string,
|
|
363
|
-
explain: string,
|
|
364
|
-
platform: ('darwin' | 'win32' | 'linux') | (Array<'darwin' | 'win32' | 'linux'>),
|
|
365
|
-
icon?: string,
|
|
366
|
-
cmds: (string | {
|
|
367
|
-
type: 'img' | 'files' | 'regex' | 'over' | 'window',
|
|
368
|
-
label: string
|
|
369
|
-
})[]
|
|
370
|
-
}): boolean;
|
|
386
|
+
setFeature(feature: PluginFeature): boolean;
|
|
371
387
|
/**
|
|
372
388
|
* 移除插件应用动态功能
|
|
373
389
|
*/
|
|
@@ -375,28 +391,20 @@ interface UToolsApi {
|
|
|
375
391
|
/**
|
|
376
392
|
* 获取插件应用动态功能,参数为空获取所有动态功能
|
|
377
393
|
*/
|
|
378
|
-
getFeatures(codes?: string[]):
|
|
379
|
-
code: string,
|
|
380
|
-
explain: string,
|
|
381
|
-
platform: ('darwin' | 'win32' | 'linux') | (Array<'darwin' | 'win32' | 'linux'>),
|
|
382
|
-
icon?: string,
|
|
383
|
-
cmds: string | {
|
|
384
|
-
type: 'img' | 'files' | 'regex' | 'over' | 'window',
|
|
385
|
-
label: string
|
|
386
|
-
}[]
|
|
387
|
-
}[];
|
|
394
|
+
getFeatures(codes?: string[]): PluginFeature[];
|
|
388
395
|
/**
|
|
389
396
|
* 插件应用间跳转
|
|
397
|
+
* @todo 创建针对type的多个重载
|
|
390
398
|
*/
|
|
391
399
|
redirect(label: string | string[], payload: string | { type: 'text' | 'img' | 'files', data: any }): void;
|
|
392
400
|
/**
|
|
393
401
|
* 获取闲置的 ubrowser
|
|
394
402
|
*/
|
|
395
|
-
getIdleUBrowsers(): { id: number, title: string, url: string}[];
|
|
403
|
+
getIdleUBrowsers(): { id: number, title: string, url: string }[];
|
|
396
404
|
/**
|
|
397
405
|
* 设置 ubrowser 代理 https://www.electronjs.org/docs/api/session#sessetproxyconfig
|
|
398
406
|
*/
|
|
399
|
-
setUBrowserProxy(config: {pacScript?: string, proxyRules?: string, proxyBypassRules?: string}): boolean;
|
|
407
|
+
setUBrowserProxy(config: { pacScript?: string, proxyRules?: string, proxyBypassRules?: string }): boolean;
|
|
400
408
|
/**
|
|
401
409
|
* 清空 ubrowser 缓存
|
|
402
410
|
*/
|
|
@@ -404,7 +412,7 @@ interface UToolsApi {
|
|
|
404
412
|
/**
|
|
405
413
|
* 显示系统通知
|
|
406
414
|
*/
|
|
407
|
-
showNotification(body: string): void;
|
|
415
|
+
showNotification(body: string, featureName?: string): void;
|
|
408
416
|
/**
|
|
409
417
|
* 弹出文件选择框
|
|
410
418
|
*/
|
|
@@ -444,7 +452,7 @@ interface UToolsApi {
|
|
|
444
452
|
/**
|
|
445
453
|
* 停止插件应用页面中查找
|
|
446
454
|
*/
|
|
447
|
-
stopFindInPage
|
|
455
|
+
stopFindInPage(action: 'clearSelection' | 'keepSelection' | 'activateSelection'): void;
|
|
448
456
|
/**
|
|
449
457
|
* 拖拽文件
|
|
450
458
|
*/
|
|
@@ -477,6 +485,10 @@ interface UToolsApi {
|
|
|
477
485
|
* 获取文件图标
|
|
478
486
|
*/
|
|
479
487
|
getFileIcon(filePath: string): string;
|
|
488
|
+
/**
|
|
489
|
+
* 获取当前窗口类型, 'main' 主窗口 | 'detach' 分离窗口 | 'browser' 由 createBrowserWindow 创建的窗口
|
|
490
|
+
*/
|
|
491
|
+
getWindowType(): 'main' | 'detach' | 'browser';
|
|
480
492
|
/**
|
|
481
493
|
* 复制文件到剪贴板
|
|
482
494
|
*/
|
|
@@ -509,6 +521,10 @@ interface UToolsApi {
|
|
|
509
521
|
* 默认方式打开给定的文件
|
|
510
522
|
*/
|
|
511
523
|
shellOpenPath(fullPath: string): void;
|
|
524
|
+
/**
|
|
525
|
+
* 删除文件到回收站
|
|
526
|
+
*/
|
|
527
|
+
shellTrashItem(filename: string): Promise<void>;
|
|
512
528
|
/**
|
|
513
529
|
* 在文件管理器中显示给定的文件
|
|
514
530
|
*/
|
|
@@ -532,7 +548,7 @@ interface UToolsApi {
|
|
|
532
548
|
/*
|
|
533
549
|
* 粘贴图像
|
|
534
550
|
*/
|
|
535
|
-
hideMainWindowPasteImage(img: string): void;
|
|
551
|
+
hideMainWindowPasteImage(img: string | Uint8Array): void;
|
|
536
552
|
/*
|
|
537
553
|
* 粘贴文本
|
|
538
554
|
*/
|
|
@@ -577,10 +593,26 @@ interface UToolsApi {
|
|
|
577
593
|
* 获取矩形所在的显示器
|
|
578
594
|
*/
|
|
579
595
|
getDisplayMatching(rect: { x: number, y: number, width: number, height: number }): Display;
|
|
596
|
+
/**
|
|
597
|
+
* 屏幕物理坐标转 DIP 坐标
|
|
598
|
+
*/
|
|
599
|
+
screenToDipPoint(point: { x: number, y: number }): { x: number, y: number };
|
|
600
|
+
/**
|
|
601
|
+
* 屏幕 DIP 坐标转物理坐标
|
|
602
|
+
*/
|
|
603
|
+
dipToScreenPoint(point: { x: number, y: number }): { x: number, y: number };
|
|
604
|
+
/**
|
|
605
|
+
* 屏幕物理区域转 DIP 区域
|
|
606
|
+
*/
|
|
607
|
+
screenToDipRect(rect: { x: number, y: number, width: number, height: number }): { x: number, y: number, width: number, height: number };
|
|
608
|
+
/**
|
|
609
|
+
* 屏幕 DIP 区域转物理区域
|
|
610
|
+
*/
|
|
611
|
+
dipToScreenRect(rect: { x: number, y: number, width: number, height: number }): { x: number, y: number, width: number, height: number };
|
|
580
612
|
/**
|
|
581
613
|
* 录屏源
|
|
582
614
|
*/
|
|
583
|
-
desktopCaptureSources(options: { types: string[], thumbnailSize?: { width: number, height: number }, fetchWindowIcons?: boolean }):Promise<{appIcon: {}, display_id: string, id: string, name: string, thumbnail: {} }>;
|
|
615
|
+
desktopCaptureSources(options: { types: string[], thumbnailSize?: { width: number, height: number }, fetchWindowIcons?: boolean }): Promise<{ appIcon: {}, display_id: string, id: string, name: string, thumbnail: {} }>;
|
|
584
616
|
/**
|
|
585
617
|
* 是否开发中
|
|
586
618
|
*/
|
|
@@ -606,7 +638,7 @@ interface UToolsApi {
|
|
|
606
638
|
/**
|
|
607
639
|
* 获取文档
|
|
608
640
|
*/
|
|
609
|
-
get(id: string): DbDoc | null;
|
|
641
|
+
get<T extends {} = Record<string, any>>(id: string): DbDoc<T> | null;
|
|
610
642
|
/**
|
|
611
643
|
* 删除文档
|
|
612
644
|
*/
|
|
@@ -618,7 +650,7 @@ interface UToolsApi {
|
|
|
618
650
|
/**
|
|
619
651
|
* 获取所有文档 可根据文档id前缀查找
|
|
620
652
|
*/
|
|
621
|
-
allDocs(key?: string): DbDoc[];
|
|
653
|
+
allDocs<T extends {} = Record<string, any>>(key?: string): DbDoc<T>[];
|
|
622
654
|
/**
|
|
623
655
|
* 存储附件到新文档
|
|
624
656
|
* @param docId 文档ID
|
|
@@ -694,15 +726,15 @@ interface UToolsApi {
|
|
|
694
726
|
* @param key 键名(同时为文档ID)
|
|
695
727
|
* @param value 键值
|
|
696
728
|
*/
|
|
697
|
-
setItem
|
|
729
|
+
setItem(key: string, value: any): void;
|
|
698
730
|
/**
|
|
699
731
|
* 获取键名对应的值
|
|
700
732
|
*/
|
|
701
|
-
getItem (key: string):
|
|
733
|
+
getItem<T = any>(key: string): T;
|
|
702
734
|
/**
|
|
703
735
|
* 删除键值对(删除文档)
|
|
704
736
|
*/
|
|
705
|
-
removeItem
|
|
737
|
+
removeItem(key: string): void;
|
|
706
738
|
};
|
|
707
739
|
|
|
708
740
|
ubrowser: UBrowser;
|