Skip to content

Commit 9a3638e

Browse files
committed
Add theme editor button and functionality to open it
1 parent 20d496e commit 9a3638e

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ <h2 class="modal-h2">About</h2>
107107
</div>
108108
<button class="about-button" onclick="checkForUpdates()">Check for Updates</button>
109109
<button class="about-button" id="open-dev-tools" onclick="window.API.openDevTools()">Open DevTools</button>
110+
<button class="about-button" id="open-theme-editor">Open Theme Editor</button>
110111
</div>
111112
</div>
112113
</div>

index.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const { app, Tray, Menu, ipcMain, Notification } = require('electron');
1+
const { app, Tray, Menu, BrowserWindow, ipcMain, Notification } = require('electron');
22
const { PARAMS, VALUE, MicaBrowserWindow, IS_WINDOWS_11, WIN10 } = require('mica-electron');
33
const path = require('path');
44

55
let mainWindow;
6+
let themeEditorWindow = null;
67
let tray = null;
78

89

@@ -74,11 +75,42 @@ app.on('ready', () => {
7475
tray.setContextMenu(contextMenu);
7576
});
7677

78+
function createThemeEditorWindow() {
79+
if (themeEditorWindow) {
80+
themeEditorWindow.focus();
81+
return;
82+
}
83+
84+
themeEditorWindow = new BrowserWindow({
85+
width: 800,
86+
height: 600,
87+
webPreferences: {
88+
contextIsolation: true,
89+
nodeIntegration: false,
90+
preload: path.join(__dirname, 'preload.js'),
91+
},
92+
title: "Theme Editor",
93+
autoHideMenuBar: true,
94+
});
95+
96+
themeEditorWindow.maximize();
97+
98+
themeEditorWindow.loadURL('https://vorlie.pages.dev/theme-editor');
99+
100+
themeEditorWindow.on('closed', () => {
101+
themeEditorWindow = null;
102+
});
103+
}
104+
105+
// IPC listener to open the theme editor
106+
ipcMain.on('open-theme-editor', () => {
107+
createThemeEditorWindow();
108+
});
109+
77110
app.on('window-all-closed', () => {
78111
if (process.platform !== 'darwin') app.quit();
79112
});
80113

81-
82114
function showNotification(title, body) {
83115
if (Notification.isSupported()) {
84116
let iconPath;
@@ -102,5 +134,4 @@ function showNotification(title, body) {
102134
} else {
103135
console.log('Notifications are not supported on this system.');
104136
}
105-
}
106-
137+
}

preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contextBridge.exposeInMainWorld('API', {
66
on: (channel, func) => ipcRenderer.on(channel, func),
77
send: (channel, ...args) => ipcRenderer.send(channel, ...args),
88
removeListener: (channel, func) => ipcRenderer.removeListener(channel, func),
9+
openThemeEditor: () => ipcRenderer.send('open-theme-editor'),
910
versions: {
1011
node: () => process.versions.node,
1112
chrome: () => process.versions.chrome,

src/script.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ document.getElementById('open-dev-tools').addEventListener('click', () => {
189189
window.API.openDevTools();
190190
});
191191

192+
document.getElementById('open-theme-editor').addEventListener('click', () => {
193+
window.API.openThemeEditor();
194+
});
195+
192196
document.addEventListener("DOMContentLoaded", () => {
193197
loadNotes();
194198
checkForUpdates();

0 commit comments

Comments
 (0)