Refactor
This commit is contained in:
9
packages/web/src/electron/ipc-types.d.ts
vendored
9
packages/web/src/electron/ipc-types.d.ts
vendored
@ -1,9 +1,10 @@
|
||||
import type { DirEntry } from "opvault.js/src/adapter"
|
||||
|
||||
export interface IPC {
|
||||
showDirectoryPicker(): Promise<string | undefined>
|
||||
pathExists(path: string): Promise<boolean>
|
||||
readdir(path: string): Promise<string[]>
|
||||
readBuffer(path: string): Promise<Uint8Array>
|
||||
readFile(path: string): Promise<string>
|
||||
readDir(path: string): Promise<DirEntry[]>
|
||||
readFile(path: string): Promise<Uint8Array>
|
||||
readTextFile(path: string): Promise<string>
|
||||
writeFile(path: string, data: string): Promise<void>
|
||||
isDirectory(path: string): Promise<boolean>
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import fs, { promises } from "fs"
|
||||
import { ipcMain, dialog } from "electron"
|
||||
import { adapter } from "opvault.js/src/adapter/node"
|
||||
import type { DirEntry } from "opvault.js/src/adapter"
|
||||
import type { IPC } from "./ipc-types"
|
||||
|
||||
registerService({
|
||||
@ -15,11 +17,11 @@ registerService({
|
||||
return fs.existsSync(path)
|
||||
},
|
||||
|
||||
async readBuffer(_, path) {
|
||||
async readFile(_, path) {
|
||||
return promises.readFile(path)
|
||||
},
|
||||
|
||||
async readFile(_, path) {
|
||||
async readTextFile(_, path) {
|
||||
return promises.readFile(path, "utf-8")
|
||||
},
|
||||
|
||||
@ -27,13 +29,12 @@ registerService({
|
||||
await promises.writeFile(path, content)
|
||||
},
|
||||
|
||||
async readdir(_, path) {
|
||||
return promises.readdir(path)
|
||||
},
|
||||
|
||||
async isDirectory(_, path) {
|
||||
const stats = await promises.stat(path)
|
||||
return stats.isDirectory()
|
||||
async readDir(_, path) {
|
||||
const entries: DirEntry[] = []
|
||||
for await (const dirent of adapter.fs.readDir(path)) {
|
||||
entries.push(dirent)
|
||||
}
|
||||
return entries
|
||||
},
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user