У меня есть электрон для моего проекта angular 8, и теперь я могу использовать электрон для создания настольного приложения из моего проекта angular 8. Вот структура моего проекта:
+ dist
+ e2e
+ electron => which includes main.ts & tsconfig.json & dist, and inside dist is my main.js
+ node_modules
+ src
Вот мой файл main.ts
import { app, BrowserWindow, ipcMain } from 'electron'
import * as path from 'path'
import * as url from 'url'
import * as fs from "fs";
let win: BrowserWindow
app.on('ready', createWindow)
app.on('activate', () => {
if (win === null) {
createWindow()
}
});
function createWindow() {
win = new BrowserWindow({ fullscreen: true })
win.loadURL(
url.format({
pathname: path.join(__dirname, `/panelfinal/index.html`),
protocol: 'file:',
slashes: true,
})
)
win.webContents.openDevTools()
win.on('closed', () => {
win = null
})
}
ipcMain.on('getFiles', (event, arg) => {
console.log(event + "this is event");
console.log(arg + " this is arg");
const files = fs.readdirSync(__dirname);
console.log(files + " Electron");
win.webContents.send('getFilesResponse', files)
})
Я хочу прочитать файлы из файловой системы с электроном, и я создал электронный сервисфайл и оттуда я пытаюсь позвонить Ipc
для доступа к файловой системе. Вот мой электронный сервис:
export class ElectronService {
public ipc: IpcRenderer
constructor(private snackBar: SnackbarService) {
if ((<any>window).require) {
try {
this.ipc = (<any>window).require('electron').ipcRenderer
} catch (error) {
throw error
}
} else {
console.warn('not for this platform')
}
}
async getFiles(plaques: string[]) {
new Promise<string[]>((resolve, reject) => {
this.ipc.once("getFilesResponse", (event, arg) => {
resolve(arg);
});
this.ipc.send("getFiles", plaques);
});
}
}
, когда я вызываю метод getFiles()
в своем электроне, я получаю эту ошибку:
Невозможно прочитать свойство 'Once' из неопределенного
Есть идеи почему?