README.md 3.0 KB
Newer Older
木偶 已提交
1 2 3
<div align= "center">
<img align="center" src="https://user-images.githubusercontent.com/21073039/123022701-c3848180-d408-11eb-86ec-7727f355ea96.png" />
</div>
M
init  
muwoo 已提交
4

木偶 已提交
5 6 7 8
<h1 align= "center">Rubick</h1>

基于 electron 的工具箱,媲美 utools的开源插件,已实现 utools 大部分的 API 能力,所以可以做到无缝适配 utools 开源的插件。
之所以做这个工具箱一方面是 utools 本身并未开源,但是公司内部的工具库又无法发布到 utools 插件中,所以为了既要享受 utools 生态又要有定制化需求,我们自己参考 utools 设计,做了 Rubick
M
init  
muwoo 已提交
9

木偶 已提交
10
![image](https://user-images.githubusercontent.com/21073039/122888869-d6e60d00-d374-11eb-9fb9-2a6e541e389e.png)
M
init  
muwoo 已提交
11

木偶 已提交
12 13
## utools 插件支持
### plugin.json
木偶 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
在你觉得合适的地方新建一个文件夹,并创建 `plugin.json` 文件。这是最重要的一个文件,用来说明这个插件将如何与 `rubick` 集成,最基本的格式如下:
```json
{
	"pluginName": "helloWorld",
	"description": "我的第一个uTools插件",
	"main": "index.html",
	"version": "0.0.1",
	"logo": "logo.png",
	"features": [
		{
		  "code": "hello",
		  "explain": "hello world",
			"cmds":["hello", "你好"]
		}
	]
}
```
所有字段和 `utools` 保持一致,这将可以完美使用`utools`的插件生态

木偶 已提交
33
## utools api 支持
木偶 已提交
34

木偶 已提交
35
### 事件
木偶 已提交
36

木偶 已提交
37
#### onPluginReady(callback)
木偶 已提交
38 39 40 41 42 43 44 45 46 47 48 49
* `callback` Function

> 当插件装载成功,uTools 将会主动调用这个方法(生命周期内仅调用一次),所有的 `api` 都应该在 `onPluginReady` 之后进行调用。

##### 示例

```js
utools.onPluginReady(() => {
  console.log('插件装配完成,已准备好')
})
```

木偶 已提交
50
#### onPluginEnter(callback)
木偶 已提交
51 52 53 54 55
* `callback` Function

> 每当插件从后台进入到前台时,uTools 将会主动调用这个方法。

##### 示例
M
init  
muwoo 已提交
56

木偶 已提交
57 58 59 60 61 62 63 64
```js
utools.onPluginEnter(({code, type, payload, optional}) => {
  console.log('用户进入插件', code, type, payload)
})
```

更多可以参考 `utools` 文档:https://u.tools/docs/developer/api.html#%E4%BA%8B%E4%BB%B6

木偶 已提交
65
### 窗口交互
木偶 已提交
66 67


木偶 已提交
68
### 本地数据库
木偶 已提交
69 70
类似于 `utools` 的功能,我们也提供了本地数据库的 api 能力

木偶 已提交
71
#### utools.db.put(doc)
木偶 已提交
72

木偶 已提交
73
##### 示例
木偶 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
```js
// 创建请求
utools.db.put({
  _id: "demo",
  data: "demo"
})
// 返回 {id: "demo", ok: true, rev: "1-05c9b92e6f24287dc1f4ec79d9a34fa8"}

// 更新请求
utools.db.put({
  _id: "demo",
  data: "demo",
  _rev: "1-05c9b92e6f24287dc1f4ec79d9a34fa8"
})

```
M
init  
muwoo 已提交
90

木偶 已提交
91 92 93
#### utools.db.get(id)
#### utools.db.remove(doc)
#### utools.db.bulkDocs(docs)
M
init  
muwoo 已提交
94

木偶 已提交
95
### ubrowser
木偶 已提交
96
可编程浏览器
M
init  
muwoo 已提交
97

木偶 已提交
98 99 100 101 102 103 104 105
```js
  const page = await utools.ubrowser.goto('https://www.baidu.com')
  await page.value('#kw', 'uTools');
  await page.click('#su');
  page.run({
      width: 600,
      height: 800,
    })
M
init  
muwoo 已提交
106 107
```

木偶 已提交
108
### 最后
木偶 已提交
109
utools过于强大,目前还没有完全实现其所有功能,不过我们会根据需要不断更新。欢迎小伙伴一起 `pr``star`
M
init  
muwoo 已提交
110

木偶 已提交
111 112 113 114

## License
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/clouDr-f2e/rubick/blob/master/LICENSE) file for details.