@becrafter/prompt-manager 0.1.12 → 0.1.15
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/app/desktop/assets/app.1.png +0 -0
- package/app/desktop/assets/app.png +0 -0
- package/app/desktop/assets/icons/icon.icns +0 -0
- package/app/desktop/assets/icons/icon.ico +0 -0
- package/app/desktop/assets/icons/icon.png +0 -0
- package/app/desktop/assets/icons/tray.png +0 -0
- package/app/desktop/assets/templates/about.html +147 -0
- package/app/desktop/assets/tray.1.png +0 -0
- package/app/desktop/assets/tray.png +0 -0
- package/app/desktop/docs/ASSETS_PLANNING.md +351 -0
- package/app/desktop/docs/REFACTORING_SUMMARY.md +205 -0
- package/app/desktop/main.js +340 -0
- package/app/desktop/package-lock.json +6912 -0
- package/app/desktop/package.json +119 -0
- package/app/desktop/preload.js +7 -0
- package/app/desktop/src/core/error-handler.js +108 -0
- package/app/desktop/src/core/event-emitter.js +84 -0
- package/app/desktop/src/core/logger.js +130 -0
- package/app/desktop/src/core/state-manager.js +125 -0
- package/app/desktop/src/services/module-loader.js +330 -0
- package/app/desktop/src/services/runtime-manager.js +398 -0
- package/app/desktop/src/services/service-manager.js +210 -0
- package/app/desktop/src/services/update-manager.js +267 -0
- package/app/desktop/src/ui/about-dialog-manager.js +208 -0
- package/app/desktop/src/ui/admin-window-manager.js +757 -0
- package/app/desktop/src/ui/splash-manager.js +253 -0
- package/app/desktop/src/ui/tray-manager.js +186 -0
- package/app/desktop/src/utils/icon-manager.js +133 -0
- package/app/desktop/src/utils/path-utils.js +58 -0
- package/app/desktop/src/utils/resource-paths.js +49 -0
- package/app/desktop/src/utils/resource-sync.js +260 -0
- package/app/desktop/src/utils/runtime-sync.js +241 -0
- package/app/desktop/src/utils/self-check.js +288 -0
- package/app/desktop/src/utils/template-renderer.js +284 -0
- package/app/desktop/src/utils/version-utils.js +59 -0
- package/env.example +1 -1
- package/examples/prompts/developer/code-review.yaml +32 -0
- package/examples/prompts/developer/code_refactoring.yaml +31 -0
- package/examples/prompts/developer/doc-generator.yaml +36 -0
- package/examples/prompts/developer/error-code-fixer.yaml +35 -0
- package/examples/prompts/engineer/engineer-professional.yaml +92 -0
- package/examples/prompts/engineer/laowang-engineer.yaml +132 -0
- package/examples/prompts/engineer/nekomata-engineer.yaml +123 -0
- package/examples/prompts/engineer/ojousama-engineer.yaml +124 -0
- package/examples/prompts/generator/gen_3d_edu_webpage_html.yaml +117 -0
- package/examples/prompts/generator/gen_3d_webpage_html.yaml +75 -0
- package/examples/prompts/generator/gen_bento_grid_html.yaml +112 -0
- package/examples/prompts/generator/gen_html_web_page.yaml +88 -0
- package/examples/prompts/generator/gen_knowledge_card_html.yaml +83 -0
- package/examples/prompts/generator/gen_magazine_card_html.yaml +82 -0
- package/examples/prompts/generator/gen_mimeng_headline_title.yaml +71 -0
- package/examples/prompts/generator/gen_podcast_script.yaml +69 -0
- package/examples/prompts/generator/gen_prd_prototype_html.yaml +175 -0
- package/examples/prompts/generator/gen_summarize.yaml +157 -0
- package/examples/prompts/generator/gen_title.yaml +119 -0
- package/examples/prompts/generator/others/api_documentation.yaml +32 -0
- package/examples/prompts/generator/others/build_mcp_server.yaml +26 -0
- package/examples/prompts/generator/others/project_architecture.yaml +31 -0
- package/examples/prompts/generator/others/test_case_generator.yaml +30 -0
- package/examples/prompts/generator/others/writing_assistant.yaml +72 -0
- package/examples/prompts/recommend/human_3-0_growth_diagnostic_coach_prompt.yaml +105 -0
- package/examples/prompts/workflow/sixstep-workflow.yaml +192 -0
- package/package.json +13 -1
- package/packages/server/.eslintrc.js +70 -0
- package/packages/server/.husky/pre-commit +8 -0
- package/packages/server/.husky/pre-push +8 -0
- package/packages/server/.prettierrc +14 -0
- package/packages/server/dev-server.js +90 -0
- package/packages/server/jsdoc.conf.json +39 -0
- package/packages/server/playwright.config.js +62 -0
- package/packages/server/scripts/generate-docs.js +300 -0
- package/packages/server/server.js +1 -0
- package/packages/server/services/TerminalService.js +84 -11
- package/packages/server/tests/e2e/terminal-e2e.test.js +315 -0
- package/packages/server/tests/integration/terminal-websocket.test.js +372 -0
- package/packages/server/tests/integration/tools.test.js +264 -0
- package/packages/server/tests/setup.js +45 -0
- package/packages/server/tests/unit/TerminalService.test.js +410 -0
- package/packages/server/tests/unit/WebSocketService.test.js +403 -0
- package/packages/server/tests/unit/core.test.js +94 -0
- package/packages/server/typedoc.json +52 -0
- package/packages/server/utils/config.js +1 -1
- package/packages/server/utils/util.js +59 -5
- package/packages/server/vitest.config.js +74 -0
- package/packages/web/0.d1c5a72339dfc32ad86a.js +1 -0
- package/packages/web/112.8807b976372b2b0541a8.js +1 -0
- package/packages/web/130.584c7e365da413f5d9be.js +1 -0
- package/packages/web/142.72c985bc29720f975cca.js +1 -0
- package/packages/web/165.a05fc53bf84d18db36b8.js +2 -0
- package/packages/web/165.a05fc53bf84d18db36b8.js.LICENSE.txt +9 -0
- package/packages/web/203.724ab9f717b80554c397.js +1 -0
- package/packages/web/241.bf941d4f02866795f64a.js +1 -0
- package/packages/web/249.54cfb224af63f5f5ec55.js +1 -0
- package/packages/web/291.6df35042f8f296fca7cd.js +1 -0
- package/packages/web/319.2fab900a31b29873f666.js +1 -0
- package/packages/web/32.c78d866281995ec33a7b.js +1 -0
- package/packages/web/325.9ca297d0f73f38468ce9.js +1 -0
- package/packages/web/366.2f9b48fdbf8eee039e57.js +1 -0
- package/packages/web/378.6be08c612cd5a3ef97dc.js +1 -0
- package/packages/web/393.7a2f817515c5e90623d7.js +1 -0
- package/packages/web/412.062df5f732d5ba203415.js +1 -0
- package/packages/web/426.08656fef4918b3fb19ad.js +1 -0
- package/packages/web/465.2be8018327130a3bd798.js +1 -0
- package/packages/web/48.8ca96fc93667a715e67a.js +1 -0
- package/packages/web/480.44c1f1a2927486ac3d4f.js +1 -0
- package/packages/web/489.e041a8d0db15dc96d607.js +1 -0
- package/packages/web/490.9ffb26c907de020d671b.js +1 -0
- package/packages/web/492.58781369e348d91fc06a.js +1 -0
- package/packages/web/495.ed63e99791a87167c6b3.js +1 -0
- package/packages/web/510.4cc07ab7d30d5c1cd17f.js +1 -0
- package/packages/web/543.3af155ed4fa237664308.js +1 -0
- package/packages/web/567.f04ab60f8e2c2fb0745a.js +1 -0
- package/packages/web/592.f3ad085fa9c1849daa06.js +1 -0
- package/packages/web/616.b03fb801b3433b17750f.js +1 -0
- package/packages/web/617.d88def54921d2c4dc44c.js +1 -0
- package/packages/web/641.d30787d674f548928261.js +1 -0
- package/packages/web/672.5269c8399fa42a5af95d.js +1 -0
- package/packages/web/731.97cab92b71811c502bda.js +1 -0
- package/packages/web/746.3947c6f0235407e420fb.js +1 -0
- package/packages/web/756.a53233b3f3913900d5ac.js +1 -0
- package/packages/web/77.68801af593a28a631fbf.js +1 -0
- package/packages/web/802.53b2bff3cf2a69f7b80c.js +1 -0
- package/packages/web/815.b6dfab82265f56c7e046.js +1 -0
- package/packages/web/821.f5a13e5c735aac244eb9.js +1 -0
- package/packages/web/846.b9bf97d5f559270675ce.js +1 -0
- package/packages/web/869.7c10403f500e6201407f.js +1 -0
- package/packages/web/885.135050364f99e6924fb5.js +1 -0
- package/packages/web/901.fd5aeb9df630609a2b43.js +1 -0
- package/packages/web/928.f67e590de3caa4daa3ae.js +1 -0
- package/packages/web/955.d833403521ba4dd567ee.js +1 -0
- package/packages/web/981.a45cb745cf424044c8c8.js +1 -0
- package/packages/web/992.645320b60c74c8787482.js +1 -0
- package/packages/web/996.ed9a963dc9e7439eca9a.js +1 -0
- package/packages/web/css/codemirror-theme_xq-light.css +43 -0
- package/packages/web/css/codemirror.css +344 -0
- package/packages/web/css/main.3b61356b384d2f11f47f.css +7268 -0
- package/packages/web/index.html +3 -0
- package/packages/web/main.77c2c4b553ca3fac223b.js +2 -0
- package/packages/web/main.77c2c4b553ca3fac223b.js.LICENSE.txt +3 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>关于 Prompt Manager</title>
|
|
6
|
+
<style>
|
|
7
|
+
/* 支持纵向滚动但隐藏滚动条 */
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
12
|
+
background: linear-gradient(135deg, #ffffff 0%, #ffffff 100%);
|
|
13
|
+
color: #333;
|
|
14
|
+
min-height: 100vh;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
/* 支持纵向滚动 */
|
|
20
|
+
overflow-x: hidden;
|
|
21
|
+
overflow-y: auto;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* 针对WebKit浏览器隐藏滚动条 */
|
|
25
|
+
body::-webkit-scrollbar {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* 针对Firefox浏览器隐藏滚动条 */
|
|
30
|
+
body {
|
|
31
|
+
scrollbar-width: none;
|
|
32
|
+
-ms-overflow-style: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.container {
|
|
36
|
+
background: white;
|
|
37
|
+
border-radius: 12px;
|
|
38
|
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
|
|
39
|
+
padding: 30px;
|
|
40
|
+
width: 320px;
|
|
41
|
+
text-align: center;
|
|
42
|
+
transition: transform 0.3s ease;
|
|
43
|
+
/* 防止容器内容溢出 */
|
|
44
|
+
max-width: 100%;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.container:hover {
|
|
48
|
+
transform: translateY(-2px);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.logo {
|
|
52
|
+
width: 64px;
|
|
53
|
+
height: 64px;
|
|
54
|
+
/* background: linear-gradient(135deg, #dcdbdb 0%, #dcdbdb 100%); */
|
|
55
|
+
border-radius: 6px;
|
|
56
|
+
border: 1px solid #ccc;
|
|
57
|
+
margin: 0 auto 15px;
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
font-size: 28px;
|
|
62
|
+
color: white;
|
|
63
|
+
font-weight: bold;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.version-info {
|
|
67
|
+
background: #f8f9fa;
|
|
68
|
+
border-radius: 8px;
|
|
69
|
+
padding: 15px;
|
|
70
|
+
margin-bottom: 20px;
|
|
71
|
+
text-align: left;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.version-item {
|
|
75
|
+
display: flex;
|
|
76
|
+
justify-content: space-between;
|
|
77
|
+
margin-bottom: 8px;
|
|
78
|
+
font-size: 14px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.version-item:last-child {
|
|
82
|
+
margin-bottom: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.label {
|
|
86
|
+
color: #7f8c8d;
|
|
87
|
+
font-weight: 500;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.value {
|
|
91
|
+
color: #2c3e50;
|
|
92
|
+
font-weight: 500;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.notification {
|
|
96
|
+
background: #e3f2fd;
|
|
97
|
+
border-left: 4px solid #2196f3;
|
|
98
|
+
padding: 12px;
|
|
99
|
+
border-radius: 0 8px 8px 0;
|
|
100
|
+
margin: 15px 0;
|
|
101
|
+
text-align: left;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.notification-title {
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
color: #1976d2;
|
|
107
|
+
margin: 0 0 5px 0;
|
|
108
|
+
font-size: 13px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.notification-content {
|
|
112
|
+
font-size: 12px;
|
|
113
|
+
color: #555;
|
|
114
|
+
margin: 0;
|
|
115
|
+
}
|
|
116
|
+
</style>
|
|
117
|
+
</head>
|
|
118
|
+
<body>
|
|
119
|
+
<div class="container">
|
|
120
|
+
<div class="logo">
|
|
121
|
+
<img src="data:image/png;base64,{{logoData}}" alt="Prompt Server Logo" width="64" height="64">
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div class="version-info">
|
|
125
|
+
<div class="version-item">
|
|
126
|
+
<span class="label">服务版本:</span>
|
|
127
|
+
<span class="value">{{version}}</span>
|
|
128
|
+
</div>
|
|
129
|
+
<div class="version-item">
|
|
130
|
+
<span class="label">Electron:</span>
|
|
131
|
+
<span class="value">{{electronVersion}}</span>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="version-item">
|
|
134
|
+
<span class="label">Node.js:</span>
|
|
135
|
+
<span class="value">{{nodeVersion}}</span>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
{{#if debugLogEnabled}}
|
|
140
|
+
<div class="notification">
|
|
141
|
+
<div class="notification-title">调试日志已开启</div>
|
|
142
|
+
<div class="notification-content">日志文件路径: {{logFilePath}}</div>
|
|
143
|
+
</div>
|
|
144
|
+
{{/if}}
|
|
145
|
+
</div>
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# HTML Assets 资源文件规划
|
|
2
|
+
|
|
3
|
+
## 当前结构
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
app/desktop/
|
|
7
|
+
├── assets/
|
|
8
|
+
│ ├── icon_16x16.png
|
|
9
|
+
│ ├── icon_24x24.png
|
|
10
|
+
│ ├── icon_32x32.png
|
|
11
|
+
│ ├── icon_48x48.png
|
|
12
|
+
│ ├── icon_64x64.png
|
|
13
|
+
│ ├── icon_96x96.png
|
|
14
|
+
│ ├── icon_128x128.png
|
|
15
|
+
│ ├── icon_256x256.png
|
|
16
|
+
│ ├── icon_512x512.png
|
|
17
|
+
│ ├── icon_1024x1024.png
|
|
18
|
+
│ ├── icon.png
|
|
19
|
+
│ ├── icon.ico
|
|
20
|
+
│ └── icon.icns
|
|
21
|
+
├── src/
|
|
22
|
+
│ ├── state-manager.js
|
|
23
|
+
│ ├── logger.js
|
|
24
|
+
│ ├── error-handler.js
|
|
25
|
+
│ ├── runtime-manager.js
|
|
26
|
+
│ ├── module-loader.js
|
|
27
|
+
│ ├── service-manager.js
|
|
28
|
+
│ ├── tray-manager.js
|
|
29
|
+
│ ├── update-manager.js
|
|
30
|
+
│ └── about-dialog-manager.js
|
|
31
|
+
├── about.html
|
|
32
|
+
├── preload.js
|
|
33
|
+
├── package.json
|
|
34
|
+
└── main.js
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 推荐重构结构
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
app/desktop/
|
|
41
|
+
├── assets/
|
|
42
|
+
│ ├── icons/ # 图标资源
|
|
43
|
+
│ │ ├── icon_16x16.png
|
|
44
|
+
│ │ ├── icon_24x24.png
|
|
45
|
+
│ │ ├── icon_32x32.png
|
|
46
|
+
│ │ ├── icon_48x48.png
|
|
47
|
+
│ │ ├── icon_64x64.png
|
|
48
|
+
│ │ ├── icon_96x96.png
|
|
49
|
+
│ │ ├── icon_128x128.png
|
|
50
|
+
│ │ ├── icon_256x256.png
|
|
51
|
+
│ │ ├── icon_512x512.png
|
|
52
|
+
│ │ ├── icon_1024x1024.png
|
|
53
|
+
│ │ ├── icon.png
|
|
54
|
+
│ │ ├── icon.ico
|
|
55
|
+
│ │ └── icon.icns
|
|
56
|
+
│ └── templates/ # HTML模板
|
|
57
|
+
│ ├── about.html # 关于页面模板
|
|
58
|
+
│ ├── update.html # 更新页面模板(未来使用)
|
|
59
|
+
│ └── error.html # 错误页面模板(未来使用)
|
|
60
|
+
├── src/
|
|
61
|
+
│ ├── core/ # 核心管理器
|
|
62
|
+
│ │ ├── state-manager.js
|
|
63
|
+
│ │ ├── logger.js
|
|
64
|
+
│ │ └── error-handler.js
|
|
65
|
+
│ ├── services/ # 服务层
|
|
66
|
+
│ │ ├── runtime-manager.js
|
|
67
|
+
│ │ ├── module-loader.js
|
|
68
|
+
│ │ ├── service-manager.js
|
|
69
|
+
│ │ └── update-manager.js
|
|
70
|
+
│ ├── ui/ # UI层
|
|
71
|
+
│ │ ├── tray-manager.js
|
|
72
|
+
│ │ ├── about-dialog-manager.js
|
|
73
|
+
│ │ └── window-manager.js # 窗口管理(未来使用)
|
|
74
|
+
│ └── utils/ # 工具类
|
|
75
|
+
│ ├── version-utils.js # 版本比较工具
|
|
76
|
+
│ ├── path-utils.js # 路径工具
|
|
77
|
+
│ └── template-renderer.js # 模板渲染工具
|
|
78
|
+
├── preload.js
|
|
79
|
+
├── package.json
|
|
80
|
+
└── main.js
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## HTML Assets 管理策略
|
|
84
|
+
|
|
85
|
+
### 1. 模板文件结构
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<!-- assets/templates/about.html -->
|
|
89
|
+
<!DOCTYPE html>
|
|
90
|
+
<html>
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="UTF-8">
|
|
93
|
+
<title>{{title}}</title>
|
|
94
|
+
<style>
|
|
95
|
+
/* 内联样式,减少外部依赖 */
|
|
96
|
+
{{styles}}
|
|
97
|
+
</style>
|
|
98
|
+
</head>
|
|
99
|
+
<body>
|
|
100
|
+
<div class="container">
|
|
101
|
+
<div class="logo">
|
|
102
|
+
<img src="data:image/png;base64,{{logoData}}" alt="{{appName}}" width="64" height="64">
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div class="version-info">
|
|
106
|
+
<div class="version-item">
|
|
107
|
+
<span class="label">服务版本:</span>
|
|
108
|
+
<span class="value">{{version}}</span>
|
|
109
|
+
</div>
|
|
110
|
+
<div class="version-item">
|
|
111
|
+
<span class="label">Electron:</span>
|
|
112
|
+
<span class="value">{{electronVersion}}</span>
|
|
113
|
+
</div>
|
|
114
|
+
<div class="version-item">
|
|
115
|
+
<span class="label">Node.js:</span>
|
|
116
|
+
<span class="value">{{nodeVersion}}</span>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
{{#if debugLogEnabled}}
|
|
121
|
+
<div class="notification">
|
|
122
|
+
<div class="notification-title">调试日志已开启</div>
|
|
123
|
+
<div class="notification-content">日志文件路径: {{logFilePath}}</div>
|
|
124
|
+
</div>
|
|
125
|
+
{{/if}}
|
|
126
|
+
|
|
127
|
+
<div class="click-hint">
|
|
128
|
+
连续点击此窗口 {{clickCount}} 次可{{#if debugLogEnabled}}关闭{{else}}开启{{/if}}调试日志
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<script>
|
|
133
|
+
// 点击事件处理
|
|
134
|
+
document.addEventListener('click', (event) => {
|
|
135
|
+
const currentTime = Date.now();
|
|
136
|
+
|
|
137
|
+
if (window.electronAPI) {
|
|
138
|
+
window.electronAPI.sendAboutWindowClick({
|
|
139
|
+
currentTime: currentTime
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
</script>
|
|
144
|
+
</body>
|
|
145
|
+
</html>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 2. 模板渲染工具
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// src/utils/template-renderer.js
|
|
152
|
+
class TemplateRenderer {
|
|
153
|
+
constructor() {
|
|
154
|
+
this.templates = new Map();
|
|
155
|
+
this.loadTemplates();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
loadTemplates() {
|
|
159
|
+
const templatesDir = path.join(__dirname, '..', '..', 'assets', 'templates');
|
|
160
|
+
|
|
161
|
+
// 加载所有模板文件
|
|
162
|
+
const templateFiles = fs.readdirSync(templatesDir);
|
|
163
|
+
templateFiles.forEach(file => {
|
|
164
|
+
if (file.endsWith('.html')) {
|
|
165
|
+
const templateName = path.basename(file, '.html');
|
|
166
|
+
const templatePath = path.join(templatesDir, file);
|
|
167
|
+
this.templates.set(templateName, fs.readFileSync(templatePath, 'utf8'));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
render(templateName, data) {
|
|
173
|
+
let template = this.templates.get(templateName);
|
|
174
|
+
if (!template) {
|
|
175
|
+
throw new Error(`Template not found: ${templateName}`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 简单的模板替换逻辑
|
|
179
|
+
// 支持 {{variable}} 和 {{#if condition}}...{{/if}}
|
|
180
|
+
return this.processTemplate(template, data);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
processTemplate(template, data) {
|
|
184
|
+
// 处理条件语句
|
|
185
|
+
template = this.processConditionals(template, data);
|
|
186
|
+
|
|
187
|
+
// 处理变量替换
|
|
188
|
+
template = this.processVariables(template, data);
|
|
189
|
+
|
|
190
|
+
return template;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
processConditionals(template, data) {
|
|
194
|
+
// 处理 {{#if condition}}...{{/if}}
|
|
195
|
+
const ifRegex = /\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g;
|
|
196
|
+
return template.replace(ifRegex, (match, condition, content) => {
|
|
197
|
+
return data[condition] ? content : '';
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
processVariables(template, data) {
|
|
202
|
+
// 处理 {{variable}}
|
|
203
|
+
const varRegex = /\{\{(\w+)\}\}/g;
|
|
204
|
+
return template.replace(varRegex, (match, variable) => {
|
|
205
|
+
return data[variable] || '';
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 3. 图标管理器
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
// src/utils/icon-manager.js
|
|
215
|
+
class IconManager {
|
|
216
|
+
constructor() {
|
|
217
|
+
this.iconCache = new Map();
|
|
218
|
+
this.iconPaths = this.getIconPaths();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
getIconPaths() {
|
|
222
|
+
const basePath = path.join(__dirname, '..', '..', 'assets', 'icons');
|
|
223
|
+
return {
|
|
224
|
+
'16': path.join(basePath, 'icon_16x16.png'),
|
|
225
|
+
'24': path.join(basePath, 'icon_24x24.png'),
|
|
226
|
+
'32': path.join(basePath, 'icon_32x32.png'),
|
|
227
|
+
'48': path.join(basePath, 'icon_48x48.png'),
|
|
228
|
+
'64': path.join(basePath, 'icon_64x64.png'),
|
|
229
|
+
'96': path.join(basePath, 'icon_96x96.png'),
|
|
230
|
+
'128': path.join(basePath, 'icon_128x128.png'),
|
|
231
|
+
'256': path.join(basePath, 'icon_256x256.png'),
|
|
232
|
+
'512': path.join(basePath, 'icon_512x512.png'),
|
|
233
|
+
'1024': path.join(basePath, 'icon_1024x1024.png'),
|
|
234
|
+
'default': path.join(basePath, 'icon.png'),
|
|
235
|
+
'ico': path.join(basePath, 'icon.ico'),
|
|
236
|
+
'icns': path.join(basePath, 'icon.icns')
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
getIcon(size = 'default') {
|
|
241
|
+
if (this.iconCache.has(size)) {
|
|
242
|
+
return this.iconCache.get(size);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const iconPath = this.iconPaths[size];
|
|
246
|
+
if (!iconPath || !fs.existsSync(iconPath)) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const icon = nativeImage.createFromPath(iconPath);
|
|
251
|
+
this.iconCache.set(size, icon);
|
|
252
|
+
return icon;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
getTrayIcon() {
|
|
256
|
+
const platform = process.platform;
|
|
257
|
+
let iconSize = '16';
|
|
258
|
+
|
|
259
|
+
if (platform === 'darwin') {
|
|
260
|
+
iconSize = '18';
|
|
261
|
+
} else if (platform === 'win32') {
|
|
262
|
+
iconSize = '16';
|
|
263
|
+
} else {
|
|
264
|
+
iconSize = '24';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return this.getIcon(iconSize) || this.getIcon('default');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
getAboutDialogIcon() {
|
|
271
|
+
return this.getIcon('64') || this.getIcon('default');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
clearCache() {
|
|
275
|
+
this.iconCache.clear();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## 资源文件使用规范
|
|
281
|
+
|
|
282
|
+
### 1. 图标使用
|
|
283
|
+
```javascript
|
|
284
|
+
// 在 TrayManager 中使用
|
|
285
|
+
const iconManager = new IconManager();
|
|
286
|
+
const trayIcon = iconManager.getTrayIcon();
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 2. 模板使用
|
|
290
|
+
```javascript
|
|
291
|
+
// 在 AboutDialogManager 中使用
|
|
292
|
+
const templateRenderer = new TemplateRenderer();
|
|
293
|
+
const htmlContent = templateRenderer.render('about', {
|
|
294
|
+
version: '1.0.0',
|
|
295
|
+
electronVersion: process.versions.electron,
|
|
296
|
+
nodeVersion: process.versions.node,
|
|
297
|
+
debugLogEnabled: false,
|
|
298
|
+
clickCount: 3,
|
|
299
|
+
logFilePath: '/path/to/log'
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 3. 资源路径管理
|
|
304
|
+
```javascript
|
|
305
|
+
// 集中管理所有资源路径
|
|
306
|
+
const ResourcePaths = {
|
|
307
|
+
icons: {
|
|
308
|
+
tray: path.join(__dirname, 'assets', 'icons', 'icon_16x16.png'),
|
|
309
|
+
about: path.join(__dirname, 'assets', 'icons', 'icon_64x64.png'),
|
|
310
|
+
main: path.join(__dirname, 'assets', 'icons', 'icon.png')
|
|
311
|
+
},
|
|
312
|
+
templates: {
|
|
313
|
+
about: path.join(__dirname, 'assets', 'templates', 'about.html'),
|
|
314
|
+
update: path.join(__dirname, 'assets', 'templates', 'update.html'),
|
|
315
|
+
error: path.join(__dirname, 'assets', 'templates', 'error.html')
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## 打包配置更新
|
|
321
|
+
|
|
322
|
+
```json
|
|
323
|
+
// package.json build 配置
|
|
324
|
+
{
|
|
325
|
+
"build": {
|
|
326
|
+
"extraResources": [
|
|
327
|
+
{
|
|
328
|
+
"from": "assets",
|
|
329
|
+
"to": "assets",
|
|
330
|
+
"filter": [
|
|
331
|
+
"**/*"
|
|
332
|
+
]
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
"files": [
|
|
336
|
+
"**/*",
|
|
337
|
+
"!assets/**/*.md",
|
|
338
|
+
"!assets/**/*.psd"
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## 未来扩展规划
|
|
345
|
+
|
|
346
|
+
1. **主题支持**: 支持亮色/暗色主题切换
|
|
347
|
+
2. **国际化**: 支持多语言界面
|
|
348
|
+
3. **自定义样式**: 支持用户自定义CSS
|
|
349
|
+
4. **动态模板**: 支持运行时模板更新
|
|
350
|
+
5. **资源热重载**: 开发模式下支持资源热更新
|
|
351
|
+
6. **压缩优化**: 生产环境自动压缩资源文件
|