feat: added skeleton omr api integration
This commit is contained in:
+28
-1
@@ -1,7 +1,7 @@
|
||||
import { app, BrowserWindow, ipcMain, dialog, Menu, nativeTheme } from "electron"
|
||||
import { join, dirname } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { readFileSync, writeFileSync } from "node:fs"
|
||||
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync, readdirSync } from "node:fs"
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
@@ -69,6 +69,14 @@ ipcMain.handle("dialog:openFile", async (_event, filters: { name: string; extens
|
||||
return result.filePaths
|
||||
})
|
||||
|
||||
ipcMain.handle("dialog:openDirectory", async () => {
|
||||
const result = await dialog.showOpenDialog(win!, {
|
||||
properties: ["openDirectory"],
|
||||
})
|
||||
win?.webContents?.focus()
|
||||
return result.filePaths?.[0] ?? ""
|
||||
})
|
||||
|
||||
ipcMain.handle("dialog:saveFile", async (_event, defaultName: string, filters: { name: string; extensions: string[] }[]) => {
|
||||
const result = await dialog.showSaveDialog(win!, {
|
||||
defaultPath: defaultName,
|
||||
@@ -97,6 +105,25 @@ ipcMain.handle("file:writeBinary", async (_event, path: string, base64: string)
|
||||
writeFileSync(path, Buffer.from(base64, "base64"))
|
||||
})
|
||||
|
||||
ipcMain.handle("dir:read", async (_event, dirPath: string) => {
|
||||
if (!existsSync(dirPath)) return []
|
||||
const entries = readdirSync(dirPath, { withFileTypes: true })
|
||||
return entries.map((e) => ({ name: e.name, isDirectory: e.isDirectory() }))
|
||||
})
|
||||
|
||||
ipcMain.handle("dir:ensure", async (_event, dirPath: string) => {
|
||||
if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true })
|
||||
return dirPath
|
||||
})
|
||||
|
||||
ipcMain.handle("path:exists", async (_event, path: string) => {
|
||||
return existsSync(path)
|
||||
})
|
||||
|
||||
ipcMain.handle("file:copy", async (_event, src: string, dest: string) => {
|
||||
copyFileSync(src, dest)
|
||||
})
|
||||
|
||||
app.whenReady().then(createWindow)
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
|
||||
@@ -12,6 +12,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
||||
},
|
||||
openFileDialog: (filters: { name: string; extensions: string[] }[]) =>
|
||||
ipcRenderer.invoke("dialog:openFile", filters),
|
||||
openDirectoryDialog: () => ipcRenderer.invoke("dialog:openDirectory"),
|
||||
saveFileDialog: (defaultName: string, filters: { name: string; extensions: string[] }[]) =>
|
||||
ipcRenderer.invoke("dialog:saveFile", defaultName, filters),
|
||||
readFile: (path: string) => ipcRenderer.invoke("file:read", path),
|
||||
@@ -19,4 +20,8 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
||||
readImage: (path: string) => ipcRenderer.invoke("file:readImage", path),
|
||||
writeBinaryFile: (path: string, base64: string) => ipcRenderer.invoke("file:writeBinary", path, base64),
|
||||
getAppPath: () => ipcRenderer.invoke("app:getPath"),
|
||||
readDir: (path: string) => ipcRenderer.invoke("dir:read", path),
|
||||
ensureDir: (path: string) => ipcRenderer.invoke("dir:ensure", path),
|
||||
pathExists: (path: string) => ipcRenderer.invoke("path:exists", path),
|
||||
copyFile: (src: string, dest: string) => ipcRenderer.invoke("file:copy", src, dest),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user