@niyamulahsan/create-deskapp 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
- {
2
- "name": "@niyamulahsan/create-deskapp",
3
- "version": "1.2.3",
4
- "description": "Scaffold a new Deskapp (Electron + Vue + npm) project",
5
- "type": "module",
6
- "bin": {
7
- "create-deskapp": "./bin/create.js"
8
- },
9
- "files": [
10
- "bin",
11
- "template",
12
- "template.manifest.json",
13
- "src"
14
- ],
15
- "license": "MIT"
16
- }
1
+ {
2
+ "name": "@niyamulahsan/create-deskapp",
3
+ "version": "1.2.5",
4
+ "description": "Scaffold a new Deskapp (Electron + Vue + npm) project",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-deskapp": "./bin/create.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "template",
12
+ "template.manifest.json",
13
+ "src"
14
+ ],
15
+ "license": "MIT"
16
+ }
@@ -80,8 +80,7 @@
80
80
  },
81
81
  "win": {
82
82
  "icon": "src/icons/web-app-manifest-512x512.png",
83
- "target": "nsis",
84
- "signAndEditExecutable": false
83
+ "target": "nsis"
85
84
  },
86
85
  "nsis": {
87
86
  "oneClick": false,
@@ -67,7 +67,7 @@ export function resolveChrome(chrome: WindowPreset["chrome"]): Required<ChromePa
67
67
  return {
68
68
  appMenu: !!chrome.appMenu,
69
69
  contextMenu: !!chrome.contextMenu,
70
- tray: !!chrome.tray,
70
+ tray: !!chrome.tray
71
71
  };
72
72
  }
73
73
 
@@ -76,9 +76,7 @@ if (!gotLock) {
76
76
 
77
77
  if (isMain) {
78
78
  const chromeParts = chrome.resolveChrome(preset.chrome);
79
- if (chromeParts.appMenu || chromeParts.contextMenu || chromeParts.tray) {
80
- chrome.setupDesktopChrome(created, chromeParts);
81
- }
79
+ chrome.setupDesktopChrome(created, chromeParts);
82
80
  }
83
81
  isMain = false;
84
82
 
@@ -1,148 +1,180 @@
1
- import { io, type Socket } from "socket.io-client";
2
- import type { App } from "vue";
3
-
4
- declare const __SOCKET_ENABLED__: boolean;
5
-
6
- type EventCallback<T = unknown> = (payload: T) => void;
7
-
8
- type ChannelBinding = {
9
- event: string;
10
- callback: EventCallback;
11
- wrapped: EventCallback;
12
- };
13
-
14
- type PulseChannel = {
15
- listen: <T = unknown>(event: string, callback: EventCallback<T>) => PulseChannel;
16
- stopListening: (event: string, callback?: EventCallback) => PulseChannel;
17
- };
18
-
19
- export type PulseClient = {
20
- connect: () => PulseClient;
21
- disconnect: () => PulseClient;
22
- channel: (name: string) => PulseChannel;
23
- private: (room: string) => PulseChannel;
24
- leave: (room: string) => PulseClient;
25
- };
26
-
27
- function createPulse(): PulseClient {
28
- if (!__SOCKET_ENABLED__) {
29
- const n = (): PulseChannel => ({ listen: () => n(), stopListening: () => n() });
30
- const c: PulseClient = {
31
- connect: () => c,
32
- disconnect: () => c,
33
- channel: n,
34
- private: n,
35
- leave: () => c,
36
- };
37
- return c;
38
- }
39
-
40
- let socket: Socket | null = null;
41
- const channels = new Map<string, ChannelBinding[]>();
42
- const joinedRooms = new Set<string>();
43
-
44
- const socketUrl = () => {
45
- const explicit = import.meta.env.VITE_SOCKET_URL || import.meta.env.VITE_API_URL;
46
- if (explicit) return explicit;
47
- return window.location.origin;
48
- };
49
-
50
- const ensureConnected = () => {
51
- if (socket) return socket;
52
-
53
- socket = io(socketUrl(), {
54
- withCredentials: true,
55
- transports: ["websocket", "polling"],
56
- });
57
-
58
- socket.on("connect", () => {
59
- for (const room of joinedRooms) {
60
- socket?.emit("join", room);
61
- }
62
- });
63
-
64
- return socket;
65
- };
66
-
67
- const channel = (name: string): PulseChannel => {
68
- const room = String(name).trim();
69
- if (!room) throw new Error("Channel name is required");
70
-
71
- const currentSocket = ensureConnected();
72
- joinedRooms.add(room);
73
- currentSocket.emit("join", room);
74
-
75
- const api: PulseChannel = {
76
- listen: <T = unknown>(event: string, callback: EventCallback<T>) => {
77
- const wrapped = (payload: unknown) => callback(payload as T);
78
- const bindings = channels.get(room) || [];
79
- bindings.push({ event, callback: callback as EventCallback, wrapped });
80
- channels.set(room, bindings);
81
- currentSocket.on(event, wrapped);
82
- return api;
83
- },
84
- stopListening: (event: string, callback?: EventCallback) => {
85
- const bindings = channels.get(room) || [];
86
- const kept: ChannelBinding[] = [];
87
-
88
- for (const binding of bindings) {
89
- const matchesEvent = binding.event === event;
90
- const matchesCallback = !callback || binding.callback === callback;
91
- if (matchesEvent && matchesCallback) {
92
- currentSocket.off(binding.event, binding.wrapped);
93
- } else {
94
- kept.push(binding);
95
- }
96
- }
97
-
98
- if (kept.length > 0) channels.set(room, kept);
99
- else channels.delete(room);
100
- return api;
101
- },
102
- };
103
-
104
- return api;
105
- };
106
-
107
- const pulse: PulseClient = {
108
- connect: () => {
109
- ensureConnected();
110
- return pulse;
111
- },
112
- disconnect: () => {
113
- socket?.disconnect();
114
- socket = null;
115
- return pulse;
116
- },
117
- channel,
118
- private: (room: string) => channel(`private:${room}`),
119
- leave: (room: string) => {
120
- if (!socket) return pulse;
121
-
122
- const bindings = channels.get(room) || [];
123
- for (const binding of bindings) {
124
- socket.off(binding.event, binding.wrapped);
125
- }
126
-
127
- channels.delete(room);
128
- joinedRooms.delete(room);
129
- return pulse;
130
- },
131
- };
132
-
133
- return pulse;
134
- }
135
-
136
- export const pulse = createPulse();
137
-
138
- export const PulsePlugin = {
139
- install(app: App) {
140
- app.config.globalProperties.$pulse = pulse;
141
- },
142
- };
143
-
144
- declare module "vue" {
145
- interface ComponentCustomProperties {
146
- $pulse: PulseClient;
147
- }
1
+ import { io, type Socket } from "socket.io-client";
2
+ import type { App } from "vue";
3
+
4
+ declare const __SOCKET_ENABLED__: boolean;
5
+
6
+ type EventCallback<T = unknown> = (payload: T) => void;
7
+
8
+ // Access token (or a getter returning one) sent with the Socket.IO handshake.
9
+ // The desktop client cannot send the httpOnly auth cookie, so the server reads
10
+ // this bare JWT from `handshake.auth.token`. A getter is preferred because it
11
+ // is resolved on every (re)connect.
12
+ export type PulseToken = string | null | (() => string | null);
13
+
14
+ type ChannelBinding = {
15
+ event: string;
16
+ callback: EventCallback;
17
+ wrapped: EventCallback;
18
+ };
19
+
20
+ type PulseChannel = {
21
+ listen: <T = unknown>(event: string, callback: EventCallback<T>) => PulseChannel;
22
+ stopListening: (event: string, callback?: EventCallback) => PulseChannel;
23
+ };
24
+
25
+ export type PulseClient = {
26
+ connect: () => PulseClient;
27
+ disconnect: () => PulseClient;
28
+ setToken: (token: PulseToken) => PulseClient;
29
+ channel: (name: string) => PulseChannel;
30
+ private: (room: string) => PulseChannel;
31
+ leave: (room: string) => PulseClient;
32
+ };
33
+
34
+ function createPulse(): PulseClient {
35
+ if (!__SOCKET_ENABLED__) {
36
+ const n = (): PulseChannel => ({ listen: () => n(), stopListening: () => n() });
37
+ const c: PulseClient = {
38
+ connect: () => c,
39
+ disconnect: () => c,
40
+ setToken: () => c,
41
+ channel: n,
42
+ private: n,
43
+ leave: () => c,
44
+ };
45
+ return c;
46
+ }
47
+
48
+ let socket: Socket | null = null;
49
+ let tokenSource: PulseToken = null;
50
+ const channels = new Map<string, ChannelBinding[]>();
51
+ const joinedRooms = new Set<string>();
52
+
53
+ // Resolve lazily so every reconnect picks up the current token.
54
+ const resolveToken = () => (typeof tokenSource === "function" ? tokenSource() : tokenSource);
55
+
56
+ const socketUrl = () => {
57
+ const explicit = import.meta.env.VITE_SOCKET_URL || import.meta.env.VITE_API_URL;
58
+ if (explicit) return explicit;
59
+ return window.location.origin;
60
+ };
61
+
62
+ const ensureConnected = () => {
63
+ if (socket) return socket;
64
+
65
+ socket = io(socketUrl(), {
66
+ withCredentials: true,
67
+ transports: ["websocket", "polling"],
68
+ auth: (callback) => {
69
+ const token = resolveToken();
70
+ callback(token ? { token } : {});
71
+ },
72
+ });
73
+
74
+ socket.on("connect", () => {
75
+ for (const room of joinedRooms) {
76
+ socket?.emit("join", room);
77
+ }
78
+ });
79
+
80
+ return socket;
81
+ };
82
+
83
+ const channel = (name: string): PulseChannel => {
84
+ const room = String(name).trim();
85
+ if (!room) throw new Error("Channel name is required");
86
+
87
+ const currentSocket = ensureConnected();
88
+ joinedRooms.add(room);
89
+ currentSocket.emit("join", room);
90
+
91
+ const api: PulseChannel = {
92
+ listen: <T = unknown>(event: string, callback: EventCallback<T>) => {
93
+ const wrapped = (payload: unknown) => callback(payload as T);
94
+ const bindings = channels.get(room) || [];
95
+ bindings.push({ event, callback: callback as EventCallback, wrapped });
96
+ channels.set(room, bindings);
97
+ currentSocket.on(event, wrapped);
98
+ return api;
99
+ },
100
+ stopListening: (event: string, callback?: EventCallback) => {
101
+ const bindings = channels.get(room) || [];
102
+ const kept: ChannelBinding[] = [];
103
+
104
+ for (const binding of bindings) {
105
+ const matchesEvent = binding.event === event;
106
+ const matchesCallback = !callback || binding.callback === callback;
107
+ if (matchesEvent && matchesCallback) {
108
+ currentSocket.off(binding.event, binding.wrapped);
109
+ } else {
110
+ kept.push(binding);
111
+ }
112
+ }
113
+
114
+ if (kept.length > 0) channels.set(room, kept);
115
+ else channels.delete(room);
116
+ return api;
117
+ },
118
+ };
119
+
120
+ return api;
121
+ };
122
+
123
+ const pulse: PulseClient = {
124
+ connect: () => {
125
+ ensureConnected();
126
+ return pulse;
127
+ },
128
+ disconnect: () => {
129
+ socket?.disconnect();
130
+ socket = null;
131
+ return pulse;
132
+ },
133
+ setToken: (token: PulseToken) => {
134
+ tokenSource = token;
135
+ if (socket) {
136
+ // Force a new handshake with the updated credentials. The connect
137
+ // handler re-joins every room in joinedRooms.
138
+ socket.disconnect().connect();
139
+ }
140
+ return pulse;
141
+ },
142
+ channel,
143
+ private: (room: string) => channel(`private:${room}`),
144
+ leave: (room: string) => {
145
+ const name = String(room).trim();
146
+ if (!name) return pulse;
147
+
148
+ joinedRooms.delete(name);
149
+ const bindings = channels.get(name) || [];
150
+ channels.delete(name);
151
+
152
+ if (socket) {
153
+ // Tell the server too: dropping listeners alone leaves the socket
154
+ // subscribed and still receiving that room's events.
155
+ socket.emit("leave", name);
156
+ for (const binding of bindings) {
157
+ socket.off(binding.event, binding.wrapped);
158
+ }
159
+ }
160
+
161
+ return pulse;
162
+ },
163
+ };
164
+
165
+ return pulse;
166
+ }
167
+
168
+ export const pulse = createPulse();
169
+
170
+ export const PulsePlugin = {
171
+ install(app: App) {
172
+ app.config.globalProperties.$pulse = pulse;
173
+ },
174
+ };
175
+
176
+ declare module "vue" {
177
+ interface ComponentCustomProperties {
178
+ $pulse: PulseClient;
179
+ }
148
180
  }
@@ -1,6 +1,12 @@
1
1
  import { Menu } from "electron";
2
2
  import { type DesktopWindow, win as winApi } from "@/window/manager";
3
3
 
4
+ export function removeAppMenu(win: DesktopWindow): void {
5
+ win.setMenu(null);
6
+ // On Windows/Linux this controls the application menu bar.
7
+ Menu.setApplicationMenu(null);
8
+ }
9
+
4
10
  export interface MenuRole {
5
11
  role: string;
6
12
  }
@@ -12,3 +12,10 @@ export function installContextMenu(win: DesktopWindow): void {
12
12
  menu.popup({ window: win });
13
13
  });
14
14
  }
15
+
16
+ export function disableContextMenu(win: DesktopWindow): void {
17
+ // Suppress default/custom context menu when explicitly disabled.
18
+ win.webContents.on("context-menu", (event) => {
19
+ event.preventDefault();
20
+ });
21
+ }
@@ -1,8 +1,34 @@
1
1
  import path from "node:path";
2
- import { app, BrowserWindow } from "electron";
2
+ import { app, BrowserWindow, nativeImage } from "electron";
3
3
  import { closeDatabase } from "@/core/database/connection";
4
4
  import { type WindowPreset, windowConfig, windows as windowPresets } from "@/window/config";
5
5
 
6
+ function resolveWindowIcon(): Electron.NativeImage | string | undefined {
7
+ const bases = app.isPackaged
8
+ ? [app.getAppPath()]
9
+ : [path.resolve(app.getAppPath(), "..", ".."), app.getAppPath(), process.cwd()];
10
+
11
+ const candidates: string[] = [];
12
+ for (const root of Array.from(new Set(bases))) {
13
+ const base = path.join(root, "src", "icons");
14
+ candidates.push(
15
+ path.join(base, "favicon.ico"),
16
+ path.join(base, "web-app-manifest-512x512.png"),
17
+ path.join(base, "web-app-manifest-192x192.png"),
18
+ path.join(base, "favicon-96x96.png"),
19
+ );
20
+ }
21
+
22
+ for (const iconPath of candidates) {
23
+ try {
24
+ const icon = nativeImage.createFromPath(iconPath);
25
+ if (!icon.isEmpty()) return icon;
26
+ } catch {}
27
+ }
28
+ // Fallback: no custom icon found (Electron default will be used).
29
+ return undefined;
30
+ }
31
+
6
32
  // We map your custom options to Electron's expected options
7
33
  export interface BrowserWindowOptions extends WindowPreset {}
8
34
 
@@ -37,6 +63,7 @@ function createWindow(options?: BrowserWindowOptions, name?: string, preloadPath
37
63
  const resolvedPreload = resolvePreloadPath(preloadPath);
38
64
  if (resolvedPreload && !defaultPreloadPath) defaultPreloadPath = resolvedPreload;
39
65
 
66
+ const icon = resolveWindowIcon();
40
67
  const win = new BrowserWindow({
41
68
  title: preset.title,
42
69
  width: preset.width,
@@ -48,12 +75,13 @@ function createWindow(options?: BrowserWindowOptions, name?: string, preloadPath
48
75
  frame: !preset.frameless,
49
76
  transparent: preset.transparentTitlebar ?? false,
50
77
  show: false,
78
+ ...(icon ? { icon } : {}),
51
79
  webPreferences: {
52
80
  preload: resolvedPreload,
53
81
  contextIsolation: true,
54
82
  nodeIntegration: false,
55
- sandbox: false
56
- }
83
+ sandbox: false,
84
+ },
57
85
  });
58
86
 
59
87
  const winId = win.id;
@@ -1,7 +1,7 @@
1
1
  import type { ChromeParts } from "@config/winsetup";
2
2
  import { resolveChrome } from "@config/winsetup";
3
- import { defaultMenuItems, installAppMenu } from "./app-menu";
4
- import { installContextMenu } from "./context-menu";
3
+ import { defaultMenuItems, installAppMenu, removeAppMenu } from "./app-menu";
4
+ import { disableContextMenu, installContextMenu } from "./context-menu";
5
5
  import { alertDialog, confirmDialog } from "./dialogs";
6
6
  import type { DesktopWindow } from "./manager";
7
7
  import { createAppTray, createHeadlessTray, createTray, hideDock, isTrayAvailable } from "./tray";
@@ -14,9 +14,14 @@ export type { ChromeParts };
14
14
  * Install desktop chrome for a window. Pass `parts` for granular control;
15
15
  * defaults to all enabled (backward compatible).
16
16
  */
17
- function setupDesktopChrome(win: DesktopWindow, parts: Required<ChromeParts> = { appMenu: true, contextMenu: true, tray: true }): void {
17
+ function setupDesktopChrome(
18
+ win: DesktopWindow,
19
+ parts: Required<ChromeParts> = { appMenu: true, contextMenu: true, tray: true },
20
+ ): void {
18
21
  if (parts.appMenu) installAppMenu(win);
22
+ else removeAppMenu(win);
19
23
  if (parts.contextMenu) installContextMenu(win);
24
+ else disableContextMenu(win);
20
25
  if (parts.tray) createAppTray();
21
26
  }
22
27
 
@@ -1,3 +1,4 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { app, Menu, nativeImage, Tray } from "electron";
3
4
  import { config } from "@/core/config";
@@ -7,18 +8,68 @@ export interface DesktopTray extends Tray {}
7
8
 
8
9
  let tray: Tray | null = null;
9
10
 
10
- function getTrayIconPath(): string {
11
- // Bundle-safe: resolve from the app root (works in dev and packaged builds).
12
- return path.join(app.getAppPath(), "src", "icons", "tray.png");
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;
13
37
  }
14
38
 
15
39
  export function createTray(): Tray | undefined {
40
+ if (tray && !(tray as any).isDestroyed?.()) return tray;
16
41
  try {
17
- const iconPath = getTrayIconPath();
18
- const icon = nativeImage.createFromPath(iconPath);
19
- if (icon.isEmpty()) return undefined;
20
- tray = new Tray(icon);
21
- return tray;
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;
22
73
  } catch {
23
74
  return undefined;
24
75
  }
@@ -40,16 +91,16 @@ export function createAppTray(): Tray | undefined {
40
91
  click: () => {
41
92
  winApi.getWindow()?.show();
42
93
  winApi.getWindow()?.focus();
43
- }
94
+ },
44
95
  },
45
96
  {
46
97
  label: "Open Settings",
47
98
  click: () => {
48
99
  void winApi.openWindow({ title: "Settings", width: 420, height: 320 });
49
- }
100
+ },
50
101
  },
51
102
  { type: "separator" },
52
- { label: "Quit", click: () => app.quit() }
103
+ { label: "Quit", click: () => app.quit() },
53
104
  ]);
54
105
 
55
106
  t.setContextMenu(contextMenu);
@@ -65,8 +116,8 @@ export function createHeadlessTray(): Tray | undefined {
65
116
  Menu.buildFromTemplate([
66
117
  { label: `${config.appName} is running - no UI`, enabled: false },
67
118
  { type: "separator" },
68
- { label: "Quit", click: () => app.quit() }
69
- ])
119
+ { label: "Quit", click: () => app.quit() },
120
+ ]),
70
121
  );
71
122
 
72
123
  return t;