Skip to content

Commit c58ec4e

Browse files
committed
add dialog for sdk
1 parent ed91406 commit c58ec4e

File tree

4 files changed

+229
-14
lines changed

4 files changed

+229
-14
lines changed

resources/lib/js/sdk.mjs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
1-
import { reactive as o, watch as d } from "vue";
2-
const i = o(window.$wujie?.props?.modelValue ?? {});
3-
d(i, (e) => {
1+
import { reactive as r, watch as p } from "vue";
2+
async function d(n) {
3+
return window.parent.electron.ipcRenderer.invoke("ipc-show-open-dialog", n);
4+
}
5+
async function w(n) {
6+
return window.parent.electron.ipcRenderer.invoke("ipc-show-save-dialog", n);
7+
}
8+
const o = r(window.$wujie?.props?.modelValue ?? {});
9+
p(o, (n) => {
410
window.$wujie.bus.$emit("update:modelValue", {
511
pluginId: window.$wujie?.props?.pluginId,
612
id: window.$wujie?.props?.editIndex,
7-
data: e
13+
data: n
814
});
915
});
10-
function p() {
11-
return i;
16+
function t() {
17+
return o;
1218
}
13-
const t = window.parent.logBus;
14-
function u(e, ...n) {
19+
const i = window.parent.logBus;
20+
function l(n, ...e) {
1521
return window.parent.electron.ipcRenderer.invoke(
1622
"ipc-plugin-exec",
1723
{ pluginId: window.$wujie?.props?.pluginId, id: window.$wujie?.props?.editIndex },
18-
e,
19-
...n
24+
n,
25+
...e
2026
);
2127
}
28+
function a(n, e) {
29+
i.on(`pluginEvent.${window.$wujie?.props?.pluginId}.${n}`, e);
30+
}
31+
function s(n, e) {
32+
i.off(`pluginEvent.${window.$wujie?.props?.pluginId}.${n}`, e);
33+
}
34+
function c(n) {
35+
i.on(`pluginError.${window.$wujie?.props?.pluginId}`, n);
36+
}
37+
function g(n) {
38+
i.off(`*pluginError.${window.$wujie?.props?.pluginId}`, n);
39+
}
2240
export {
23-
u as callServerMethod,
24-
t as eventBus,
25-
p as useData
41+
c as addPluginErrorListen,
42+
a as addPluginEventListen,
43+
l as callServerMethod,
44+
i as eventBus,
45+
g as removePluginErrorListen,
46+
s as removePluginEventListen,
47+
d as showOpenDialog,
48+
w as showSaveDialog,
49+
t as useData
2650
};
2751
//# sourceMappingURL=index.mjs.map
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// ============ 文件对话框相关类型定义 ============
2+
3+
/**
4+
* 文件过滤器,用于限制可选择的文件类型
5+
*/
6+
export interface FileFilter {
7+
/** 过滤器名称,例如 "Images" */
8+
name: string
9+
/** 文件扩展名数组,例如 ["png", "jpg"] */
10+
extensions: string[]
11+
}
12+
13+
/**
14+
* 打开文件对话框的配置选项
15+
*/
16+
export interface OpenDialogOptions {
17+
/** 对话框标题 */
18+
title?: string
19+
/** 默认路径 */
20+
defaultPath?: string
21+
/**
22+
* 确认按钮的自定义标签,留空时使用默认标签
23+
*/
24+
buttonLabel?: string
25+
/** 文件过滤器数组 */
26+
filters?: FileFilter[]
27+
/**
28+
* 对话框的功能配置
29+
* - openFile: 允许选择文件
30+
* - openDirectory: 允许选择文件夹
31+
* - multiSelections: 允许多选
32+
* - showHiddenFiles: 显示隐藏文件
33+
* - createDirectory: 允许创建新目录 (macOS)
34+
* - promptToCreate: 如果输入的路径不存在,提示创建 (Windows)
35+
* - noResolveAliases: 禁用自动别名解析 (macOS)
36+
* - treatPackageAsDirectory: 将包视为目录 (macOS)
37+
* - dontAddToRecent: 不添加到最近文档 (Windows)
38+
*/
39+
properties?: Array<
40+
| 'openFile'
41+
| 'openDirectory'
42+
| 'multiSelections'
43+
| 'showHiddenFiles'
44+
| 'createDirectory'
45+
| 'promptToCreate'
46+
| 'noResolveAliases'
47+
| 'treatPackageAsDirectory'
48+
| 'dontAddToRecent'
49+
>
50+
/**
51+
* 显示在输入框上方的消息 (仅 macOS)
52+
* @platform darwin
53+
*/
54+
message?: string
55+
/**
56+
* 创建安全作用域书签 (仅 macOS)
57+
* @platform darwin,mas
58+
*/
59+
securityScopedBookmarks?: boolean
60+
}
61+
62+
/**
63+
* 打开文件对话框的返回值
64+
*/
65+
export interface OpenDialogReturnValue {
66+
/** 对话框是否被取消 */
67+
canceled: boolean
68+
/** 用户选择的文件路径数组。如果对话框被取消,这将是一个空数组 */
69+
filePaths: string[]
70+
/**
71+
* 与 filePaths 数组匹配的 base64 编码字符串数组,包含安全作用域书签数据
72+
* 必须启用 securityScopedBookmarks 才会填充此字段 (仅 macOS)
73+
* @platform darwin,mas
74+
*/
75+
bookmarks?: string[]
76+
}
77+
78+
/**
79+
* 保存文件对话框的配置选项
80+
*/
81+
export interface SaveDialogOptions {
82+
/**
83+
* 对话框标题。在某些 Linux 桌面环境中无法显示
84+
*/
85+
title?: string
86+
/**
87+
* 默认使用的绝对目录路径、绝对文件路径或文件名
88+
*/
89+
defaultPath?: string
90+
/**
91+
* 确认按钮的自定义标签,留空时使用默认标签
92+
*/
93+
buttonLabel?: string
94+
/** 文件过滤器数组 */
95+
filters?: FileFilter[]
96+
/**
97+
* 显示在文本字段上方的消息 (仅 macOS)
98+
* @platform darwin
99+
*/
100+
message?: string
101+
/**
102+
* 显示在文件名文本字段前的自定义标签 (仅 macOS)
103+
* @platform darwin
104+
*/
105+
nameFieldLabel?: string
106+
/**
107+
* 显示标签输入框,默认为 true (仅 macOS)
108+
* @platform darwin
109+
*/
110+
showsTagField?: boolean
111+
/**
112+
* 对话框的功能配置
113+
* - showHiddenFiles: 显示隐藏文件
114+
* - createDirectory: 允许创建新目录 (macOS)
115+
* - treatPackageAsDirectory: 将包视为目录 (macOS)
116+
* - showOverwriteConfirmation: 如果文件已存在,显示覆盖确认
117+
* - dontAddToRecent: 不添加到最近文档 (Windows)
118+
*/
119+
properties?: Array<
120+
| 'showHiddenFiles'
121+
| 'createDirectory'
122+
| 'treatPackageAsDirectory'
123+
| 'showOverwriteConfirmation'
124+
| 'dontAddToRecent'
125+
>
126+
/**
127+
* 为 Mac App Store 打包时创建安全作用域书签
128+
* 如果启用此选项且文件不存在,将在选择的路径创建一个空文件 (仅 macOS)
129+
* @platform darwin,mas
130+
*/
131+
securityScopedBookmarks?: boolean
132+
}
133+
134+
/**
135+
* 保存文件对话框的返回值
136+
*/
137+
export interface SaveDialogReturnValue {
138+
/** 对话框是否被取消 */
139+
canceled: boolean
140+
/** 用户选择的文件路径。如果对话框被取消,这将是一个空字符串 */
141+
filePath: string
142+
/**
143+
* Base64 编码的字符串,包含已保存文件的安全作用域书签数据
144+
* 必须启用 securityScopedBookmarks 才会填充此字段 (仅 macOS)
145+
* @platform darwin,mas
146+
*/
147+
bookmark?: string
148+
}
149+
150+
/**
151+
* 显示打开文件对话框
152+
* @param options 对话框选项
153+
* @returns Promise,包含用户选择的文件路径和取消状态
154+
* @example
155+
* ```typescript
156+
* const result = await showOpenDialog({
157+
* title: '选择文件',
158+
* filters: [{ name: 'Images', extensions: ['jpg', 'png'] }],
159+
* properties: ['openFile', 'multiSelections']
160+
* })
161+
* if (!result.canceled) {
162+
* console.log('选择的文件:', result.filePaths)
163+
* }
164+
* ```
165+
*/
166+
export async function showOpenDialog(options: OpenDialogOptions): Promise<OpenDialogReturnValue> {
167+
return window.parent.electron.ipcRenderer.invoke('ipc-show-open-dialog', options)
168+
}
169+
170+
/**
171+
* 显示保存文件对话框
172+
* @param options 对话框选项
173+
* @returns Promise,包含用户选择的保存路径和取消状态
174+
* @example
175+
* ```typescript
176+
* const result = await showSaveDialog({
177+
* title: '保存文件',
178+
* defaultPath: 'untitled.txt',
179+
* filters: [{ name: 'Text Files', extensions: ['txt'] }]
180+
* })
181+
* if (!result.canceled) {
182+
* console.log('保存路径:', result.filePath)
183+
* }
184+
* ```
185+
*/
186+
export async function showSaveDialog(options: SaveDialogOptions): Promise<SaveDialogReturnValue> {
187+
return window.parent.electron.ipcRenderer.invoke('ipc-show-save-dialog', options)
188+
}

src/renderer/src/plugin-sdk/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { reactive, watch } from 'vue'
3+
export { showOpenDialog, showSaveDialog } from './dialog'
4+
5+
// ============ 插件数据和方法 ============
36

47
const data = reactive<any>(window.$wujie?.props?.modelValue ?? {})
58

src/renderer/src/plugin-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ecubus-pro/renderer-plugin-sdk",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "EcuBus Pro renderer plugin SDK",
55
"type": "module",
66
"module": "./dist/index.mjs",

0 commit comments

Comments
 (0)