Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit d99d17e

Browse files
authored
#23 from andrinoff/next-next
2 parents 3af652e + f37f204 commit d99d17e

10 files changed

Lines changed: 589 additions & 154 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
dist
23
dist*
34
release
45
package-lock.json

main.js

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,37 @@ const { exec } = require("child_process");
1313
const os = require("os");
1414

1515
let mainWindow = null;
16+
let settingsWindow = null;
1617

1718
// --- App Setup: Create Thumbnail Cache Directory ---
1819
const cacheDir = path.join(app.getPath("userData"), "thumbnails");
1920
if (!fsSync.existsSync(cacheDir)) {
2021
fsSync.mkdirSync(cacheDir, { recursive: true });
2122
}
2223

24+
// --- Settings File Setup ---
25+
const settingsPath = path.join(app.getPath("userData"), "settings.json");
26+
27+
async function getSettings() {
28+
try {
29+
await fs.access(settingsPath);
30+
const settingsFile = await fs.readFile(settingsPath, "utf-8");
31+
return JSON.parse(settingsFile);
32+
} catch (error) {
33+
// If the file doesn't exist or there's an error, return default settings
34+
const defaultSettings = {
35+
theme: "tokyo-night-blue",
36+
openCommand: "CommandOrControl+Shift+P",
37+
};
38+
await saveSettings(defaultSettings);
39+
return defaultSettings;
40+
}
41+
}
42+
43+
async function saveSettings(settings) {
44+
await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2));
45+
}
46+
2347
const run = (cmd) =>
2448
new Promise((resolve, reject) => {
2549
exec(cmd, { maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => {
@@ -64,6 +88,8 @@ function createWindow() {
6488
focusable: true,
6589
});
6690

91+
console.log("Main window created.");
92+
6793
if (process.platform === "darwin") {
6894
app.dock.hide();
6995
}
@@ -79,8 +105,18 @@ function createWindow() {
79105
});
80106
}
81107

82-
app.whenReady().then(() => {
83-
globalShortcut.register("CommandOrControl+Shift+P", () => {
108+
ipcMain.on("toggle-settings", () => {
109+
if (mainWindow) {
110+
mainWindow.webContents.send("toggle-settings");
111+
}
112+
});
113+
114+
app.whenReady().then(async () => {
115+
console.log("App is ready.");
116+
const settings = await getSettings();
117+
console.log("Settings loaded:", settings);
118+
globalShortcut.register(settings.openCommand, () => {
119+
console.log("Global shortcut triggered.");
84120
if (mainWindow) {
85121
mainWindow.close();
86122
} else {
@@ -101,6 +137,50 @@ app.on("will-quit", () => {
101137

102138
// --- IPC Handlers ---
103139

140+
141+
142+
ipcMain.handle("get-settings", async () => {
143+
return await getSettings();
144+
});
145+
146+
ipcMain.handle("save-settings", async (event, settings) => {
147+
await saveSettings(settings);
148+
// You might want to re-register the shortcut if it changed
149+
globalShortcut.unregisterAll();
150+
const newSettings = await getSettings();
151+
globalShortcut.register(newSettings.openCommand, () => {
152+
if (mainWindow) {
153+
mainWindow.close();
154+
} else {
155+
createWindow();
156+
}
157+
});
158+
if (mainWindow) {
159+
mainWindow.webContents.send("theme-updated", newSettings.theme);
160+
}
161+
});
162+
163+
ipcMain.handle("get-themes", async () => {
164+
const themeDir = path.join(__dirname, "src/themes");
165+
try {
166+
const files = await fs.readdir(themeDir);
167+
const themes = await Promise.all(
168+
files.map(async (file) => {
169+
if (file.endsWith(".json")) {
170+
const filePath = path.join(themeDir, file);
171+
const content = await fs.readFile(filePath, "utf-8");
172+
return JSON.parse(content);
173+
}
174+
return null;
175+
})
176+
);
177+
return themes.filter((theme) => theme !== null);
178+
} catch (error) {
179+
console.error(`Error reading theme directory: ${themeDir}`, error);
180+
return [];
181+
}
182+
});
183+
104184
// **FIXED**: Handler to open external links securely in the user's default browser.
105185
ipcMain.handle("open-external-link", async (event, url) => {
106186
await shell.openExternal(url);

preload.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ contextBridge.exposeInMainWorld("api", {
1010
getThumbnail: (imageName) => ipcRenderer.invoke("get-thumbnail", imageName),
1111
openWallpapersFolder: () => ipcRenderer.invoke("open-wallpapers-folder"),
1212
getAppVersion: () => ipcRenderer.invoke("get-app-version"),
13-
// **FIXED**: Expose the method to open external links
1413
openExternalLink: (url) => ipcRenderer.invoke("open-external-link", url),
14+
toggleSettings: () => ipcRenderer.send("toggle-settings"),
15+
getSettings: () => ipcRenderer.invoke("get-settings"),
16+
saveSettings: (settings) => ipcRenderer.invoke("save-settings", settings),
17+
getThemes: () => ipcRenderer.invoke("get-themes"),
18+
onThemeUpdated: (callback) => {
19+
const listener = (event, ...args) => callback(...args);
20+
ipcRenderer.on("theme-updated", listener);
21+
return () => {
22+
ipcRenderer.removeListener("theme-updated", listener);
23+
};
24+
},
1525
});

0 commit comments

Comments
 (0)