Skip to content

Instantly share code, notes, and snippets.

@swt02026
Created November 27, 2018 09:30
Show Gist options
  • Save swt02026/09780006f3041968c95d3daafbdcd971 to your computer and use it in GitHub Desktop.
Save swt02026/09780006f3041968c95d3daafbdcd971 to your computer and use it in GitHub Desktop.
const {ipcMain, app, BrowserWindow} = require('electron');
const fs = require('fs');
const fsPromises = fs.promises;
console.log(process.version)
const path = 'd:\\Users\\swt02026\\Desktop\\zcb\\aaa.txt';
var position = 0;
var mainWindow = null;
var isFinishload = false;
var fh = null;
(async () => {
fh = await fsPromises.open(path, 'r+');
})();
function StartWather() {
var chokidar = require('chokidar');
var watcher = chokidar.watch(path, {ignored: /[\/\\]\./, persistent: true});
watcher.on('change', (path) => {
console.log(path);
});
}
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.webContents.on('did-finish-load', () => {
var content = null;
(async () => {
content = await fh.readFile();
mainWindow.webContents.send('create', content);
StartWather();
})();
// position += content.length;
// StartWather();
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment