This repository was archived by the owner on Jan 6, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtrayIndex.js
More file actions
132 lines (115 loc) · 3.75 KB
/
trayIndex.js
File metadata and controls
132 lines (115 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// const { ipcRenderer } = require('electron');
import { ipcRenderer } from 'electron';
const getIconKey = (status) => {
switch (status) {
case 'running':
case 'starting':
return 'syncing';
//TODO: consider camelcased strings
case 'error running':
case 'error starting':
case 'error stopping':
case 'notInstalled':
case 'notRunning':
case 'isOutdated':
return 'error';
default:
return status;
}
};
const getStatusText = (status) => {
switch (status) {
case 'notInstalled':
return 'Not Installed';
case 'notRunning':
return 'Not Running';
case 'isOutdated':
return 'Update Now';
default:
return status;
}
};
ipcRenderer.on(
'update-menu',
(event, { nodePackageTrayMenu, podmanMenuItem, statusIcons }) => {
const menuItems = [
...nodePackageTrayMenu.map((item) => ({
name: item.name,
status: item.status,
action: () => ipcRenderer.send('node-package-click', item.id),
})),
...(nodePackageTrayMenu.length >= 1 ? [{ separator: true }] : []),
...(podmanMenuItem.status !== 'isRunning'
? [
{
name: 'Podman',
status: podmanMenuItem.status,
action: () => ipcRenderer.send('podman-click'),
},
{ separator: true },
]
: []),
{
name: 'Open NiceNode',
action: () => ipcRenderer.send('show-main-window'),
},
{ name: 'Quit', action: () => ipcRenderer.send('quit-app') },
];
const container = document.getElementById('menu-container');
container.innerHTML = ''; // Clear existing items
menuItems.forEach((item) => {
if (item.separator) {
const separator = document.createElement('div');
separator.className = 'separator';
container.appendChild(separator);
} else {
const menuItem = document.createElement('div');
menuItem.className = 'menu-item';
if (item.status === 'stopped') {
menuItem.classList.add('stopped');
}
const nameSpan = document.createElement('span');
nameSpan.textContent = item.name;
menuItem.appendChild(nameSpan);
if (item.status) {
const statusContainer = document.createElement('div');
statusContainer.className = 'menu-status-container';
const statusIconContainer = document.createElement('div');
statusIconContainer.className = 'menu-status-icon';
const statusIcon = document.createElement('div');
statusIcon.innerHTML =
statusIcons[getIconKey(item.status)] || statusIcons.default;
statusIcon.className = 'status-icon';
const statusText = document.createElement('div');
statusText.className = 'menu-status';
statusText.textContent = getStatusText(item.status);
statusIconContainer.appendChild(statusIcon);
statusContainer.appendChild(statusIconContainer);
statusContainer.appendChild(statusText);
menuItem.appendChild(statusContainer);
}
menuItem.addEventListener('click', item.action);
container.appendChild(menuItem);
}
});
ipcRenderer.send('adjust-height', document.body.scrollHeight);
},
);
ipcRenderer.on('set-theme', (event, theme) => {
applyTheme(theme);
});
// Apply theme-based styles
const applyTheme = (theme) => {
const body = document.body;
const menuItems = document.querySelectorAll('.menu-item');
if (theme === 'dark') {
body.classList.add('dark');
body.classList.remove('light');
} else {
body.classList.add('light');
body.classList.remove('dark');
}
};
ipcRenderer.on('update-menu', (event, updatedItems) => {
// Update menu items if necessary
});