init commit
This commit is contained in:
46
src/main/window/localSoftware/FontDesignWindow.ts
Normal file
46
src/main/window/localSoftware/FontDesignWindow.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { readFile, writeFile, existsSync } from 'fs'
|
||||
import { IpcMainEvent } from 'electron'
|
||||
import { LocalSoftwareWindow } from '../LocalSoftwareWindow'
|
||||
|
||||
const FONT_LIBRARY_FILE_PATH = './fontLibrary.json'
|
||||
|
||||
export class FontDesignWindow extends LocalSoftwareWindow {
|
||||
constructor (options = {}) {
|
||||
super('font-design.html', options )
|
||||
}
|
||||
|
||||
bindIpcEvent(): void {
|
||||
this.webContents.ipc.on('LOAD_FONT_LIBRARY', this.load )
|
||||
this.webContents.ipc.on('SAVE_FONT_LIBRARY', this.save )
|
||||
}
|
||||
|
||||
load(event: IpcMainEvent) {
|
||||
if (!existsSync(FONT_LIBRARY_FILE_PATH)) {
|
||||
event.returnValue = {}
|
||||
return
|
||||
}
|
||||
|
||||
readFile(FONT_LIBRARY_FILE_PATH, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
||||
event.returnValue = {}
|
||||
} else {
|
||||
event.returnValue = { data }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
save(event: IpcMainEvent, fontLibrary: string) {
|
||||
if (!fontLibrary) {
|
||||
event.returnValue = { err: new Error('字库为空') }
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
writeFile( FONT_LIBRARY_FILE_PATH, fontLibrary, 'utf8', () => event.returnValue = 'OK')
|
||||
} catch (err) {
|
||||
event.returnValue = { err }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user