npm install fs-jetpack --save
const { app, BrowserWindow } = require('electron'); const jetpack = require('fs-jetpack');
let win;
function createWindow() { win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } });
win.loadFile('index.html');
// Handle local file operations win.webContents.on('did-finish-load', () => { const sourcePath = jetpack.read('file.txt'); console.log(sourcePath); });
// Open the DevTools. win.webContents.openDevTools();
win.on('closed', () => { win = null; }); }
// Handle open-file event app.on('open-file', (event, path) => { event.preventDefault();
if (win) { win.webContents.send('open-file', path); } else { storedPath = path; } });
app.on('ready', createWindow);
import { Component, OnInit } from '@angular/core'; import { ElectronService } from 'ngx-electron';
@Component({ selector: 'app-file', templateUrl: './file.component.html', styleUrls: ['./file.component.css'] }) export class FileComponent implements OnInit {
constructor(private electronService: ElectronService) { }
ngOnInit() { this.electronService.ipcRenderer.on('open-file', (event, path) => { console.log(path); }); }
}
import { Component, OnInit } from '@angular/core'; import { ElectronService } from 'ngx-electron';
@Component({ // ... }) export class FileComponent implements OnInit {
constructor(private electronService: ElectronService) { }
ngOnInit() { // ... }
openFile() { this.electronService.remote.dialog.showOpenDialog({