@bytechain.cn/colamd 1.5.1 → 1.5.2

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.
Files changed (201) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +105 -38
  3. package/README_CN.md +121 -46
  4. package/dist/lib/colamd-renderer.js +193804 -0
  5. package/dist/lib/colamd-renderer.js.map +1 -0
  6. package/dist/lib/colamd.css +1810 -0
  7. package/dist/lib/editor/editor.d.ts +27 -0
  8. package/dist/lib/editor/html-view.d.ts +2 -0
  9. package/dist/lib/editor/lib.d.ts +49 -0
  10. package/dist/lib/editor/plugins/index.d.ts +56 -0
  11. package/dist/lib/editor/plugins/lib-entry.d.ts +10 -0
  12. package/dist/lib/editor/plugins/math-plugin.d.ts +9 -0
  13. package/dist/lib/editor/plugins/mermaid-plugin.d.ts +19 -0
  14. package/dist/lib/editor/plugins/themes/theme-manager.d.ts +30 -0
  15. package/dist/main/index.js +93 -32
  16. package/dist/preload/index.js +2 -1
  17. package/dist/renderer/assets/{arc-_lugyDzx.js → arc-CpIo2PoE.js} +1 -1
  18. package/dist/renderer/assets/{architectureDiagram-3BPJPVTR-DDfP-F9D.js → architectureDiagram-3BPJPVTR-T-4Cq0Bz.js} +2 -2
  19. package/dist/renderer/assets/{blockDiagram-GPEHLZMM-DOETUKma.js → blockDiagram-GPEHLZMM-C-SuR6eu.js} +4 -4
  20. package/dist/renderer/assets/{c4Diagram-AAUBKEIU-kAmLfVtk.js → c4Diagram-AAUBKEIU-PJp81cGm.js} +2 -2
  21. package/dist/renderer/assets/{channel-CD4vJFwr.js → channel-CtIHaaRI.js} +1 -1
  22. package/dist/renderer/assets/{chunk-2J33WTMH-DkVrgw4l.js → chunk-2J33WTMH-BrchfQL6.js} +1 -1
  23. package/dist/renderer/assets/{chunk-4BX2VUAB-JTZ-VKNX.js → chunk-4BX2VUAB-BCc3Ev_H.js} +1 -1
  24. package/dist/renderer/assets/{chunk-55IACEB6-Di_O5box.js → chunk-55IACEB6-B2M27HQo.js} +1 -1
  25. package/dist/renderer/assets/{chunk-727SXJPM-BgKvwR8w.js → chunk-727SXJPM-DXDHGECs.js} +5 -5
  26. package/dist/renderer/assets/{chunk-AQP2D5EJ-DonSXCCQ.js → chunk-AQP2D5EJ-BNb1lOQY.js} +3 -3
  27. package/dist/renderer/assets/{chunk-FMBD7UC4-CsV8Lmy6.js → chunk-FMBD7UC4-CzgfEH2z.js} +1 -1
  28. package/dist/renderer/assets/{chunk-ND2GUHAM-C_-_dlq7.js → chunk-ND2GUHAM-BUFT_yOe.js} +1 -1
  29. package/dist/renderer/assets/{chunk-QZHKN3VN-aCmcDsfu.js → chunk-QZHKN3VN-C-zV7oBi.js} +1 -1
  30. package/dist/renderer/assets/{classDiagram-v2-Q7XG4LA2-nuHQLjzM.js → classDiagram-4FO5ZUOK-CAyhGSvf.js} +6 -6
  31. package/dist/renderer/assets/{classDiagram-4FO5ZUOK-nuHQLjzM.js → classDiagram-v2-Q7XG4LA2-CAyhGSvf.js} +6 -6
  32. package/dist/renderer/assets/{cose-bilkent-S5V4N54A-Di1_SXt9.js → cose-bilkent-S5V4N54A-ldu81kCk.js} +1 -1
  33. package/dist/renderer/assets/{dagre-BM42HDAG-CqOUIYsL.js → dagre-BM42HDAG-NJgy8CTw.js} +3 -3
  34. package/dist/renderer/assets/{diagram-2AECGRRQ-F-fP19TC.js → diagram-2AECGRRQ-CuIcMpOn.js} +2 -2
  35. package/dist/renderer/assets/{diagram-5GNKFQAL-BD5XZc8G.js → diagram-5GNKFQAL-BJwFCroB.js} +3 -3
  36. package/dist/renderer/assets/{diagram-KO2AKTUF-Qa3ZxA67.js → diagram-KO2AKTUF-C7NgQ8ju.js} +2 -2
  37. package/dist/renderer/assets/{diagram-LMA3HP47-DqDnw2RA.js → diagram-LMA3HP47-B71v6MOq.js} +2 -2
  38. package/dist/renderer/assets/{diagram-OG6HWLK6-BH4Elzby.js → diagram-OG6HWLK6-D2ZxkrSe.js} +3 -3
  39. package/dist/renderer/assets/{erDiagram-TEJ5UH35-CaKZCewa.js → erDiagram-TEJ5UH35-4ToW0p3h.js} +4 -4
  40. package/dist/renderer/assets/{flowDiagram-I6XJVG4X-C8znUgyL.js → flowDiagram-I6XJVG4X-DBkZLqwn.js} +6 -6
  41. package/dist/renderer/assets/{ganttDiagram-6RSMTGT7-DnRvbMnU.js → ganttDiagram-6RSMTGT7-G3xD2VXj.js} +2 -2
  42. package/dist/renderer/assets/{gitGraphDiagram-PVQCEYII-CZuRZzk4.js → gitGraphDiagram-PVQCEYII-BcTNiFfg.js} +3 -3
  43. package/dist/renderer/assets/{graph-CYiEKt0j.js → graph--Vhl4p4D.js} +1 -1
  44. package/dist/renderer/assets/{index-BX6JHKv6.js → index-C63bU7CF.js} +400 -54
  45. package/dist/renderer/assets/{index-CcwAgVRi.css → index-D8nA981z.css} +12 -0
  46. package/dist/renderer/assets/{infoDiagram-5YYISTIA-BlBUdqMb.js → infoDiagram-5YYISTIA-DjKa7Yv-.js} +1 -1
  47. package/dist/renderer/assets/{ishikawaDiagram-YF4QCWOH-TeVytCrP.js → ishikawaDiagram-YF4QCWOH-xIWzW1pL.js} +1 -1
  48. package/dist/renderer/assets/{journeyDiagram-JHISSGLW-BLZa3jnX.js → journeyDiagram-JHISSGLW-DxMBkVOF.js} +4 -4
  49. package/dist/renderer/assets/{kanban-definition-UN3LZRKU-foVxWrJn.js → kanban-definition-UN3LZRKU-DqJeL6E1.js} +2 -2
  50. package/dist/renderer/assets/{layout-DOAlFUVb.js → layout-B3giiMoK.js} +2 -2
  51. package/dist/renderer/assets/{linear-BMBn6kVq.js → linear-Cqh3vVIf.js} +1 -1
  52. package/dist/renderer/assets/{mindmap-definition-RKZ34NQL-5pGeNCcp.js → mindmap-definition-RKZ34NQL-DUay02ma.js} +3 -3
  53. package/dist/renderer/assets/{pieDiagram-4H26LBE5-N9aAUxfr.js → pieDiagram-4H26LBE5-CVcfLtky.js} +3 -3
  54. package/dist/renderer/assets/{quadrantDiagram-W4KKPZXB-BPxbtjga.js → quadrantDiagram-W4KKPZXB-wDHffPOs.js} +2 -2
  55. package/dist/renderer/assets/{requirementDiagram-4Y6WPE33-CK1LrJyG.js → requirementDiagram-4Y6WPE33-C4pgGDGv.js} +3 -3
  56. package/dist/renderer/assets/{sankeyDiagram-5OEKKPKP-BNj7Sqii.js → sankeyDiagram-5OEKKPKP-Jsf0rRMo.js} +1 -1
  57. package/dist/renderer/assets/{sequenceDiagram-3UESZ5HK-B-r7lNhI.js → sequenceDiagram-3UESZ5HK-e6QS7gt8.js} +3 -3
  58. package/dist/renderer/assets/{stateDiagram-AJRCARHV-wrWE0MRa.js → stateDiagram-AJRCARHV-DgYKZzDq.js} +6 -6
  59. package/dist/renderer/assets/{stateDiagram-v2-BHNVJYJU-CE-Lqo2d.js → stateDiagram-v2-BHNVJYJU-CUdmd_50.js} +4 -4
  60. package/dist/renderer/assets/{timeline-definition-PNZ67QCA-BkeMGH4J.js → timeline-definition-PNZ67QCA-S12e1Mp_.js} +2 -2
  61. package/dist/renderer/assets/{vennDiagram-CIIHVFJN-BTxVzto3.js → vennDiagram-CIIHVFJN-CNDBG6A2.js} +1 -1
  62. package/dist/renderer/assets/{wardleyDiagram-YWT4CUSO-D2r5dVGW.js → wardleyDiagram-YWT4CUSO-CLlGQcof.js} +2 -2
  63. package/dist/renderer/assets/{xychartDiagram-2RQKCTM6-BHQdINVc.js → xychartDiagram-2RQKCTM6-CUtsHUQd.js} +2 -2
  64. package/dist/renderer/index.html +6 -2
  65. package/package.json +25 -1
  66. package/.github/workflows/release.yml +0 -66
  67. package/.trae/specs/optimize-theme-loading/checklist.md +0 -20
  68. package/.trae/specs/optimize-theme-loading/spec.md +0 -103
  69. package/.trae/specs/optimize-theme-loading/tasks.md +0 -40
  70. package/CLAUDE.md +0 -143
  71. package/android/app/build/.npmkeep +0 -0
  72. package/android/app/build.gradle +0 -76
  73. package/android/app/capacitor.build.gradle +0 -24
  74. package/android/app/proguard-rules.pro +0 -21
  75. package/android/app/release.keystore +0 -0
  76. package/android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java +0 -26
  77. package/android/app/src/main/AndroidManifest.xml +0 -64
  78. package/android/app/src/main/java/cn/bytechain/colamd/MainActivity.java +0 -180
  79. package/android/app/src/main/res/drawable/ic_launcher_background.xml +0 -170
  80. package/android/app/src/main/res/drawable/splash.png +0 -0
  81. package/android/app/src/main/res/drawable-land-hdpi/splash.png +0 -0
  82. package/android/app/src/main/res/drawable-land-mdpi/splash.png +0 -0
  83. package/android/app/src/main/res/drawable-land-xhdpi/splash.png +0 -0
  84. package/android/app/src/main/res/drawable-land-xxhdpi/splash.png +0 -0
  85. package/android/app/src/main/res/drawable-land-xxxhdpi/splash.png +0 -0
  86. package/android/app/src/main/res/drawable-port-hdpi/splash.png +0 -0
  87. package/android/app/src/main/res/drawable-port-mdpi/splash.png +0 -0
  88. package/android/app/src/main/res/drawable-port-xhdpi/splash.png +0 -0
  89. package/android/app/src/main/res/drawable-port-xxhdpi/splash.png +0 -0
  90. package/android/app/src/main/res/drawable-port-xxxhdpi/splash.png +0 -0
  91. package/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -34
  92. package/android/app/src/main/res/layout/activity_main.xml +0 -12
  93. package/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -5
  94. package/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -5
  95. package/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  96. package/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
  97. package/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  98. package/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  99. package/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
  100. package/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  101. package/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  102. package/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
  103. package/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  104. package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  105. package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
  106. package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  107. package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  108. package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
  109. package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  110. package/android/app/src/main/res/values/ic_launcher_background.xml +0 -4
  111. package/android/app/src/main/res/values/strings.xml +0 -7
  112. package/android/app/src/main/res/values/styles.xml +0 -22
  113. package/android/app/src/main/res/xml/file_paths.xml +0 -5
  114. package/android/app/src/main/res/xml/network_security_config.xml +0 -8
  115. package/android/app/src/test/java/com/getcapacitor/myapp/ExampleUnitTest.java +0 -18
  116. package/android/build.gradle +0 -29
  117. package/android/capacitor.settings.gradle +0 -21
  118. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  119. package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
  120. package/android/gradle.properties +0 -22
  121. package/android/gradlew +0 -248
  122. package/android/gradlew.bat +0 -92
  123. package/android/settings.gradle +0 -5
  124. package/android/variables.gradle +0 -16
  125. package/capacitor.config.js +0 -29
  126. package/capacitor.config.ts +0 -30
  127. package/demo.md +0 -193
  128. package/docs/RELEASE_NOTES_v1.5.1.md +0 -382
  129. package/docs/academic-demo.md +0 -567
  130. package/docs/agent-diff-view.md +0 -48
  131. package/docs/demo.html +0 -748
  132. package/docs/demo.md +0 -546
  133. package/docs/demo.pdf +0 -0
  134. package/docs/theme-paradigm.md +0 -797
  135. package/electron-builder.yml +0 -64
  136. package/electron.vite.config.js +0 -31
  137. package/electron.vite.config.ts +0 -30
  138. package/ios/App/App/AppDelegate.swift +0 -49
  139. package/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png +0 -0
  140. package/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -14
  141. package/ios/App/App/Assets.xcassets/Contents.json +0 -6
  142. package/ios/App/App/Assets.xcassets/Splash.imageset/Contents.json +0 -23
  143. package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
  144. package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
  145. package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
  146. package/ios/App/App/Base.lproj/LaunchScreen.storyboard +0 -32
  147. package/ios/App/App/Base.lproj/Main.storyboard +0 -19
  148. package/ios/App/App/Info.plist +0 -49
  149. package/ios/App/App.xcodeproj/project.pbxproj +0 -408
  150. package/ios/App/App.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  151. package/ios/App/Podfile +0 -28
  152. package/resources/entitlements.mac.plist +0 -12
  153. package/resources/icon.icns +0 -0
  154. package/resources/icon.png +0 -0
  155. package/resources/icon.svg +0 -23
  156. package/resources/templates/slides/icon.png +0 -0
  157. package/resources/templates/slides/slides-template.md +0 -74
  158. package/resources/templates/slides/template-forest-ink.html +0 -540
  159. package/resources/templates/slides/template.html +0 -535
  160. package/scripts/afterPack.js +0 -13
  161. package/scripts/generate-icons.js +0 -102
  162. package/src/main/index.ts +0 -919
  163. package/src/preload/index.d.ts +0 -51
  164. package/src/preload/index.js +0 -70
  165. package/src/preload/index.ts +0 -110
  166. package/src/renderer/capacitor-api.ts +0 -713
  167. package/src/renderer/editor/editor.ts +0 -287
  168. package/src/renderer/editor/html-view.ts +0 -15
  169. package/src/renderer/editor/plugins/index.ts +0 -86
  170. package/src/renderer/editor/plugins/math-plugin.ts +0 -305
  171. package/src/renderer/editor/plugins/mermaid-plugin-custom.css +0 -46
  172. package/src/renderer/editor/plugins/mermaid-plugin-dark.css +0 -428
  173. package/src/renderer/editor/plugins/mermaid-plugin-elegant.css +0 -443
  174. package/src/renderer/editor/plugins/mermaid-plugin-newsprint.css +0 -208
  175. package/src/renderer/editor/plugins/mermaid-plugin.css +0 -111
  176. package/src/renderer/editor/plugins/mermaid-plugin.ts +0 -680
  177. package/src/renderer/editor/plugins/themes/base/dark.css +0 -23
  178. package/src/renderer/editor/plugins/themes/base/elegant.css +0 -32
  179. package/src/renderer/editor/plugins/themes/base/light.css +0 -20
  180. package/src/renderer/editor/plugins/themes/base/newsprint.css +0 -27
  181. package/src/renderer/editor/plugins/themes/base.css +0 -509
  182. package/src/renderer/editor/plugins/themes/components/mermaid/academic.css +0 -43
  183. package/src/renderer/editor/plugins/themes/components/mermaid/dark.css +0 -20
  184. package/src/renderer/editor/plugins/themes/components/mermaid/elegant.css +0 -24
  185. package/src/renderer/editor/plugins/themes/components/mermaid/light.css +0 -21
  186. package/src/renderer/editor/plugins/themes/components/mermaid/newsprint.css +0 -26
  187. package/src/renderer/editor/plugins/themes/components/mermaid/variables.css +0 -592
  188. package/src/renderer/editor/plugins/themes/foundation.css +0 -143
  189. package/src/renderer/editor/plugins/themes/theme-manager.ts +0 -133
  190. package/src/renderer/env.d.ts +0 -10
  191. package/src/renderer/index.html +0 -76
  192. package/src/renderer/main.ts +0 -775
  193. package/src/renderer/mobile.css +0 -428
  194. package/tsconfig.json +0 -14
  195. package/tsconfig.main.json +0 -12
  196. package/tsconfig.main.tsbuildinfo +0 -1
  197. package/tsconfig.preload.json +0 -12
  198. package/tsconfig.preload.tsbuildinfo +0 -1
  199. package/tsconfig.renderer.json +0 -13
  200. package/tsconfig.renderer.tsbuildinfo +0 -1
  201. package/tsconfig.tsbuildinfo +0 -1
package/src/main/index.ts DELETED
@@ -1,919 +0,0 @@
1
- import { app, BrowserWindow, ipcMain, dialog, Menu, shell } from 'electron'
2
- import { join, basename, dirname, extname } from 'path'
3
- import { readFile, writeFile, readdir, copyFile, mkdir, stat } from 'fs/promises'
4
- import { existsSync, readFileSync } from 'fs'
5
- import { IncomingMessage, ServerResponse } from 'http'
6
- import { createServer as createHttpServer } from 'http'
7
-
8
- // Custom themes directory
9
- const themesDir = join(app.getPath('home'), '.colamd', 'themes')
10
-
11
- // PDF 导出时注入的布局 CSS(insertCSS 引擎级注入,仅负责页面结构调整)
12
- const BASE_PRINT_CSS = [
13
- 'html, body { height:auto !important; overflow:visible !important; -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; }',
14
- '#titlebar, #slides-btn, #agent-dot { display:none !important; }',
15
- '#editor { height:auto !important; overflow:visible !important; }',
16
- '#editor .ProseMirror { min-height:auto !important; }',
17
- '.mermaid-error, .mermaid-loading { display:none !important; }',
18
- 'svg .error-icon, svg .error-text { display:none !important; }',
19
- '.math-inline-raw, .math-block-raw, textarea.mermaid-source { display:none !important; }',
20
- ].join('\n')
21
-
22
- function ensureThemesDir(): void {
23
- if (!existsSync(themesDir)) {
24
- mkdir(themesDir, { recursive: true }).catch(() => {})
25
- }
26
- }
27
-
28
- // Per-window state
29
- interface WindowState {
30
- filePath: string | null
31
- watcher: ReturnType<typeof setInterval> | null
32
- isInternalSave: boolean
33
- debounceTimer: ReturnType<typeof setTimeout> | null
34
- agentState: 'idle' | 'active' | 'cooldown'
35
- lastExternalChange: number
36
- agentCooldownTimer: ReturnType<typeof setTimeout> | null
37
- }
38
-
39
- const windowStates = new Map<number, WindowState>()
40
- let pendingFilePaths: string[] = []
41
-
42
- // Plugin menu state — populated by renderer via register-plugins IPC
43
- let pluginMenuItems: Electron.MenuItemConstructorOptions[] = []
44
-
45
- function getState(win: BrowserWindow): WindowState {
46
- let state = windowStates.get(win.id)
47
- if (!state) {
48
- state = { filePath: null, watcher: null, isInternalSave: false, debounceTimer: null, agentState: 'idle', lastExternalChange: 0, agentCooldownTimer: null }
49
- windowStates.set(win.id, state)
50
- }
51
- return state
52
- }
53
-
54
- function getWinFromEvent(event: Electron.IpcMainInvokeEvent): BrowserWindow | null {
55
- return BrowserWindow.fromWebContents(event.sender)
56
- }
57
-
58
- function createWindow(filePath?: string): BrowserWindow {
59
- const win = new BrowserWindow({
60
- width: 960,
61
- height: 720,
62
- minWidth: 600,
63
- minHeight: 400,
64
- titleBarStyle: 'hiddenInset',
65
- trafficLightPosition: { x: 16, y: 16 },
66
- webPreferences: {
67
- preload: join(__dirname, '../preload/index.js'),
68
- contextIsolation: true,
69
- nodeIntegration: false,
70
- sandbox: false
71
- }
72
- })
73
-
74
- const state = getState(win)
75
-
76
- if (process.env.ELECTRON_RENDERER_URL) {
77
- win.loadURL(process.env.ELECTRON_RENDERER_URL)
78
- } else {
79
- win.loadFile(join(__dirname, '../renderer/index.html'))
80
- }
81
-
82
- win.webContents.on('did-finish-load', () => {
83
- // 开发环境自动打开 DevTools 方便调试
84
- // win.webContents.openDevTools({ mode: 'bottom' })
85
- if (filePath) {
86
- loadFileInWindow(win, filePath)
87
- }
88
- })
89
-
90
- win.on('closed', () => {
91
- stopWatching(state)
92
- windowStates.delete(win.id)
93
- })
94
-
95
- updateTitle(win)
96
- return win
97
- }
98
-
99
- function updateTitle(win: BrowserWindow): void {
100
- const state = getState(win)
101
- const fileName = state.filePath ? basename(state.filePath) : 'Untitled'
102
- win.setTitle(`${fileName} — ColaMD`)
103
- }
104
-
105
- function suggestFileName(win: BrowserWindow, content?: string): string | undefined {
106
- const state = getState(win)
107
- if (state.filePath) return basename(state.filePath, '.md')
108
- if (!content) return undefined
109
- // Extract first heading or first non-empty line
110
- const match = content.match(/^#\s+(.+)/m) || content.match(/^(.+)/m)
111
- if (!match) return undefined
112
- return match[1].trim().replace(/[/\\:*?"<>|]/g, '').slice(0, 60) || undefined
113
- }
114
-
115
- function stopWatching(state: WindowState): void {
116
- if (state.watcher) {
117
- clearInterval(state.watcher)
118
- state.watcher = null
119
- }
120
- if (state.agentCooldownTimer) {
121
- clearTimeout(state.agentCooldownTimer)
122
- state.agentCooldownTimer = null
123
- }
124
- state.agentState = 'idle'
125
- state.lastExternalChange = 0
126
- }
127
-
128
- function transitionAgentState(win: BrowserWindow, state: WindowState, newState: 'idle' | 'active' | 'cooldown'): void {
129
- if (state.agentCooldownTimer) {
130
- clearTimeout(state.agentCooldownTimer)
131
- state.agentCooldownTimer = null
132
- }
133
-
134
- if (newState === 'active') {
135
- if (state.agentState !== 'active') {
136
- state.agentState = 'active'
137
- if (!win.isDestroyed()) win.webContents.send('agent-activity', 'active')
138
- }
139
- // Reset cooldown timer — 3s after last write
140
- state.agentCooldownTimer = setTimeout(() => {
141
- transitionAgentState(win, state, 'cooldown')
142
- }, 3000)
143
- } else if (newState === 'cooldown') {
144
- state.agentState = 'cooldown'
145
- if (!win.isDestroyed()) win.webContents.send('agent-activity', 'cooldown')
146
- state.agentCooldownTimer = setTimeout(() => {
147
- transitionAgentState(win, state, 'idle')
148
- }, 2000)
149
- } else {
150
- state.agentState = 'idle'
151
- if (!win.isDestroyed()) win.webContents.send('agent-activity', 'idle')
152
- }
153
- }
154
-
155
- function watchFile(win: BrowserWindow, state: WindowState): void {
156
- if (!state.filePath) return
157
- stopWatching(state)
158
- const filePath = state.filePath
159
- let lastMtime = 0
160
-
161
- stat(filePath).then(s => { lastMtime = s.mtimeMs }).catch(() => {})
162
-
163
- state.watcher = setInterval(() => {
164
- if (state.isInternalSave) return
165
- stat(filePath).then(s => {
166
- if (s.mtimeMs === lastMtime) return
167
- lastMtime = s.mtimeMs
168
-
169
- // Agent activity detection
170
- const now = Date.now()
171
- const gap = now - state.lastExternalChange
172
- state.lastExternalChange = now
173
- if (gap > 0 && gap < 2000) {
174
- transitionAgentState(win, state, 'active')
175
- } else if (state.agentState === 'active') {
176
- transitionAgentState(win, state, 'active') // reset cooldown timer
177
- }
178
-
179
- if (state.debounceTimer) clearTimeout(state.debounceTimer)
180
- state.debounceTimer = setTimeout(() => {
181
- readFile(filePath, 'utf-8')
182
- .then((data) => {
183
- if (!win.isDestroyed()) win.webContents.send('file-changed', resolveImagePaths(data, filePath))
184
- })
185
- .catch(() => {})
186
- }, 100)
187
- }).catch(() => {})
188
- }, 500)
189
- }
190
-
191
- // Rewrite relative image paths in markdown to absolute file:// URLs
192
- function resolveImagePaths(content: string, filePath: string): string {
193
- const dir = dirname(filePath)
194
- return content.replace(/!\[([^\]]*)\]\((?!https?:\/\/|file:\/\/|data:)([^)]+)\)/g, (_match, alt, src) => {
195
- const abs = join(dir, src)
196
- return `![${alt}](file://${abs})`
197
- })
198
- }
199
-
200
- function loadFileInWindow(win: BrowserWindow, filePath: string): void {
201
- readFile(filePath, 'utf-8')
202
- .then((data) => {
203
- const state = getState(win)
204
- state.filePath = filePath
205
- watchFile(win, state)
206
- updateTitle(win)
207
- win.webContents.send('file-opened', { path: filePath, content: resolveImagePaths(data, filePath) })
208
- })
209
- .catch(() => {})
210
- }
211
-
212
- // Find window that already has this file open
213
- function findWindowForFile(filePath: string): BrowserWindow | null {
214
- for (const [id, state] of windowStates) {
215
- if (state.filePath === filePath) {
216
- return BrowserWindow.fromId(id) || null
217
- }
218
- }
219
- return null
220
- }
221
-
222
- // Open file: reuse existing window or create new one
223
- function openFile(filePath: string): void {
224
- // If already open, focus that window
225
- const existing = findWindowForFile(filePath)
226
- if (existing) {
227
- existing.focus()
228
- return
229
- }
230
-
231
- // Find an untitled empty window to reuse
232
- const emptyWin = findEmptyWindow()
233
- if (emptyWin) {
234
- loadFileInWindow(emptyWin, filePath)
235
- emptyWin.focus()
236
- return
237
- }
238
-
239
- // Create new window
240
- const win = createWindow(filePath)
241
- win.focus()
242
- }
243
-
244
- function findEmptyWindow(): BrowserWindow | null {
245
- for (const [id, state] of windowStates) {
246
- if (!state.filePath) {
247
- return BrowserWindow.fromId(id) || null
248
- }
249
- }
250
- return null
251
- }
252
-
253
- async function saveToPath(win: BrowserWindow, filePath: string, content: string): Promise<boolean> {
254
- const state = getState(win)
255
- try {
256
- state.isInternalSave = true
257
- await writeFile(filePath, content, 'utf-8')
258
- state.filePath = filePath
259
- watchFile(win, state)
260
- updateTitle(win)
261
- return true
262
- } catch {
263
- return false
264
- } finally {
265
- setTimeout(() => { state.isInternalSave = false }, 100)
266
- }
267
- }
268
-
269
- // IPC Handlers
270
-
271
- ipcMain.on('open-external', (_event, url: string) => {
272
- if (typeof url === 'string' && (url.startsWith('https://') || url.startsWith('http://'))) {
273
- shell.openExternal(url)
274
- }
275
- })
276
-
277
- ipcMain.handle('open-file', async (event) => {
278
- const win = getWinFromEvent(event)
279
- if (!win) return null
280
- const result = await dialog.showOpenDialog(win, {
281
- filters: [
282
- { name: 'Markdown', extensions: ['md', 'markdown', 'mdown', 'mkd'] },
283
- { name: 'Text', extensions: ['txt'] },
284
- { name: 'All Files', extensions: ['*'] }
285
- ],
286
- properties: ['openFile']
287
- })
288
- if (result.canceled || result.filePaths.length === 0) return null
289
-
290
- const filePath = result.filePaths[0]
291
-
292
- // If this window has no file, load here; otherwise open in new window
293
- const state = getState(win)
294
- if (!state.filePath) {
295
- try {
296
- const content = await readFile(filePath, 'utf-8')
297
- state.filePath = filePath
298
- watchFile(win, state)
299
- updateTitle(win)
300
- return { path: filePath, content }
301
- } catch {
302
- return null
303
- }
304
- } else {
305
- openFile(filePath)
306
- return null
307
- }
308
- })
309
-
310
- ipcMain.handle('open-file-path', async (event, filePath: string) => {
311
- const win = getWinFromEvent(event)
312
- if (!win) return null
313
- const state = getState(win)
314
-
315
- // If this window has no file, load here
316
- if (!state.filePath) {
317
- try {
318
- const content = await readFile(filePath, 'utf-8')
319
- state.filePath = filePath
320
- watchFile(win, state)
321
- updateTitle(win)
322
- return { path: filePath, content }
323
- } catch {
324
- return null
325
- }
326
- } else {
327
- openFile(filePath)
328
- return null
329
- }
330
- })
331
-
332
- ipcMain.handle('save-file', async (event, content: string) => {
333
- const win = getWinFromEvent(event)
334
- if (!win) return false
335
- const state = getState(win)
336
- if (!state.filePath) {
337
- const result = await dialog.showSaveDialog(win, {
338
- defaultPath: suggestFileName(win, content),
339
- filters: [
340
- { name: 'Markdown', extensions: ['md'] },
341
- { name: 'All Files', extensions: ['*'] }
342
- ]
343
- })
344
- if (result.canceled || !result.filePath) return false
345
- state.filePath = result.filePath
346
- // Copy slides assets alongside the file if this looks like a slides file
347
- if (content.includes('kicker:') || content.includes('chip:')) {
348
- const destDir = dirname(state.filePath)
349
- try {
350
- const files = await readdir(slidesTemplateDir)
351
- await Promise.all(files.filter(f => f !== 'slides-template.md').map(async (f) => {
352
- const dest = join(destDir, f)
353
- if (!existsSync(dest)) await copyFile(join(slidesTemplateDir, f), dest)
354
- }))
355
- } catch { /* best effort */ }
356
- }
357
- }
358
- return saveToPath(win, state.filePath, content)
359
- })
360
-
361
- ipcMain.handle('save-file-as', async (event, content: string) => {
362
- const win = getWinFromEvent(event)
363
- if (!win) return false
364
- const result = await dialog.showSaveDialog(win, {
365
- defaultPath: suggestFileName(win, content),
366
- filters: [
367
- { name: 'Markdown', extensions: ['md'] },
368
- { name: 'All Files', extensions: ['*'] }
369
- ]
370
- })
371
- if (result.canceled || !result.filePath) return false
372
- return saveToPath(win, result.filePath, content)
373
- })
374
-
375
- ipcMain.handle('save-export-file', async (event, dataUrl: string, defaultName: string) => {
376
- const win = getWinFromEvent(event)
377
- if (!win) return false
378
- const ext = (defaultName.match(/\.(\w+)$/)?.[1] || 'png').toLowerCase()
379
- const result = await dialog.showSaveDialog(win, {
380
- defaultPath: defaultName,
381
- filters: [{ name: `${ext.toUpperCase()} File`, extensions: [ext] }]
382
- })
383
- if (result.canceled || !result.filePath) return false
384
- try {
385
- const base64 = dataUrl.replace(/^data:[^;]+;base64,/, '')
386
- await writeFile(result.filePath, Buffer.from(base64, 'base64'))
387
- return true
388
- } catch {
389
- return false
390
- }
391
- })
392
-
393
-
394
- ipcMain.handle('export-pdf', async (event, printCSS?: string) => {
395
- const win = getWinFromEvent(event)
396
- if (!win) return false
397
- const defaultName = (suggestFileName(win) || 'colamd-print') + '.pdf'
398
- const result = await dialog.showSaveDialog(win, {
399
- defaultPath: defaultName,
400
- filters: [{ name: 'PDF', extensions: ['pdf'] }]
401
- })
402
- if (result.canceled || !result.filePath) return false
403
-
404
- try {
405
- const cssKey = await win.webContents.insertCSS(BASE_PRINT_CSS + '\n' + (printCSS || ''))
406
- // 等待样式重排完成(Chromium 需要一帧来应用注入的 CSS)
407
- await new Promise(r => setTimeout(r, 200))
408
- const pdfData = await Promise.race([
409
- win.webContents.printToPDF({
410
- printBackground: true,
411
- pageSize: 'A4'
412
- }),
413
- new Promise<Buffer>((_, reject) => setTimeout(() => reject(new Error('PDF timeout')), 30000))
414
- ])
415
- await win.webContents.removeInsertedCSS(cssKey)
416
- await writeFile(result.filePath, pdfData)
417
- return true
418
- } catch (e) {
419
- console.error('[export-pdf] PDF export failed:', e)
420
- return false
421
- }
422
- })
423
-
424
- ipcMain.handle('export-html', async (event, htmlContent: string) => {
425
- const win = getWinFromEvent(event)
426
- if (!win) return false
427
- const defaultName = (suggestFileName(win) || 'colamd-export') + '.html'
428
- const result = await dialog.showSaveDialog(win, {
429
- defaultPath: defaultName,
430
- filters: [{ name: 'HTML', extensions: ['html'] }]
431
- })
432
- if (result.canceled || !result.filePath) return false
433
-
434
- try {
435
- await writeFile(result.filePath, htmlContent, 'utf-8')
436
- return true
437
- } catch {
438
- return false
439
- }
440
- })
441
-
442
- // ─── Slides feature ──────────────────────────────────────────────────────────
443
-
444
- const slidesTemplateDir = app.isPackaged
445
- ? join(process.resourcesPath, 'templates', 'slides')
446
- : join(__dirname, '../../resources/templates/slides')
447
-
448
- // Per-directory HTTP servers for slides preview: dir -> { server, port }
449
- const slidesServers = new Map<string, { port: number; server: ReturnType<typeof createHttpServer> }>()
450
-
451
- const MIME: Record<string, string> = {
452
- '.html': 'text/html',
453
- '.md': 'text/plain',
454
- '.css': 'text/css',
455
- '.js': 'application/javascript',
456
- '.png': 'image/png',
457
- '.jpg': 'image/jpeg',
458
- '.jpeg': 'image/jpeg',
459
- '.mp4': 'video/mp4',
460
- '.webm': 'video/webm',
461
- '.svg': 'image/svg+xml',
462
- '.ico': 'image/x-icon',
463
- }
464
-
465
- function getOrCreateSlidesServer(dir: string): Promise<number> {
466
- const existing = slidesServers.get(dir)
467
- if (existing) return Promise.resolve(existing.port)
468
-
469
- return new Promise((resolve, reject) => {
470
- const server = createHttpServer((req: IncomingMessage, res: ServerResponse) => {
471
- const url = req.url === '/' ? '/template.html' : (req.url || '/')
472
- const filePath = join(dir, url.split('?')[0])
473
- const ext = extname(filePath).toLowerCase()
474
- const mime = MIME[ext] || 'application/octet-stream'
475
- try {
476
- const data = readFileSync(filePath)
477
- res.writeHead(200, { 'Content-Type': mime })
478
- res.end(data)
479
- } catch {
480
- res.writeHead(404)
481
- res.end('Not found')
482
- }
483
- })
484
- server.listen(0, '127.0.0.1', () => {
485
- const addr = server.address()
486
- if (!addr || typeof addr === 'string') { reject(new Error('no port')); return }
487
- slidesServers.set(dir, { port: addr.port, server })
488
- resolve(addr.port)
489
- })
490
- server.on('error', reject)
491
- })
492
- }
493
-
494
- // New Slides: load template into editor without saving first (⌘S saves later)
495
- // Also copy assets (template.html, icon.png) to the save directory when user saves
496
- ipcMain.handle('new-slides', async (event) => {
497
- const win = getWinFromEvent(event)
498
- if (!win) return null
499
- try {
500
- const content = await readFile(join(slidesTemplateDir, 'slides-template.md'), 'utf-8')
501
- win.webContents.send('new-slides-content', content)
502
- return true
503
- } catch {
504
- return null
505
- }
506
- })
507
-
508
- // Open as Slides: serve the directory containing the current .md file
509
- // If no file is open, first create a new slides file (same as New Slides)
510
- ipcMain.handle('open-as-slides', async (event, content?: string) => {
511
- const win = getWinFromEvent(event)
512
- if (!win) return false
513
- const state = getState(win)
514
-
515
- // No file open — create one first
516
- if (!state.filePath) {
517
- const result = await dialog.showSaveDialog(win, {
518
- title: 'Create New Slides',
519
- defaultPath: 'slides.md',
520
- filters: [{ name: 'Markdown', extensions: ['md'] }]
521
- })
522
- if (result.canceled || !result.filePath) return false
523
- try {
524
- await copyFile(join(slidesTemplateDir, 'slides-template.md'), result.filePath)
525
- loadFileInWindow(win, result.filePath)
526
- state.filePath = result.filePath
527
- } catch {
528
- return false
529
- }
530
- }
531
-
532
- // Auto-save current content to disk before opening browser
533
- if (content !== undefined && state.filePath) {
534
- try {
535
- await writeFile(state.filePath, content, 'utf-8')
536
- } catch { /* best effort */ }
537
- }
538
-
539
- const dir = dirname(state.filePath)
540
- const mdName = basename(state.filePath)
541
-
542
- // Always overwrite template.html so updates take effect
543
- const templateDest = join(dir, 'template.html')
544
- try {
545
- await copyFile(join(slidesTemplateDir, 'template.html'), templateDest)
546
- } catch {
547
- return false
548
- }
549
-
550
- // Rename slides.md reference in template to match actual filename
551
- // (template always fetches 'slides.md' — if file is named differently, patch it)
552
- if (mdName !== 'slides.md') {
553
- try {
554
- let html = await readFile(templateDest, 'utf-8')
555
- html = html.replace(/fetch\('slides\.md'\)/, `fetch('${mdName}')`)
556
- await writeFile(templateDest, html, 'utf-8')
557
- } catch { /* best effort */ }
558
- }
559
-
560
- try {
561
- const port = await getOrCreateSlidesServer(dir)
562
- shell.openExternal(`http://127.0.0.1:${port}/template.html`)
563
- return true
564
- } catch {
565
- return false
566
- }
567
- })
568
-
569
- // Export Slides: inline images as base64, copy videos alongside, produce shareable output
570
- ipcMain.handle('export-slides', async (event, content: string) => {
571
- const win = getWinFromEvent(event)
572
- if (!win) return false
573
- const state = getState(win)
574
- if (!state.filePath) return false
575
-
576
- const srcDir = dirname(state.filePath)
577
-
578
- // Detect if content references any video files
579
- const videoRefs = [...content.matchAll(/<!--\s*type:\s*video[^>]*src:\s*([^\s,>]+)/g)]
580
- .map(m => m[1].trim())
581
- .filter(Boolean)
582
- const hasVideo = videoRefs.length > 0
583
-
584
- // Choose export destination
585
- let destDir: string
586
- let destHtml: string
587
-
588
- if (hasVideo) {
589
- const result = await dialog.showSaveDialog(win, {
590
- title: 'Export Slides Folder',
591
- defaultPath: join(srcDir, 'slides-export'),
592
- buttonLabel: 'Export'
593
- })
594
- if (result.canceled || !result.filePath) return false
595
- destDir = result.filePath
596
- destHtml = join(destDir, 'index.html')
597
- await mkdir(destDir, { recursive: true })
598
- } else {
599
- const result = await dialog.showSaveDialog(win, {
600
- title: 'Export Slides',
601
- defaultPath: join(srcDir, 'slides.html'),
602
- filters: [{ name: 'HTML', extensions: ['html'] }]
603
- })
604
- if (result.canceled || !result.filePath) return false
605
- destDir = dirname(result.filePath)
606
- destHtml = result.filePath
607
- }
608
-
609
- // Read template and inline the markdown content
610
- let html = await readFile(join(srcDir, 'template.html'), 'utf-8')
611
-
612
- // Replace fetch('slides.md') with inline content
613
- const escaped = content.replace(/`/g, '\\`').replace(/\$/g, '\\$')
614
- html = html.replace(
615
- /fetch\('[^']+'\)\s*\n?\s*\.then\(r => r\.text\(\)\)/,
616
- `Promise.resolve(\`${escaped}\`)`
617
- )
618
-
619
- // Inline images as base64
620
- const imgMatches = [...content.matchAll(/!\[[^\]]*\]\((?!https?:\/\/|data:)([^)]+)\)/g)]
621
- const inlinedImages = new Map<string, string>()
622
- for (const m of imgMatches) {
623
- const imgPath = m[1].trim()
624
- if (inlinedImages.has(imgPath)) continue
625
- try {
626
- const abs = join(srcDir, imgPath)
627
- const buf = await readFile(abs)
628
- const ext = extname(imgPath).slice(1).toLowerCase()
629
- const mime = ext === 'jpg' || ext === 'jpeg' ? 'image/jpeg'
630
- : ext === 'png' ? 'image/png'
631
- : ext === 'gif' ? 'image/gif'
632
- : ext === 'webp' ? 'image/webp'
633
- : ext === 'svg' ? 'image/svg+xml'
634
- : 'image/png'
635
- inlinedImages.set(imgPath, `data:${mime};base64,${buf.toString('base64')}`)
636
- } catch { /* skip missing images */ }
637
- }
638
- for (const [src, dataUrl] of inlinedImages) {
639
- html = html.replaceAll(`src="${src}"`, `src="${dataUrl}"`)
640
- html = html.replaceAll(`src='${src}'`, `src='${dataUrl}'`)
641
- }
642
-
643
- // Copy video files alongside if needed
644
- if (hasVideo) {
645
- for (const videoSrc of videoRefs) {
646
- try {
647
- await copyFile(join(srcDir, videoSrc), join(destDir, videoSrc))
648
- } catch { /* skip missing videos */ }
649
- }
650
- }
651
-
652
- await writeFile(destHtml, html, 'utf-8')
653
- shell.showItemInFolder(destHtml)
654
- return true
655
- })
656
-
657
- ipcMain.handle('load-custom-theme', async (event) => {
658
- const win = getWinFromEvent(event)
659
- if (!win) return null
660
- const result = await dialog.showOpenDialog(win, {
661
- filters: [{ name: 'CSS', extensions: ['css'] }],
662
- properties: ['openFile']
663
- })
664
- if (result.canceled || result.filePaths.length === 0) return null
665
-
666
- try {
667
- const srcPath = result.filePaths[0]
668
- const fileName = basename(srcPath)
669
- const destPath = join(themesDir, fileName)
670
- await copyFile(srcPath, destPath)
671
- const css = await readFile(destPath, 'utf-8')
672
- invalidateThemeCache()
673
- await buildMenu() // rebuild menu to include new theme
674
- return { name: fileName, css }
675
- } catch {
676
- return null
677
- }
678
- })
679
-
680
- ipcMain.handle('load-theme-css', async (_event, fileName: string) => {
681
- try {
682
- return await readFile(join(themesDir, fileName), 'utf-8')
683
- } catch {
684
- return null
685
- }
686
- })
687
-
688
- // Plugin menu — receives plugin list from renderer, builds dynamic submenu
689
-
690
- ipcMain.handle('register-plugins', (_event, plugins: Array<{ id: string; name: string; enabled: boolean }>) => {
691
- pluginMenuItems = plugins.map((p) => ({
692
- id: p.id,
693
- label: p.name,
694
- type: 'checkbox' as const,
695
- checked: p.enabled,
696
- click: () => sendToFocused('menu-toggle-plugin', p.id)
697
- }))
698
- void buildMenu()
699
- return true
700
- })
701
-
702
- ipcMain.handle('sync-plugin-state', (_event, id: string, enabled: boolean) => {
703
- const item = pluginMenuItems.find((p: any) => p.id === id)
704
- if (item) item.checked = enabled
705
- void buildMenu()
706
- })
707
-
708
- // Menu — targets the focused window
709
-
710
- let cachedThemeFiles: string[] = []
711
- let themeFilesValid = false
712
-
713
- function invalidateThemeCache(): void {
714
- themeFilesValid = false
715
- }
716
-
717
- async function scanThemeFiles(): Promise<void> {
718
- try {
719
- const files = await readdir(themesDir)
720
- cachedThemeFiles = files.filter(f => f.endsWith('.css')).sort()
721
- } catch {
722
- cachedThemeFiles = []
723
- }
724
- themeFilesValid = true
725
- }
726
-
727
- async function getCachedThemeFiles(): Promise<string[]> {
728
- if (!themeFilesValid) await scanThemeFiles()
729
- return cachedThemeFiles
730
- }
731
-
732
- function getFocusedWindow(): BrowserWindow | null {
733
- return BrowserWindow.getFocusedWindow()
734
- }
735
-
736
- function sendToFocused(channel: string, ...args: unknown[]): void {
737
- const win = getFocusedWindow()
738
- if (win) win.webContents.send(channel, ...args)
739
- }
740
-
741
- async function buildMenu(): Promise<void> {
742
- const isMac = process.platform === 'darwin'
743
-
744
- const customThemeItems: Electron.MenuItemConstructorOptions[] = []
745
- const files = await getCachedThemeFiles()
746
- for (const file of files) {
747
- customThemeItems.push({
748
- label: file.replace(/\.css$/, ''),
749
- click: async () => {
750
- try {
751
- const css = await readFile(join(themesDir, file), 'utf-8')
752
- sendToFocused('set-theme', `custom:${file}`)
753
- sendToFocused('set-custom-css', css)
754
- } catch { /* ignore */ }
755
- }
756
- })
757
- }
758
-
759
- const themeSubmenu: Electron.MenuItemConstructorOptions[] = [
760
- { label: 'Light', click: () => sendToFocused('set-theme', 'light') },
761
- { label: 'Dark', click: () => sendToFocused('set-theme', 'dark') },
762
- { label: 'Elegant', click: () => sendToFocused('set-theme', 'elegant') },
763
- { label: 'Newsprint', click: () => sendToFocused('set-theme', 'newsprint') },
764
- ]
765
- if (customThemeItems.length > 0) {
766
- themeSubmenu.push({ type: 'separator' }, ...customThemeItems)
767
- }
768
- themeSubmenu.push({ type: 'separator' }, {
769
- label: 'Import Theme...',
770
- click: () => sendToFocused('menu-import-theme')
771
- })
772
-
773
- const template: Electron.MenuItemConstructorOptions[] = [
774
- ...(isMac ? [{
775
- label: 'ColaMD',
776
- submenu: [
777
- { role: 'about' as const },
778
- { type: 'separator' as const },
779
- { role: 'hide' as const },
780
- { role: 'hideOthers' as const },
781
- { role: 'unhide' as const },
782
- { type: 'separator' as const },
783
- { role: 'quit' as const }
784
- ]
785
- }] : []),
786
- {
787
- label: 'File',
788
- submenu: [
789
- {
790
- label: 'New',
791
- accelerator: 'CmdOrCtrl+N',
792
- click: () => createWindow()
793
- },
794
- {
795
- label: 'New Slides...',
796
- accelerator: 'CmdOrCtrl+Shift+N',
797
- click: () => sendToFocused('menu-new-slides')
798
- },
799
- {
800
- label: 'Open...',
801
- accelerator: 'CmdOrCtrl+O',
802
- click: () => sendToFocused('menu-open')
803
- },
804
- { type: 'separator' },
805
- {
806
- label: 'Save',
807
- accelerator: 'CmdOrCtrl+S',
808
- click: () => sendToFocused('menu-save')
809
- },
810
- {
811
- label: 'Save As...',
812
- accelerator: 'CmdOrCtrl+Shift+S',
813
- click: () => sendToFocused('menu-save-as')
814
- },
815
- { type: 'separator' },
816
- {
817
- label: 'Export PDF...',
818
- click: () => sendToFocused('menu-export-pdf')
819
- },
820
- {
821
- label: 'Export HTML...',
822
- click: () => sendToFocused('menu-export-html')
823
- },
824
- {
825
- label: 'Export Slides...',
826
- click: () => sendToFocused('menu-export-slides')
827
- },
828
- {
829
- label: 'Open as Slides',
830
- accelerator: 'CmdOrCtrl+Shift+P',
831
- click: () => sendToFocused('menu-open-as-slides')
832
- },
833
- { type: 'separator' },
834
- isMac ? { role: 'close' } : { role: 'quit' }
835
- ]
836
- },
837
- {
838
- label: 'Edit',
839
- submenu: [
840
- { role: 'undo' },
841
- { role: 'redo' },
842
- { type: 'separator' },
843
- { role: 'cut' },
844
- { role: 'copy' },
845
- { role: 'paste' },
846
- { role: 'selectAll' }
847
- ]
848
- },
849
- {
850
- label: 'View',
851
- submenu: [
852
- { role: 'resetZoom' },
853
- { role: 'zoomIn' },
854
- { role: 'zoomOut' },
855
- { type: 'separator' },
856
- { role: 'togglefullscreen' },
857
- ...(pluginMenuItems.length > 0
858
- ? [{ type: 'separator' as const }, { label: 'Plugins', submenu: pluginMenuItems }]
859
- : [])
860
- ]
861
- },
862
- {
863
- label: 'Theme',
864
- submenu: themeSubmenu
865
- },
866
- {
867
- label: 'Help',
868
- submenu: [
869
- {
870
- label: 'About ColaMD',
871
- click: () => shell.openExternal('https://github.com/marswaveai/colamd')
872
- }
873
- ]
874
- }
875
- ]
876
-
877
- Menu.setApplicationMenu(Menu.buildFromTemplate(template))
878
- }
879
-
880
- // App lifecycle
881
-
882
- app.whenReady().then(async () => {
883
- ensureThemesDir()
884
- await scanThemeFiles()
885
- await buildMenu()
886
-
887
- // Check command line args for file paths
888
- const args = process.argv.slice(app.isPackaged ? 1 : 2)
889
- const fileArgs = args.filter((arg) => !arg.startsWith('-'))
890
- if (fileArgs.length > 0) {
891
- pendingFilePaths = fileArgs
892
- }
893
-
894
- if (pendingFilePaths.length > 0) {
895
- for (const fp of pendingFilePaths) {
896
- createWindow(fp)
897
- }
898
- pendingFilePaths = []
899
- } else {
900
- createWindow()
901
- }
902
-
903
- app.on('activate', () => {
904
- if (BrowserWindow.getAllWindows().length === 0) createWindow()
905
- })
906
- })
907
-
908
- app.on('window-all-closed', () => {
909
- if (process.platform !== 'darwin') app.quit()
910
- })
911
-
912
- app.on('open-file', (event, filePath) => {
913
- event.preventDefault()
914
- if (app.isReady()) {
915
- openFile(filePath)
916
- } else {
917
- pendingFilePaths.push(filePath)
918
- }
919
- })