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