@@ -15,8 +15,6 @@ sidebar_position: 7
1515node_modules/ // Node.js 依赖包
1616 ├── pkg-name // 相关模块
1717 │ ├── lib/ // 工程目录
18- │ │ ├── response/ // 应用
19- │ │ ├── middleware/ // 中间件
2018 │ │ └── index.js // 入口文件
2119 │ └── package.json // 工程配置文件
2220```
@@ -27,94 +25,165 @@ node_modules/ // Node.js 依赖包
2725
2826以入口文件的目录为工程目录
2927
30- ## 配置
28+ ## 服务端
29+
30+ ### 配置
3131
3232``` json title="package.json"
3333{
34- // 官方 @alemonjs/XXX
35- // 三方 alemonjs-XXX
36- "name" : " @alemonjs/test" , // *
37- "version" : " 0.0.1" , // *
34+ "name" : " @alemonjs/test" , // * 包名
35+ "version" : " 0.0.1" , // * 版本号
3836 "author" : {
3937 "name" : " ningmengchongshui" ,
4038 "email" : " ningmengchongshui@gmail.com" ,
4139 "url" : " https://github.com/ningmengchongshui"
4240 },
43- "type" : " module" , // *
44- "main" : " lib/index.js" , // *
41+ "type" : " module" , // * 仅支持esm
42+ "main" : " lib/index.js" , // * 包入口
4543 "scripts" : {
4644 "build" : " npx lvy build"
4745 },
4846 "export" : {
49- "." : " ./lib/index.js" , // *
50- "./package" : " ./package.json" // *
47+ "." : " ./lib/index.js" , // * 包入口
48+ "./package" : " ./package.json" // * 包配置信息
5149 },
5250 "keywords" : [" alemonjs" ], // *
5351 "publishConfig" : {
5452 "registry" : " https://registry.npmjs.org" , // *
5553 "access" : " public" // *
5654 },
5755 "alemonjs" : {
58- // alemonjs 相关配置,依赖于 package 导出进行读取
56+ // 应用服务器相关配置
57+ "web" : {
58+ // html服务根目录。即 dist/index.html
59+ "root" : " dist"
60+ }
5961 }
6062 // 要发布模块,请确保没有以下内容。
6163 // "private": true,
6264 // "workspaces": ["packages/*"]
6365}
6466```
6567
66- ## 桌面
68+ ## 桌面端
6769
6870### 配置
6971
7072``` json title="package.json"
7173{
7274 "export" : {
73- "./desktop" : " ./lib/desktop.js" // 桌面扩展入口脚本
75+ "./desktop" : " ./lib/desktop.js" // * 桌面扩展入口脚本,固定导出
7476 },
7577 "alemonjs" : {
78+ // 应用服务器相关配置
79+ "web" : {
80+ // html服务根目录。即 dist/index.html
81+ "root" : " dist"
82+ },
83+ // 桌面相关配置
7684 "desktop" : {
77- // 图标(可选)
78- // 支持antd图标,如 antd.OpenAIOutlined
79- // https://ant.design/components/icon-cn
8085 "logo" : " public/logo.png" ,
81- // 指令输入框
86+ // "logo": "antd.OpenAIOutlined",
8287 "command" : [
8388 {
8489 "name" : " test" ,
85- // 图标(可选)支持antd图标
8690 "icon" : " public/logo.png" ,
8791 "command" : " open.test" // 发送指令
8892 }
8993 ],
90- // 侧边栏
9194 "sidebars" : [
9295 {
93- // 无图标则显示
94- "name" : " test" ,
95- // 图标(可选) 支持antd图标
96- "icon" : " public/logo.png" ,
97- "command" : " open.test" // 发送指令
96+ "command" : " open.test"
9897 }
9998 ],
100- // 平台(拥有此配置将无法被添加至config.value.apps)
101- "platform" : [
99+ "menus" : [
102100 {
103- "name " : " test" // --login test
101+ "command " : " open. test"
104102 }
105103 ]
106104 }
107105 }
108106}
109107```
110108
109+ ``` ts
110+ type Desktop = {
111+ // 应用基础LOGO
112+ // 支持antd图标,如 antd.OpenAIOutlined
113+ // https://ant.design/components/icon-cn
114+ logo: string
115+ // 指令输入框 - 窗体上方的指令输入框
116+ command: CommandItem []
117+ // 侧边栏应用 - webview 里的 侧边栏
118+ sidebars: CommandItem []
119+ // 菜单按钮 - 窗体的左侧导航栏
120+ menus: CommandItem []
121+ // 控件按钮 - 窗体上方,指令输入框的两侧的控件按钮
122+ controls: ControlItem []
123+ }
124+
125+ type CommandItem = {
126+ name: string // 必要的command名
127+ icon: string // 图标(可选) 支持antd图标
128+ command: string // 要执行的指令
129+ }
130+
131+ type ControlItem = {
132+ position: ' left' | ' right' // 位置。macos默认右边,windows/linux默认左边。
133+ icon: string // 图标 支持antd图标
134+ command: string // 要执行的指令
135+ }
136+ ` ` `
137+
138+ ### 指令
139+
140+ 注意command有2类约定前缀
141+
142+ #### ` view .`
143+
144+ ` view .home ` 前往首页
145+
146+ ` view .git -exp -manage ` git扩展管理
147+
148+ ` view .npm -exp -manage ` npm扩展管理
149+
150+ ` view .webview ` 应用中心
151+
152+ ` view .settings ` 设置
153+
154+ ` view .settings .about ` 设置-关于
155+
156+ ` view .settings .theme ` 设置-主题
157+
158+ ` view .settings .files ` 设置-文件
159+
160+ ` view .settings .notice ` 设置-更新日志
161+
162+ #### ` app .`
163+
164+ ` app .open .devtools ` 打开开发者工具
165+
111166### 周期
112167
113- ``` js title="package .js"
168+ ` ` ` js title =" desktop .js"
114169// 被激活的时候。
115170export const activate = context => {}
116171```
117172
173+ ``` ts title="desktop.ts"
174+ // ts
175+ import { Context } from ' @alemonjs/process'
176+ export const activate = (context : Context ) => {}
177+ ```
178+
179+ ### 通知推送
180+
181+ ``` js title="desktop.js"
182+ export const activate = context => {
183+ context .notification (' 扩展加载' )
184+ }
185+ ```
186+
118187### 渲染
119188
120189``` js title="desktop.js"
@@ -127,7 +196,7 @@ export const activate = context => {
127196 // 创建一个 webview。
128197 const sidebarWebView =
129198 context .createSidebarWebView (context)
130- // 当命令被触发的时候。
199+ // 监听指定指令的执行
131200 context .onCommand (' open.test' , () => {
132201 const dir = join (__dirname , ' assets' , ' index.html' )
133202 // 确保路径存在
@@ -138,6 +207,18 @@ export const activate = context => {
138207}
139208` ` `
140209
210+ ### 从webview到app
211+
212+ - 发送消息
213+
214+ ` ` ` js title= " index.js"
215+ const API = createDesktopAPI ()
216+ API .postMessage ({
217+ type: ' pong' ,
218+ data: ' '
219+ })
220+ ` ` `
221+
141222- 接收消息
142223
143224` ` ` js title= " desktop.js"
@@ -152,6 +233,8 @@ export const activate = context => {
152233}
153234` ` `
154235
236+ ### 从app到webview
237+
155238- 发送消息
156239
157240` ` ` js title= " desktop.js"
@@ -167,6 +250,18 @@ export const activate = context => {
167250}
168251` ` `
169252
253+ - 接收消息
254+
255+ ` ` ` js title= " index.js"
256+ const API = createDesktopAPI ()
257+
258+ API .onMessage (data => {
259+ // { type: 'ping', data: '' }
260+ })
261+ ` ` `
262+
263+ ### 主题
264+
170265- 主题变量
171266
172267` ` ` css
@@ -179,28 +274,7 @@ export const activate = context => {
179274}
180275` ` `
181276
182- ### 脚本
183-
184- - 发送消息
185-
186- ` ` ` js title= " index.js"
187- const API = createDesktopAPI ()
188-
189- API .postMessage ({
190- type: ' pong' ,
191- data: ' '
192- })
193- ` ` `
194-
195- - 接收消息
196-
197- ` ` ` js title= " index.js"
198- const API = createDesktopAPI ()
199-
200- API .onMessage (data => {
201- // { type: 'ping', data: '' }
202- })
203- ` ` `
277+ > 推荐使用 ` @alemonjs/ react- ui` ,是一组自带主题的库
204278
205279### 资源路径
206280
@@ -220,11 +294,3 @@ export const activate = context => {
220294 // 可替换 html 内部资源,确保正确加载
221295}
222296` ` `
223-
224- ### 通知推送
225-
226- ` ` ` js title= " desktop.js"
227- export const activate = context => {
228- context .notification (' 扩展加载' )
229- }
230- ` ` `
0 commit comments