-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
167 lines (142 loc) · 3.81 KB
/
index.js
File metadata and controls
167 lines (142 loc) · 3.81 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const {
app,
Tray,
Menu,
BrowserWindow,
ipcMain,
Notification,
} = require("electron");
const {
PARAMS,
VALUE,
MicaBrowserWindow,
IS_WINDOWS_11,
WIN10,
} = require("mica-electron");
const path = require("path");
let mainWindow;
let themeEditorWindow = null;
let tray = null;
app.on("ready", () => {
mainWindow = new MicaBrowserWindow({
width: 1200,
height: 700,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, "/preload.js"),
},
menuBarVisible: false,
frame: false,
show: false,
titleBarStyle: "hidden",
...(process.platform !== "darwin" ? { titleBarOverlay: true } : {}),
});
if (require("electron-squirrel-startup")) app.quit();
mainWindow.setRoundedCorner();
mainWindow.setMicaAcrylicEffect();
mainWindow.setTitleBarOverlay({
color: "rgba(0, 0, 0, 0)", // Transparent background
symbolColor: "rgba(255, 255, 255, 1)", // Default to light symbols (for dark themes)
height: 48,
});
mainWindow.setMinimumSize(1200, 700);
//Menu.setApplicationMenu(null);
mainWindow.loadFile("index.html");
mainWindow.webContents.once("dom-ready", () => {
mainWindow.show(); // Show the window only when DOM is ready
});
mainWindow.on("closed", () => {
mainWindow = null;
if (themeEditorWindow) {
themeEditorWindow.close(); // Close editor if main closes
}
// app.quit()
});
ipcMain.on("show-notification", (event, title, body) => {
showNotification(title, body);
});
ipcMain.on("open-dev-tools", () => {
if (mainWindow) {
mainWindow.webContents.openDevTools();
}
});
ipcMain.on("set-titlebar-overlay", (event, options) => {
if (mainWindow) {
const symbolColor = options.isLight
? "rgba(0, 0, 0, 1)"
: "rgba(255, 255, 255, 1)";
mainWindow.setTitleBarOverlay({
color: "rgba(0, 0, 0, 0)",
symbolColor: symbolColor,
height: 48,
});
}
});
tray = new Tray(path.join(__dirname, "assets/icon.png"));
const contextMenu = Menu.buildFromTemplate([
{
label: "Check for Updates",
click: () => {
console.log("Check for Updates menu item clicked");
if (mainWindow) {
mainWindow.webContents.send("check-for-updates"); // Send to renderer
}
},
},
{ type: "separator" },
{ label: "Quit", click: () => app.quit() },
]);
tray.setToolTip("Iota's Notepad");
tray.setContextMenu(contextMenu);
});
function createThemeEditorWindow() {
if (themeEditorWindow) {
themeEditorWindow.focus();
return;
}
themeEditorWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, "preload.js"),
},
title: "Theme Editor",
autoHideMenuBar: true,
});
themeEditorWindow.maximize();
themeEditorWindow.loadURL("https://vorlie.pages.dev/theme-editor");
themeEditorWindow.on("closed", () => {
themeEditorWindow = null;
});
}
// IPC listener to open the theme editor
ipcMain.on("open-theme-editor", () => {
createThemeEditorWindow();
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
function showNotification(title, body) {
if (Notification.isSupported()) {
let iconPath;
iconPath = path.join(__dirname, "assets", "icon.png");
const notification = new Notification({
title: title,
body: body,
icon: iconPath,
});
notification.on("click", () => {
console.log("Notification clicked");
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
notification.show();
} else {
console.log("Notifications are not supported on this system.");
}
}