Skip to content

Commit 101cc7b

Browse files
committed
Update README and version to 1.2.2; refactor code for consistency and add title bar overlay functionality
1 parent 7be9c9f commit 101cc7b

File tree

6 files changed

+83
-41
lines changed

6 files changed

+83
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Iota's Notepad is a simple note-taking application built with Electron. It allow
2121
- **In-app update notifications**: Stay informed when updates are available for the app.
2222
- **Settings modal**: Access app settings for customizing functionality and preferences.
2323
- **12-hour and 24-hour time formats**: Choose between 12-hour and 24-hour time format for note timestamps.
24-
- **Selectable Catppuccin Mocha, Frappe, and Macchiato flavors**: Choose from three Catppuccin theme flavors for a personalized interface.
24+
- **Customizable UI colors**: Customize the UI colors to match your preferences.
2525
- **Import and apply custom themes**: Customize the UI colors by importing and applying your own themes.
2626
- **Developer Options**: Access DevTools.
2727

index.js

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,107 @@
1-
const { app, Tray, Menu, BrowserWindow, ipcMain, Notification } = require('electron');
2-
const { PARAMS, VALUE, MicaBrowserWindow, IS_WINDOWS_11, WIN10 } = require('mica-electron');
3-
const path = require('path');
1+
const {
2+
app,
3+
Tray,
4+
Menu,
5+
BrowserWindow,
6+
ipcMain,
7+
Notification,
8+
} = require("electron");
9+
const {
10+
PARAMS,
11+
VALUE,
12+
MicaBrowserWindow,
13+
IS_WINDOWS_11,
14+
WIN10,
15+
} = require("mica-electron");
16+
const path = require("path");
417

518
let mainWindow;
619
let themeEditorWindow = null;
720
let tray = null;
821

9-
10-
app.on('ready', () => {
22+
app.on("ready", () => {
1123
mainWindow = new MicaBrowserWindow({
1224
width: 1200,
1325
height: 700,
1426
webPreferences: {
1527
contextIsolation: true,
1628
nodeIntegration: false,
17-
preload: __dirname + '/preload.js',
29+
preload: path.join(__dirname, "/preload.js"),
1830
},
1931
menuBarVisible: false,
2032
frame: false,
2133
show: false,
22-
titleBarStyle: 'hidden',
23-
...(process.platform !== 'darwin' ? { titleBarOverlay: true } : {})
34+
titleBarStyle: "hidden",
35+
...(process.platform !== "darwin" ? { titleBarOverlay: true } : {}),
2436
});
2537

26-
if (require('electron-squirrel-startup')) app.quit();
38+
if (require("electron-squirrel-startup")) app.quit();
2739

2840
mainWindow.setRoundedCorner();
2941
mainWindow.setMicaAcrylicEffect();
3042

3143
mainWindow.setTitleBarOverlay({
32-
color: 'rgba(0, 0, 0, 0)', // Transparent background
33-
symbolColor: 'rgba(255, 255, 255, 1)', // Symbol color
34-
height: 48
44+
color: "rgba(0, 0, 0, 0)", // Transparent background
45+
symbolColor: "rgba(255, 255, 255, 1)", // Default to light symbols (for dark themes)
46+
height: 48,
3547
});
3648

3749
mainWindow.setMinimumSize(1200, 700);
3850

3951
//Menu.setApplicationMenu(null);
4052

41-
mainWindow.loadFile('index.html');
53+
mainWindow.loadFile("index.html");
4254

43-
mainWindow.webContents.once('dom-ready', () => {
55+
mainWindow.webContents.once("dom-ready", () => {
4456
mainWindow.show(); // Show the window only when DOM is ready
4557
});
4658

47-
mainWindow.on('closed', () => {
48-
app.quit();
59+
mainWindow.on("closed", () => {
60+
mainWindow = null;
61+
if (themeEditorWindow) {
62+
themeEditorWindow.close(); // Close editor if main closes
63+
}
64+
// app.quit()
4965
});
5066

51-
ipcMain.on('show-notification', (event, title, body) => {
67+
ipcMain.on("show-notification", (event, title, body) => {
5268
showNotification(title, body);
5369
});
5470

55-
ipcMain.on('open-dev-tools', () => {
71+
ipcMain.on("open-dev-tools", () => {
5672
if (mainWindow) {
5773
mainWindow.webContents.openDevTools();
5874
}
5975
});
6076

61-
tray = new Tray(path.join(__dirname, 'assets/icon.png'));
77+
ipcMain.on("set-titlebar-overlay", (event, options) => {
78+
if (mainWindow) {
79+
const symbolColor = options.isLight
80+
? "rgba(0, 0, 0, 1)"
81+
: "rgba(255, 255, 255, 1)";
82+
mainWindow.setTitleBarOverlay({
83+
color: "rgba(0, 0, 0, 0)",
84+
symbolColor: symbolColor,
85+
height: 48,
86+
});
87+
}
88+
});
89+
90+
tray = new Tray(path.join(__dirname, "assets/icon.png"));
6291
const contextMenu = Menu.buildFromTemplate([
6392
{
64-
label: 'Check for Updates', click: () => {
93+
label: "Check for Updates",
94+
click: () => {
6595
console.log("Check for Updates menu item clicked");
6696
if (mainWindow) {
67-
mainWindow.webContents.send('check-for-updates'); // Send to renderer
97+
mainWindow.webContents.send("check-for-updates"); // Send to renderer
6898
}
69-
}
99+
},
70100
},
71-
{ type: 'separator' },
72-
{ label: 'Quit', click: () => app.quit() }
101+
{ type: "separator" },
102+
{ label: "Quit", click: () => app.quit() },
73103
]);
74-
tray.setToolTip('Iota\'s Notepad');
104+
tray.setToolTip("Iota's Notepad");
75105
tray.setContextMenu(contextMenu);
76106
});
77107

@@ -87,43 +117,43 @@ function createThemeEditorWindow() {
87117
webPreferences: {
88118
contextIsolation: true,
89119
nodeIntegration: false,
90-
preload: path.join(__dirname, 'preload.js'),
120+
preload: path.join(__dirname, "preload.js"),
91121
},
92122
title: "Theme Editor",
93123
autoHideMenuBar: true,
94124
});
95125

96126
themeEditorWindow.maximize();
97127

98-
themeEditorWindow.loadURL('https://vorlie.pages.dev/theme-editor');
128+
themeEditorWindow.loadURL("https://vorlie.pages.dev/theme-editor");
99129

100-
themeEditorWindow.on('closed', () => {
130+
themeEditorWindow.on("closed", () => {
101131
themeEditorWindow = null;
102132
});
103133
}
104134

105135
// IPC listener to open the theme editor
106-
ipcMain.on('open-theme-editor', () => {
136+
ipcMain.on("open-theme-editor", () => {
107137
createThemeEditorWindow();
108138
});
109139

110-
app.on('window-all-closed', () => {
111-
if (process.platform !== 'darwin') app.quit();
140+
app.on("window-all-closed", () => {
141+
if (process.platform !== "darwin") app.quit();
112142
});
113143

114144
function showNotification(title, body) {
115145
if (Notification.isSupported()) {
116146
let iconPath;
117-
iconPath = path.join(__dirname, 'assets', 'icon.png');
147+
iconPath = path.join(__dirname, "assets", "icon.png");
118148

119149
const notification = new Notification({
120150
title: title,
121151
body: body,
122152
icon: iconPath,
123153
});
124154

125-
notification.on('click', () => {
126-
console.log('Notification clicked');
155+
notification.on("click", () => {
156+
console.log("Notification clicked");
127157
if (mainWindow) {
128158
if (mainWindow.isMinimized()) mainWindow.restore();
129159
mainWindow.focus();
@@ -132,6 +162,6 @@ function showNotification(title, body) {
132162

133163
notification.show();
134164
} else {
135-
console.log('Notifications are not supported on this system.');
165+
console.log("Notifications are not supported on this system.");
136166
}
137-
}
167+
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iotas-notepad",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"main": "index.js",
55
"scripts": {
66
"electron": "electron .",

preload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ contextBridge.exposeInMainWorld('API', {
1111
node: () => process.versions.node,
1212
chrome: () => process.versions.chrome,
1313
electron: () => process.versions.electron,
14-
iotanotepad: () => "1.2.1"
14+
iotanotepad: () => "1.2.2"
1515
},
1616
});

src/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ const defaultThemes = {
185185
}
186186
};
187187

188+
function sendTitleBarUpdate(isLight) {
189+
window.API.send('set-titlebar-overlay', { isLight: isLight });
190+
}
191+
188192
document.getElementById('open-dev-tools').addEventListener('click', () => {
189193
window.API.openDevTools();
190194
});
@@ -444,8 +448,16 @@ function loadTheme(themeName) {
444448
const theme = customThemes[themeName] || defaultThemes[themeName];
445449
if (theme) {
446450
applyTheme(theme);
451+
452+
const isLightTheme = themeName.toLowerCase().includes('latte') || themeName.toLowerCase().includes('light');
453+
//const useLightSymbols = themeName.toLowerCase().includes('dark');
454+
sendTitleBarUpdate(isLightTheme);
447455
} else {
456+
//console.warn(`Theme ${themeName} not found.`);
448457
document.documentElement.setAttribute('data-theme', themeName);
458+
//const defaultThemeName = 'mocha';
459+
//applyTheme(defaultThemes[defaultThemeName]);
460+
//sendTitleBarUpdate(false);
449461
}
450462
}
451463

0 commit comments

Comments
 (0)