# 插件API手册
# onPluginReady
插件应用初始化完成时触发
focusany.onPluginReady((data) => {
// data.actionName 动作名称
// data.actionMatch 动作
// data.actionMatchFiles 匹配到的文件
// data.requestId 请求ID
// data.reenter 是否重新进入,对于 singleton 的插件,当再次调用时为 true
// data.isView 是否是快捷面板
});
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# onPluginExit
插件应用退出时触发
focusany.onPluginExit(() => {
alert('插件即将退出');
});
1
2
3
2
3
# onPluginEvent
插件事件触发
// 剪切板变化
focusany.onPluginEvent('ClipboardChange', (data) => {
console.log('剪切板变化', data);
})
// 用户变化
focusany.onPluginEvent('UserChange', (data) => {
console.log('用户变化', data);
})
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# offPluginEvent
移除插件事件
focusany.offPluginEvent('ClipboardChange',cb);
focusany.offPluginEvent('UserChange',cb);
1
2
2
# offPluginEventAll
移除所有插件事件
focusany.offPluginEventAll('ClipboardChange');
focusany.offPluginEventAll('UserChange');
1
2
2
# isMainWindowShown
插件主窗口是否显示
focusany.isMainWindowShown();
1
# hideMainWindow
隐藏插件主窗口
focusany.hideMainWindow();
1
# showMainWindow
显示插件主窗口
focusany.showMainWindow();
1
# isFastPanelWindowShown
快捷面板窗口是否显示
focusany.isFastPanelWindowShown();
1
# showFastPanelWindow
显示快捷面板窗口
focusany.showFastPanelWindow();
1
# hideFastPanelWindow
隐藏快捷面板窗口
focusany.hideFastPanelWindow();
1
# setExpendHeight
设置插件的高度
focusany.setExpendHeight(300);
1
# setSubInput
设置输入框监听
focusany.setSubInput((keywords) => {
console.log('输入变化', keywords);
}, '请输入关键字', true, true);
1
2
3
2
3
# removeSubInput
移除输入框监听
focusany.removeSubInput();
1
# setSubInputValue
获取子输入框的值
focusany.setSubInputValue('测试');
1
# subInputBlur
子输入框失去焦点
focusany.subInputBlur();
1
# getPluginRoot
获取插件根目录
focusany.getPluginRoot();
1
# getPluginConfig
获取插件配置文件 config.json
focusany.getPluginConfig();
1
# getPluginInfo
获取插件信息
focusany.getPluginInfo();
1
# getPluginEnv
获取插件环境
// dev 或 prod
focusany.getPluginEnv();
1
2
2
# getQuery
获取插件查询信息
focusany.onPluginReady((data) => {
const query = focusany.getQuery(data.requestId);
});
1
2
3
2
3
# createBrowserWindow
创建窗口
focusany.createBrowserWindow('path/to/page.html', {
width: 800,
height: 600,
});
1
2
3
4
2
3
4
# outPlugin
关闭插件
focusany.outPlugin();
1
# isDarkColors
是否是暗色主题
focusany.isDarkColors();
1
# showUserLogin
显示用户登录窗口
focusany.showUserLogin();
1
# getUser
获取用户
const user = focusany.getUser();
// user.isLogin 是否登录
// user.avatar 头像
// user.nickname 昵称
// user.vipFlag 会员标识
// user.deviceCode 设备ID
// user.openId 用户OpenId,每个用户对每个插件的标识唯一
1
2
3
4
5
6
7
2
3
4
5
6
7
# getUserAccessToken
获取用户访问令牌
const accessToken = await focusany.getUserAccessToken();
// accessToken.token 访问令牌
// accessToken.expireAt 过期时间
1
2
3
2
3
# listGoods
获取商品列表
const goods = await focusany.listGoods();
1
结果示例
[
{
"id": "goodsId",
"title": "商品名称",
"cover": "商品封面",
// 商品价格类型 fixed: 固定价格,dynamic: 动态价格
"priceType": "fixed",
// 固定价格
"fixedPrice": "0.01",
"description": "商品描述"
}
]
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# openGoodsPayment
创建订单并显示
const result = await focusany.openGoodsPayment({
// 插件商品ID
goodsId: 'xxx',
// 插件商品价格,固定价格商品无需传入,动态价格商品需传入价格,如 0.01
price: '0.01',
// 第三方订单号,字符串,最大长度 64 字符
outOrderId: 'xxxx',
// 参数数据,长度不超过 200 字符
outParam: 'xxxx',
});
// result.paySuccess 是否支付成功,注意,支付是否成功需要依赖服务端的回调,此处仅作参考
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# queryGoodsOrders
查询插件商品订单
const result = focusany.queryGoodsOrders({
// 插件商品ID,可选
goodsId: 'xxx',
// 分页页码,从 1 开始,可选
page: 1,
// 分页大小,可选,默认是 10
pageSize: 10,
})
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
结果示例
{
"total": 1,
"page": 1,
"records": [
{
// 订单号
"id": "xxxx",
// 插件商品ID
"goodsId": "xxx",
// 状态 Paid: 已支付, Unpaid: 未支付
"status": "Paid"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# setAction
动态设置插件动作
设置一个动作
focusany.setAction({
name: 'actionName',
title: '动作名称',
icon: 'icon',
})
1
2
3
4
5
2
3
4
5
设置多个动作
focusany.setAction([
{
name: 'actionName1',
title: '动作名称1',
icon: 'icon1',
},
{
name: 'actionName2',
title: '动作名称2',
icon: 'icon2',
},
]);
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# removeAction
移除插件动作
focusany.removeAction('actionName');
1
# getActions
获取插件动作
focusany.getActions();
1
示例结果
[
{
"fullName": "完整名称",
"name": "actionName",
"title": "动作名称",
"icon": "icon",
"type": "web",
}
]
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# redirect
打开插件动作
focusany.redirect('actionName')
1
# showToast
显示提示
focusany.showToast('提示内容', { duration: 3000, status: 'info' });
1
# showNotification
显示通知
// 显示通知
focusany.showNotification('通知内容');
// 显示通知,点击执行动作
focusany.showNotification('通知内容','clickActionName');
1
2
3
4
2
3
4
# showMessageBox
显示消息框
focusany.showMessageBox('消息内容', { title: '消息标题', yes: '确定', no: '取消' });
1
# showOpenDialog
打开文件选择框
const result = focusany.showOpenDialog({
title:'选择文件',
});
1
2
3
2
3
# showSaveDialog
打开文件保存框
const result = focusany.showSaveDialog({
title:'保存文件',
});
1
2
3
2
3
# screenCapture
截图
focusany.screenCapture((imgBase64) => {
console.log('截图文件',imgBase64);
});
1
2
3
2
3
# getNativeId
获取设备ID
focusany.getNativeId();
1
# getAppVersion
获取软件版本
focusany.getAppVersion();
1
# getPath
获取路径
// 获取用户目录
focusany.getPath('home');
// 获取应用数据目录
focusany.getPath('appData');
// 获取用户数据目录
focusany.getPath('userData');
// 获取临时目录
focusany.getPath('temp');
// 获取应用目录
focusany.getPath('exe');
// 获取桌面目录
focusany.getPath('desktop');
// 获取文档目录
focusany.getPath('documents');
// 获取下载目录
focusany.getPath('downloads');
// 获取音乐目录
focusany.getPath('music');
// 获取图片目录
focusany.getPath('pictures');
// 获取视频目录
focusany.getPath('videos');
// 获取日志目录
focusany.getPath('logs');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# getFileIcon
获取文件图标
focusany.getFileIcon('path.txt');
1
# copyFile
复制文件到剪贴板
focusany.copyFile('/path/to/file.txt');
1
# copyImage
复制图片到剪贴板
focusany.copyImage('/path/to/image.png');
1
# copyText
复制文本到剪贴板
focusany.copyText('text');
1
# getClipboardText
获取剪贴板文本
// 输出剪贴板文本
const result = focusany.getClipboardText();
1
2
2
# getClipboardImage
获取剪贴板图片
// 输出图片的 base64 编码
const result = focusany.getClipboardImage();
1
2
2
# getClipboardFiles
获取剪贴板文件
// 输出剪贴板文件
const result = focusany.getClipboardFiles();
1
2
2
结果示例
[
{
"name": "文件名",
"isDirectory": false,
"isFile": true,
"path": "文件路径",
"fileExt": "文件扩展名",
}
]
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# shellOpenPath
使用默认的应用打开文件
focusany.shellOpenPath('/path/to/file.doc');
1
# shellShowItemInFolder
在文件管理器中显示文件
focusany.shellShowItemInFolder('/path/to/file.txt');
1
# shellOpenExternal
打开链接
focusany.shellOpenExternal('https://focusany.com');
1
# shellBeep
播放提示音
focusany.shellBeep();
1
# simulateKeyboardTap
模拟键盘按键
focusany.simulateKeyboardTap('key', ['ctrl', 'shift']);
1
# getCursorScreenPoint
获取鼠标位置
// 输出 {x: 100, y: 200}
const result = focusany.getCursorScreenPoint();
1
2
2
# getDisplayNearestPoint
获取显示器
const result = focusany.getDisplayNearestPoint(100, 200);
1
输出示例
{
"id": "显示器ID",
"bounds": {
"x": 0,
"y": 0,
"width": 1920,
"height": 1080
},
"workArea": {
"x": 0,
"y": 0,
"width": 1920,
"height": 1080
},
"scaleFactor": 1.0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# isMacOs
是否是MacOS
focusany.isMacOs();
1
# isWindows
是否是Windows
focusany.isWindows();
1
# isLinux
是否是Linux
focusany.isLinux();
1
# getPlatformArch
获取平台架构
// x86 arm64 null
focusany.getPlatformArch();
1
2
2
# sendBackendEvent
发送后端事件
// 发送事件
focusany.sendBackendEvent('event', { data }, { timeout: 3000 });
// 发送事件并等待响应
const result = await focusany.sendBackendEvent('event', { data }, { timeout: 3000 });
1
2
3
4
2
3
4
# db
数据库操作
# db.put
添加文档
focusany.db.put(doc);
1
# db.get
获取文档
focusany.db.get(id);
1
# db.remove
删除文档
focusany.db.remove(doc);
1
# db.bulkDocs
批量添加文档
focusany.db.bulkDocs(docs);
1
# db.allDocs
批量获取文档
focusany.db.allDocs(key);
1
# db.postAttachment
保存附件
focusany.db.postAttachment(docId, attachment, type);
1
# db.getAttachment
获取附件
focusany.db.getAttachment(docId);
1
# db.getAttachmentType
获取附件类型
focusany.db.getAttachmentType(docId);
1
# dbStorage
本地存储
# dbStorage.setItem
设置存储
focusany.dbStorage.setItem(key, value);
1
# dbStorage.getItem
获取存储
focusany.dbStorage.getItem(key);
1
# dbStorage.removeItem
移除存储
focusany.dbStorage.removeItem(key);
1
# view
快捷面板
# view.setHeight
设置快捷面板当前插件渲染区域的高度
focusany.view.setHeight(300);
1
# view.getHeight
获取快捷面板当前插件渲染区域的高度
focusany.getHeight.getHeight();
1
# detach
分离窗口
# detach.setTitle
设置分离窗口的标题
focusany.detach.setTitle('标题');
1
# detach.setPosition
设置分离窗口的位置
// 可选位置 center, right-bottom, left-top, right-top, left-bottom
focusany.detach.setPosition('center');
1
2
2
# detach.setAlwaysOnTop
设置分离窗口是否置顶
focusany.detach.setAlwaysOnTop(true);
1
# detach.setSize
设置分离窗口的大小
focusany.detach.setSize(800, 600);
1
# util
工具
# util.randomString
生成随机字符串
focusany.util.randomString(10);
1
# util.bufferToBase64
Buffer 转 Base64
focusany.util.bufferToBase64(buffer);
1
# util.datetimeString
获取当前时间戳字符串
focusany.util.datetimeString();
1
# util.base64Encode
数据转 Base64
focusany.util.base64Encode(data);
1
# util.base64Decode
Base64 转数据
focusany.util.base64Decode(data);
1
# util.md5
MD5 摘要
focusany.util.md5(data);
1
# util.save
保存文件
// 保存Base64
focusany.util.save('filename.png', 'xxxx', { isBase64: true });
// 保存Buffer
focusany.util.save('filename.png', buffer);
1
2
3
4
2
3
4