notes API cleanup
This commit is contained in:
@@ -61,9 +61,7 @@ const updateNote = (relativePath, content) => {
|
||||
fs.writeFileSync(fullPath, content, "utf-8");
|
||||
return true;
|
||||
};
|
||||
const notes = {
|
||||
ensureBaseDir,
|
||||
sanitizeRelativePath,
|
||||
const notesAPI = {
|
||||
readAllNotesRecursive,
|
||||
createNote,
|
||||
createDirectory,
|
||||
@@ -123,27 +121,18 @@ electron.app.whenReady().then(() => {
|
||||
utils.optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
createWindow();
|
||||
notes.ensureBaseDir();
|
||||
ensureBaseDir();
|
||||
electron.app.on("activate", function() {
|
||||
if (electron.BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
electron.ipcMain.on("open-note-window", (_, noteId) => {
|
||||
createNoteWindow(noteId);
|
||||
});
|
||||
electron.ipcMain.handle("notes:list", () => {
|
||||
return notes.readAllNotesRecursive();
|
||||
});
|
||||
electron.ipcMain.handle("notes:create", (_, { path: path2, content }) => {
|
||||
return notes.createNote(path2, content);
|
||||
});
|
||||
electron.ipcMain.handle("notes:createDir", (_, path2) => {
|
||||
return notes.createDirectory(path2);
|
||||
});
|
||||
electron.ipcMain.handle("notes:read", (_, path2) => {
|
||||
return notes.readNote(path2);
|
||||
});
|
||||
electron.ipcMain.handle("notes:update", (_, { path: path2, content }) => {
|
||||
return notes.updateNote(path2, content);
|
||||
electron.ipcMain.handle("notesAPI:call", async (_, method, args) => {
|
||||
if (!notesAPI[method]) {
|
||||
throw new Error("Invalid method");
|
||||
}
|
||||
return notesAPI[method](...args);
|
||||
});
|
||||
});
|
||||
electron.app.on("window-all-closed", () => {
|
||||
|
||||
@@ -3,16 +3,15 @@ const electron = require("electron");
|
||||
const api = {
|
||||
openNoteWindow: (noteId) => {
|
||||
electron.ipcRenderer.send("open-note-window", noteId);
|
||||
},
|
||||
listNotes: () => electron.ipcRenderer.invoke("notes:list"),
|
||||
createNote: (path, content) => electron.ipcRenderer.invoke("notes:create", { path, content }),
|
||||
createNoteDir: (path) => electron.ipcRenderer.invoke("notes:createDir", path),
|
||||
readNote: (path) => electron.ipcRenderer.invoke("notes:read", path),
|
||||
updateNote: (path, content) => electron.ipcRenderer.invoke("notes:update", { path, content })
|
||||
}
|
||||
};
|
||||
const notesAPI = {
|
||||
call: (method, ...args) => electron.ipcRenderer.invoke("notesAPI:call", method, args)
|
||||
};
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
electron.contextBridge.exposeInMainWorld("api", api);
|
||||
electron.contextBridge.exposeInMainWorld("notesAPI", notesAPI);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user