@niyamulahsan/create-deskapp 1.2.5 → 1.2.6

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 (104) hide show
  1. package/package.json +1 -1
  2. package/template/.env.example +20 -13
  3. package/template/AGENTS.md +699 -0
  4. package/template/package.json +3 -0
  5. package/template/src/config/app.ts +26 -24
  6. package/template/src/config/winsetup.ts +93 -91
  7. package/template/src/core/api/binding-error.ts +57 -0
  8. package/template/src/core/api/bindings.generated.ts +2 -0
  9. package/template/src/core/api/generate.manifest.ts +84 -80
  10. package/template/src/core/api/registry.ts +58 -48
  11. package/template/src/core/config.ts +101 -99
  12. package/template/src/core/database/aggregate.ts +89 -85
  13. package/template/src/core/database/config.ts +50 -48
  14. package/template/src/core/database/connection.ts +116 -114
  15. package/template/src/core/database/migrate-hooks.ts +86 -84
  16. package/template/src/core/database/paginate.ts +226 -224
  17. package/template/src/core/database/reset.ts +21 -19
  18. package/template/src/core/database/seed.ts +169 -167
  19. package/template/src/core/database/status.ts +37 -35
  20. package/template/src/core/env.ts +108 -106
  21. package/template/src/core/facade.ts +63 -61
  22. package/template/src/core/maker/db/fresh.ts +10 -8
  23. package/template/src/core/maker/db/generate.ts +13 -11
  24. package/template/src/core/maker/db/helpers.ts +92 -96
  25. package/template/src/core/maker/db/migrate.ts +37 -35
  26. package/template/src/core/maker/db/mod.ts +93 -91
  27. package/template/src/core/maker/db/module-migrate.ts +56 -54
  28. package/template/src/core/maker/db/push.ts +23 -21
  29. package/template/src/core/maker/db/reset.ts +8 -6
  30. package/template/src/core/maker/db/seed.ts +9 -7
  31. package/template/src/core/maker/db/status.ts +8 -6
  32. package/template/src/core/maker/help.ts +59 -57
  33. package/template/src/core/maker/make/controller.ts +25 -22
  34. package/template/src/core/maker/make/helpers.ts +97 -91
  35. package/template/src/core/maker/make/mod.ts +69 -67
  36. package/template/src/core/maker/make/model.ts +16 -14
  37. package/template/src/core/maker/make/module.ts +53 -39
  38. package/template/src/core/maker/make/seeder.ts +23 -21
  39. package/template/src/core/maker/make/test.ts +33 -30
  40. package/template/src/core/maker/mod.ts +85 -83
  41. package/template/src/core/maker/run/mod.ts +134 -132
  42. package/template/src/core/maker/stub.ts +26 -24
  43. package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
  44. package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
  45. package/template/src/core/maker/stubs/facade/facade.stub +21 -0
  46. package/template/src/core/maker/stubs/model/model.stub +10 -8
  47. package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
  48. package/template/src/core/maker/stubs/test/test.stub +9 -7
  49. package/template/src/core/maker/sync-config.ts +93 -94
  50. package/template/src/core/utils/password.ts +29 -27
  51. package/template/src/core/utils/playwright.ts +123 -121
  52. package/template/src/core/utils/queue.ts +68 -66
  53. package/template/src/core/utils/scheduler.ts +62 -60
  54. package/template/src/core/utils/storage.ts +3 -1
  55. package/template/src/core/utils/validation.ts +37 -35
  56. package/template/src/database/schema.ts +2 -0
  57. package/template/src/main.ts +120 -118
  58. package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
  59. package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
  60. package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
  61. package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
  62. package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
  63. package/template/src/modules/app/controllers/demo.controller.ts +120 -118
  64. package/template/src/modules/app/controllers/net.controller.ts +50 -48
  65. package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
  66. package/template/src/modules/app/controllers/storage.controller.ts +231 -229
  67. package/template/src/modules/app/controllers/window.controller.ts +2 -0
  68. package/template/src/modules/app/facade.ts +21 -0
  69. package/template/src/preload.ts +25 -2
  70. package/template/src/ui/src/App.vue +4 -2
  71. package/template/src/ui/src/app.ts +38 -23
  72. package/template/src/ui/src/bindings.d.ts +18 -16
  73. package/template/src/ui/src/components/Button.vue +34 -32
  74. package/template/src/ui/src/components/Checkbox.vue +26 -29
  75. package/template/src/ui/src/components/Input.vue +221 -227
  76. package/template/src/ui/src/components/InputGroup.vue +141 -0
  77. package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
  78. package/template/src/ui/src/components/Modal.vue +65 -55
  79. package/template/src/ui/src/components/Spinner.vue +44 -42
  80. package/template/src/ui/src/components/Switch.vue +62 -65
  81. package/template/src/ui/src/components/TextArea.vue +108 -121
  82. package/template/src/ui/src/components/Toast.vue +55 -56
  83. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
  84. package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
  85. package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
  86. package/template/src/ui/src/components/datatable/index.vue +336 -258
  87. package/template/src/ui/src/env.d.ts +16 -13
  88. package/template/src/ui/src/global.d.ts +21 -2
  89. package/template/src/ui/src/helpers/nformatter.ts +12 -10
  90. package/template/src/ui/src/pages/dashboard/index.vue +690 -687
  91. package/template/src/ui/src/plugins/browserDetect.ts +57 -0
  92. package/template/src/ui/src/plugins/gum.ts +576 -549
  93. package/template/src/ui/src/plugins/pulse.ts +2 -0
  94. package/template/src/ui/src/plugins/routeProgress.ts +89 -0
  95. package/template/src/ui/src/router/index.ts +44 -25
  96. package/template/src/ui/src/stores/example.ts +2 -0
  97. package/template/src/ui/vite.config.ts +40 -38
  98. package/template/src/window/app-menu.ts +89 -87
  99. package/template/src/window/config.ts +14 -12
  100. package/template/src/window/context-menu.ts +23 -21
  101. package/template/src/window/dialogs.ts +92 -90
  102. package/template/src/window/manager.ts +2 -0
  103. package/template/src/window/native.ts +47 -45
  104. package/template/src/window/tray.ts +132 -130
@@ -1,90 +1,92 @@
1
- import { BrowserWindow, dialog } from "electron";
2
-
3
- // ---------------------------------------------------------------------------
4
- // Message dialogs (confirm / alert / prompt)
5
- // ---------------------------------------------------------------------------
6
-
7
- export async function confirmDialog(message: string): Promise<boolean> {
8
- const result = await dialog.showMessageBox({
9
- type: "question",
10
- buttons: ["Cancel", "OK"],
11
- title: "Confirm",
12
- message: message
13
- });
14
-
15
- return result.response === 1;
16
- }
17
-
18
- export async function alertDialog(message: string): Promise<void> {
19
- await dialog.showMessageBox({
20
- type: "info",
21
- title: "Alert",
22
- message: message
23
- });
24
- }
25
-
26
- export interface PickOpenOptions {
27
- title?: string;
28
- filter?: string; // Electron uses extensions array, but we can parse your string
29
- }
30
-
31
- export interface PickSaveOptions {
32
- title?: string;
33
- defaultName?: string;
34
- filter?: string;
35
- }
36
-
37
- export interface PickFolderOptions {
38
- title?: string;
39
- }
40
-
41
- // Helper to convert "All files (*.*)|*.*" to Electron format: [{ name: 'All files', extensions: ['*'] }]
42
- export function parseFilter(filterStr?: string) {
43
- if (!filterStr) return undefined;
44
- const parts = filterStr.split("|");
45
- const filters = [];
46
- for (let i = 0; i < parts.length; i += 2) {
47
- if (parts[i] && parts[i + 1]) {
48
- filters.push({
49
- name: parts[i].replace(/\s*\(.*?\)\s*/, ""),
50
- extensions: parts[i + 1].split(";").map((ext) => ext.replace("*.", "").replace("*", "*"))
51
- });
52
- }
53
- }
54
- return filters.length > 0 ? filters : undefined;
55
- }
56
-
57
- async function pickOpenPath(options: PickOpenOptions = {}): Promise<string | null> {
58
- const win = BrowserWindow.getFocusedWindow();
59
- const result = await dialog.showOpenDialog(win!, {
60
- title: options.title ?? "Open a file",
61
- properties: ["openFile"],
62
- filters: parseFilter(options.filter)
63
- });
64
- return result.canceled ? null : result.filePaths[0];
65
- }
66
-
67
- async function pickSavePath(options: PickSaveOptions = {}): Promise<string | null> {
68
- const win = BrowserWindow.getFocusedWindow();
69
- const result = await dialog.showSaveDialog(win!, {
70
- title: options.title ?? "Save as",
71
- defaultPath: options.defaultName,
72
- filters: parseFilter(options.filter)
73
- });
74
- return result.canceled ? null : result.filePath || null;
75
- }
76
-
77
- async function pickFolder(options: PickFolderOptions = {}): Promise<string | null> {
78
- const win = BrowserWindow.getFocusedWindow();
79
- const result = await dialog.showOpenDialog(win!, {
80
- title: options.title ?? "Choose a folder",
81
- properties: ["openDirectory"]
82
- });
83
- return result.canceled ? null : result.filePaths[0];
84
- }
85
-
86
- export const pickers = {
87
- open: pickOpenPath,
88
- save: pickSavePath,
89
- folder: pickFolder
90
- };
1
+ // ./src/window/dialogs.ts
2
+
3
+ import { BrowserWindow, dialog } from "electron";
4
+
5
+ // ---------------------------------------------------------------------------
6
+ // Message dialogs (confirm / alert / prompt)
7
+ // ---------------------------------------------------------------------------
8
+
9
+ export async function confirmDialog(message: string): Promise<boolean> {
10
+ const result = await dialog.showMessageBox({
11
+ type: "question",
12
+ buttons: ["Cancel", "OK"],
13
+ title: "Confirm",
14
+ message: message
15
+ });
16
+
17
+ return result.response === 1;
18
+ }
19
+
20
+ export async function alertDialog(message: string): Promise<void> {
21
+ await dialog.showMessageBox({
22
+ type: "info",
23
+ title: "Alert",
24
+ message: message
25
+ });
26
+ }
27
+
28
+ export interface PickOpenOptions {
29
+ title?: string;
30
+ filter?: string; // Electron uses extensions array, but we can parse your string
31
+ }
32
+
33
+ export interface PickSaveOptions {
34
+ title?: string;
35
+ defaultName?: string;
36
+ filter?: string;
37
+ }
38
+
39
+ export interface PickFolderOptions {
40
+ title?: string;
41
+ }
42
+
43
+ // Helper to convert "All files (*.*)|*.*" to Electron format: [{ name: 'All files', extensions: ['*'] }]
44
+ export function parseFilter(filterStr?: string) {
45
+ if (!filterStr) return undefined;
46
+ const parts = filterStr.split("|");
47
+ const filters = [];
48
+ for (let i = 0; i < parts.length; i += 2) {
49
+ if (parts[i] && parts[i + 1]) {
50
+ filters.push({
51
+ name: parts[i].replace(/\s*\(.*?\)\s*/, ""),
52
+ extensions: parts[i + 1].split(";").map((ext) => ext.replace("*.", "").replace("*", "*"))
53
+ });
54
+ }
55
+ }
56
+ return filters.length > 0 ? filters : undefined;
57
+ }
58
+
59
+ async function pickOpenPath(options: PickOpenOptions = {}): Promise<string | null> {
60
+ const win = BrowserWindow.getFocusedWindow();
61
+ const result = await dialog.showOpenDialog(win!, {
62
+ title: options.title ?? "Open a file",
63
+ properties: ["openFile"],
64
+ filters: parseFilter(options.filter)
65
+ });
66
+ return result.canceled ? null : result.filePaths[0];
67
+ }
68
+
69
+ async function pickSavePath(options: PickSaveOptions = {}): Promise<string | null> {
70
+ const win = BrowserWindow.getFocusedWindow();
71
+ const result = await dialog.showSaveDialog(win!, {
72
+ title: options.title ?? "Save as",
73
+ defaultPath: options.defaultName,
74
+ filters: parseFilter(options.filter)
75
+ });
76
+ return result.canceled ? null : result.filePath || null;
77
+ }
78
+
79
+ async function pickFolder(options: PickFolderOptions = {}): Promise<string | null> {
80
+ const win = BrowserWindow.getFocusedWindow();
81
+ const result = await dialog.showOpenDialog(win!, {
82
+ title: options.title ?? "Choose a folder",
83
+ properties: ["openDirectory"]
84
+ });
85
+ return result.canceled ? null : result.filePaths[0];
86
+ }
87
+
88
+ export const pickers = {
89
+ open: pickOpenPath,
90
+ save: pickSavePath,
91
+ folder: pickFolder
92
+ };
@@ -1,3 +1,5 @@
1
+ // ./src/window/manager.ts
2
+
1
3
  import path from "node:path";
2
4
  import { app, BrowserWindow, nativeImage } from "electron";
3
5
  import { closeDatabase } from "@/core/database/connection";
@@ -1,45 +1,47 @@
1
- import type { ChromeParts } from "@config/winsetup";
2
- import { resolveChrome } from "@config/winsetup";
3
- import { defaultMenuItems, installAppMenu, removeAppMenu } from "./app-menu";
4
- import { disableContextMenu, installContextMenu } from "./context-menu";
5
- import { alertDialog, confirmDialog } from "./dialogs";
6
- import type { DesktopWindow } from "./manager";
7
- import { createAppTray, createHeadlessTray, createTray, hideDock, isTrayAvailable } from "./tray";
8
-
9
- export type { MenuActionItem, MenuItem, MenuRole, MenuSubmenu } from "@/window/app-menu";
10
- export type { DesktopTray } from "@/window/tray";
11
- export type { ChromeParts };
12
-
13
- /**
14
- * Install desktop chrome for a window. Pass `parts` for granular control;
15
- * defaults to all enabled (backward compatible).
16
- */
17
- function setupDesktopChrome(
18
- win: DesktopWindow,
19
- parts: Required<ChromeParts> = { appMenu: true, contextMenu: true, tray: true },
20
- ): void {
21
- if (parts.appMenu) installAppMenu(win);
22
- else removeAppMenu(win);
23
- if (parts.contextMenu) installContextMenu(win);
24
- else disableContextMenu(win);
25
- if (parts.tray) createAppTray();
26
- }
27
-
28
- export const chrome = {
29
- // Tray
30
- createTray,
31
- isTrayAvailable,
32
- createAppTray,
33
- createHeadlessTray,
34
- hideDock,
35
- // Dialogs
36
- confirmDialog,
37
- alertDialog,
38
- // Menu
39
- defaultMenuItems,
40
- installAppMenu,
41
- installContextMenu,
42
- // Orchestration
43
- setupDesktopChrome,
44
- resolveChrome
45
- };
1
+ // ./src/window/native.ts
2
+
3
+ import type { ChromeParts } from "@config/winsetup";
4
+ import { resolveChrome } from "@config/winsetup";
5
+ import { defaultMenuItems, installAppMenu, removeAppMenu } from "./app-menu";
6
+ import { disableContextMenu, installContextMenu } from "./context-menu";
7
+ import { alertDialog, confirmDialog } from "./dialogs";
8
+ import type { DesktopWindow } from "./manager";
9
+ import { createAppTray, createHeadlessTray, createTray, hideDock, isTrayAvailable } from "./tray";
10
+
11
+ export type { MenuActionItem, MenuItem, MenuRole, MenuSubmenu } from "@/window/app-menu";
12
+ export type { DesktopTray } from "@/window/tray";
13
+ export type { ChromeParts };
14
+
15
+ /**
16
+ * Install desktop chrome for a window. Pass `parts` for granular control;
17
+ * defaults to all enabled (backward compatible).
18
+ */
19
+ function setupDesktopChrome(
20
+ win: DesktopWindow,
21
+ parts: Required<ChromeParts> = { appMenu: true, contextMenu: true, tray: true },
22
+ ): void {
23
+ if (parts.appMenu) installAppMenu(win);
24
+ else removeAppMenu(win);
25
+ if (parts.contextMenu) installContextMenu(win);
26
+ else disableContextMenu(win);
27
+ if (parts.tray) createAppTray();
28
+ }
29
+
30
+ export const chrome = {
31
+ // Tray
32
+ createTray,
33
+ isTrayAvailable,
34
+ createAppTray,
35
+ createHeadlessTray,
36
+ hideDock,
37
+ // Dialogs
38
+ confirmDialog,
39
+ alertDialog,
40
+ // Menu
41
+ defaultMenuItems,
42
+ installAppMenu,
43
+ installContextMenu,
44
+ // Orchestration
45
+ setupDesktopChrome,
46
+ resolveChrome
47
+ };
@@ -1,130 +1,132 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { app, Menu, nativeImage, Tray } from "electron";
4
- import { config } from "@/core/config";
5
- import { win as winApi } from "@/window/manager";
6
-
7
- export interface DesktopTray extends Tray {}
8
-
9
- let tray: Tray | null = null;
10
-
11
- // 16x16 red dot (known-good data URL) as guaranteed fallback so tray can still appear.
12
- const FALLBACK_TRAY_ICON =
13
- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABYSURBVHgB7ZMxDoAgDEXfQI7gERzFQw5u5BWMg4maNB8WBgeTPqHJb9qfAjgQCLZYkGIgnSWmmOMcRZ6LzF1k65s6UKMo15W1X9mHe3vK+3xM4QcM0wUogx/2yq6l8gAAAABJRU5ErkJggg==";
14
-
15
- function getTrayIconCandidates(): string[] {
16
- // In dev, main bundle runs from out/main so app.getAppPath() can resolve to out/main;
17
- // project assets live at the project root (../../ from out/main). In packaged builds,
18
- // app.getAppPath() points to the app root (or asar root) where src/icons is packaged.
19
- const bases = app.isPackaged
20
- ? [app.getAppPath()]
21
- : [path.resolve(app.getAppPath(), "..", ".."), app.getAppPath(), process.cwd()];
22
-
23
- const candidates: string[] = [];
24
- for (const root of Array.from(new Set(bases))) {
25
- const base = path.join(root, "src", "icons");
26
- candidates.push(
27
- path.join(base, "tray.png"),
28
- path.join(base, "favicon-96x96.png"),
29
- path.join(base, "favicon.ico"),
30
- path.join(base, "web-app-manifest-192x192.png"),
31
- path.join(base, "web-app-manifest-512x512.png"),
32
- );
33
- }
34
- // Last resort: executable icon (Electron icon in dev, app icon when packaged).
35
- candidates.push(process.execPath);
36
- return candidates;
37
- }
38
-
39
- export function createTray(): Tray | undefined {
40
- if (tray && !(tray as any).isDestroyed?.()) return tray;
41
- try {
42
- for (const iconPath of getTrayIconCandidates()) {
43
- try {
44
- // Prefer passing a file path string directly (supported by Electron Tray).
45
- if (fs.existsSync(iconPath)) {
46
- try {
47
- tray = new Tray(iconPath);
48
- return tray;
49
- } catch {}
50
- }
51
- const icon = nativeImage.createFromPath(iconPath);
52
- if (!icon.isEmpty()) {
53
- const size = icon.getSize();
54
- const trayIcon = size.width > 32 ? icon.resize({ width: 16, height: 16 }) : icon;
55
- tray = new Tray(trayIcon);
56
- return tray;
57
- }
58
- } catch {
59
- // try next candidate
60
- }
61
- }
62
-
63
- // Guaranteed fallback so tray still appears even if files/exe icon can't be loaded.
64
- try {
65
- const fallback = nativeImage.createFromDataURL(FALLBACK_TRAY_ICON);
66
- if (!fallback.isEmpty()) {
67
- tray = new Tray(fallback);
68
- return tray;
69
- }
70
- } catch {}
71
-
72
- return undefined;
73
- } catch {
74
- return undefined;
75
- }
76
- }
77
-
78
- export function isTrayAvailable(): boolean {
79
- return true;
80
- }
81
-
82
- export function createAppTray(): Tray | undefined {
83
- const t = createTray();
84
- if (!t) return undefined;
85
-
86
- t.setToolTip(config.appName);
87
-
88
- const contextMenu = Menu.buildFromTemplate([
89
- {
90
- label: "Show window",
91
- click: () => {
92
- winApi.getWindow()?.show();
93
- winApi.getWindow()?.focus();
94
- },
95
- },
96
- {
97
- label: "Open Settings",
98
- click: () => {
99
- void winApi.openWindow({ title: "Settings", width: 420, height: 320 });
100
- },
101
- },
102
- { type: "separator" },
103
- { label: "Quit", click: () => app.quit() },
104
- ]);
105
-
106
- t.setContextMenu(contextMenu);
107
- return t;
108
- }
109
-
110
- export function createHeadlessTray(): Tray | undefined {
111
- const t = createTray();
112
- if (!t) return undefined;
113
-
114
- t.setToolTip(`${config.appName} (headless)`);
115
- t.setContextMenu(
116
- Menu.buildFromTemplate([
117
- { label: `${config.appName} is running - no UI`, enabled: false },
118
- { type: "separator" },
119
- { label: "Quit", click: () => app.quit() },
120
- ]),
121
- );
122
-
123
- return t;
124
- }
125
-
126
- export function hideDock(): void {
127
- if (process.platform === "darwin" && app.dock) {
128
- app.dock.hide();
129
- }
130
- }
1
+ // ./src/window/tray.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { app, Menu, nativeImage, Tray } from "electron";
6
+ import { config } from "@/core/config";
7
+ import { win as winApi } from "@/window/manager";
8
+
9
+ export interface DesktopTray extends Tray {}
10
+
11
+ let tray: Tray | null = null;
12
+
13
+ // 16x16 red dot (known-good data URL) as guaranteed fallback so tray can still appear.
14
+ const FALLBACK_TRAY_ICON =
15
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABYSURBVHgB7ZMxDoAgDEXfQI7gERzFQw5u5BWMg4maNB8WBgeTPqHJb9qfAjgQCLZYkGIgnSWmmOMcRZ6LzF1k65s6UKMo15W1X9mHe3vK+3xM4QcM0wUogx/2yq6l8gAAAABJRU5ErkJggg==";
16
+
17
+ function getTrayIconCandidates(): string[] {
18
+ // In dev, main bundle runs from out/main so app.getAppPath() can resolve to out/main;
19
+ // project assets live at the project root (../../ from out/main). In packaged builds,
20
+ // app.getAppPath() points to the app root (or asar root) where src/icons is packaged.
21
+ const bases = app.isPackaged
22
+ ? [app.getAppPath()]
23
+ : [path.resolve(app.getAppPath(), "..", ".."), app.getAppPath(), process.cwd()];
24
+
25
+ const candidates: string[] = [];
26
+ for (const root of Array.from(new Set(bases))) {
27
+ const base = path.join(root, "src", "icons");
28
+ candidates.push(
29
+ path.join(base, "tray.png"),
30
+ path.join(base, "favicon-96x96.png"),
31
+ path.join(base, "favicon.ico"),
32
+ path.join(base, "web-app-manifest-192x192.png"),
33
+ path.join(base, "web-app-manifest-512x512.png"),
34
+ );
35
+ }
36
+ // Last resort: executable icon (Electron icon in dev, app icon when packaged).
37
+ candidates.push(process.execPath);
38
+ return candidates;
39
+ }
40
+
41
+ export function createTray(): Tray | undefined {
42
+ if (tray && !(tray as any).isDestroyed?.()) return tray;
43
+ try {
44
+ for (const iconPath of getTrayIconCandidates()) {
45
+ try {
46
+ // Prefer passing a file path string directly (supported by Electron Tray).
47
+ if (fs.existsSync(iconPath)) {
48
+ try {
49
+ tray = new Tray(iconPath);
50
+ return tray;
51
+ } catch {}
52
+ }
53
+ const icon = nativeImage.createFromPath(iconPath);
54
+ if (!icon.isEmpty()) {
55
+ const size = icon.getSize();
56
+ const trayIcon = size.width > 32 ? icon.resize({ width: 16, height: 16 }) : icon;
57
+ tray = new Tray(trayIcon);
58
+ return tray;
59
+ }
60
+ } catch {
61
+ // try next candidate
62
+ }
63
+ }
64
+
65
+ // Guaranteed fallback so tray still appears even if files/exe icon can't be loaded.
66
+ try {
67
+ const fallback = nativeImage.createFromDataURL(FALLBACK_TRAY_ICON);
68
+ if (!fallback.isEmpty()) {
69
+ tray = new Tray(fallback);
70
+ return tray;
71
+ }
72
+ } catch {}
73
+
74
+ return undefined;
75
+ } catch {
76
+ return undefined;
77
+ }
78
+ }
79
+
80
+ export function isTrayAvailable(): boolean {
81
+ return true;
82
+ }
83
+
84
+ export function createAppTray(): Tray | undefined {
85
+ const t = createTray();
86
+ if (!t) return undefined;
87
+
88
+ t.setToolTip(config.appName);
89
+
90
+ const contextMenu = Menu.buildFromTemplate([
91
+ {
92
+ label: "Show window",
93
+ click: () => {
94
+ winApi.getWindow()?.show();
95
+ winApi.getWindow()?.focus();
96
+ },
97
+ },
98
+ {
99
+ label: "Open Settings",
100
+ click: () => {
101
+ void winApi.openWindow({ title: "Settings", width: 420, height: 320 });
102
+ },
103
+ },
104
+ { type: "separator" },
105
+ { label: "Quit", click: () => app.quit() },
106
+ ]);
107
+
108
+ t.setContextMenu(contextMenu);
109
+ return t;
110
+ }
111
+
112
+ export function createHeadlessTray(): Tray | undefined {
113
+ const t = createTray();
114
+ if (!t) return undefined;
115
+
116
+ t.setToolTip(`${config.appName} (headless)`);
117
+ t.setContextMenu(
118
+ Menu.buildFromTemplate([
119
+ { label: `${config.appName} is running - no UI`, enabled: false },
120
+ { type: "separator" },
121
+ { label: "Quit", click: () => app.quit() },
122
+ ]),
123
+ );
124
+
125
+ return t;
126
+ }
127
+
128
+ export function hideDock(): void {
129
+ if (process.platform === "darwin" && app.dock) {
130
+ app.dock.hide();
131
+ }
132
+ }