From 012d2f9034d3414322eb92c6c0a0c954d45f2e98 Mon Sep 17 00:00:00 2001 From: danbulant Date: Sun, 23 Jun 2019 12:16:22 +0200 Subject: [PATCH] testing file system --- files.js | 15 +++++++++++++++ html/node.js | 4 ++++ main.js | 13 +++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 files.js diff --git a/files.js b/files.js new file mode 100644 index 0000000..26890ee --- /dev/null +++ b/files.js @@ -0,0 +1,15 @@ +// files.js +var fs = require('fs'); +var path = require('path'); +module.exports = { + fs: require('fs'), + path: require('path'), + walkDir: function(dir, callback){ + fs.readdirSync(dir).forEach( f => { + let dirPath = path.join(dir, f); + let isDirectory = fs.statSync(dirPath).isDirectory(); + isDirectory ? + walkDir(dirPath, callback) : callback(path.join(dir, f)); + }); + } +} diff --git a/html/node.js b/html/node.js index 45decca..4262acb 100644 --- a/html/node.js +++ b/html/node.js @@ -21,6 +21,10 @@ if(typeof require() != undefined){ } ipcRenderer.send('get-data', 'wifi'); ipcRenderer.send('get-data', 'wifiQuality'); + ipcRenderer.on('listFiles', (event, arg) => { + console.log(arg); + }) + ipcRenderer.send('listFiles', '/'); } else { //no NODE integration, propably browser access } diff --git a/main.js b/main.js index 6c9061f..44d15ab 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ -const { dialog, Menu, app, BrowserWindow } = require('electron') +const { dialog, Menu, app, BrowserWindow } = require('electron'); +var files = require('./files'); var wifi = require('node-wifi'); -let win +let win; wifi.init({ iface : null @@ -170,6 +171,14 @@ ipcMain.on('fullscreen', (event, arg) => { console.log('Setting to fullscreen ' + arg); win.setFullScreen(arg); }) +ipcMain.on('listFiles', (event, arg) => { + console.log('Listing all files and directories in ' + arg); + dirs = files.walkDir('my-dir', function(filePath) { + const fileContents = fs.readFileSync(filePath, 'utf8'); + console.log(filePath, fileContents); + }); + event.reply('listFiles', fileContents); +}) app.setAppUserModelId(process.execPath) app.on('window-all-closed', () => {