local file saving/reading
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import notes from './notesStorage'
|
||||
import { join } from 'path'
|
||||
|
||||
const preloadPath = join(__dirname, '../preload/index.js')
|
||||
const rendererPath = join(__dirname, '../renderer/index.html')
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
@@ -10,7 +14,7 @@ function createWindow() {
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
preload: preloadPath,
|
||||
sandbox: false,
|
||||
},
|
||||
})
|
||||
@@ -29,7 +33,7 @@ function createWindow() {
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
mainWindow.loadFile(rendererPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +43,7 @@ function createNoteWindow(noteId) {
|
||||
height: 549,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, 'preload.js'),
|
||||
preload: preloadPath,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
},
|
||||
@@ -50,7 +54,7 @@ function createNoteWindow(noteId) {
|
||||
`${process.env['ELECTRON_RENDERER_URL']}/note/${noteId}`,
|
||||
)
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'), {
|
||||
mainWindow.loadFile(rendererPath, {
|
||||
path: `/notes/${noteId}`,
|
||||
})
|
||||
}
|
||||
@@ -70,10 +74,12 @@ app.whenReady().then(() => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
console.log(app.getPath('userData'))
|
||||
|
||||
// Create main window
|
||||
createWindow()
|
||||
|
||||
// Ensure data directory is present
|
||||
notes.ensureBaseDir()
|
||||
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
@@ -84,6 +90,23 @@ app.whenReady().then(() => {
|
||||
ipcMain.on('open-note-window', (_, noteId) => {
|
||||
createNoteWindow(noteId)
|
||||
})
|
||||
|
||||
// File access
|
||||
ipcMain.handle('notes:list', () => {
|
||||
return notes.readAllNotesRecursive()
|
||||
})
|
||||
ipcMain.handle('notes:create', (_, { path, content }) => {
|
||||
return notes.createNote(path, content)
|
||||
})
|
||||
ipcMain.handle('notes:createDir', (_, path) => {
|
||||
return notes.createDirectory(path)
|
||||
})
|
||||
ipcMain.handle('notes:read', (_, path) => {
|
||||
return notes.readNote(path)
|
||||
})
|
||||
ipcMain.handle('notes:update', (_, { path, content }) => {
|
||||
return notes.updateNote(path, content)
|
||||
})
|
||||
})
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
|
||||
Reference in New Issue
Block a user