我正在使用electron-react-boilerplate。我有这个main.dev.ts
ipcMain.handle('getSettings', (e) => {
return FileController.getSettings();
});
还有我的 FileController 类
import { Settings } from "../models";
// import { toast } from "react-toastify";
import fs from 'fs';
import Path from 'path';
import { app } from 'electron';
import Finder from "fs-finder";
const userDataPath = app.getPath('userData');
const settingsPath = Path.join(userDataPath, 'settings.json');
export class FileController {
static getSettings(): Promise<Settings> {
return new Promise((resolve) => {
fs.readFile(settingsPath, (err, data) => {
if (!err){
resolve(JSON.parse(data.toString()) as Settings);
} else if (!err.message.toLowerCase().includes('no such file')){
console.log(err);
// toast.error('Failed to load settings.');
}
resolve(null);
})
});
}
}
运行应用程序时,我得到
无法读取未定义的属性“getPath”
我升级到新版本的样板和扩展电子。由于远程现在已弃用,我将一些逻辑移入主进程。我不知道为什么 app 没有定义。