Skip to content

Commit

Permalink
OpenFile dialog now works, selects a file and logs name to console.
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Ross <[email protected]>
  • Loading branch information
Blake Bender and BenjaminPerryRoss committed Jun 27, 2018
1 parent 38fc288 commit 5ec53b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fileManagement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var fs = require('fs');

function openFile () {

dialog.showOpenDialog(function (fileNames) {
if (fileNames === undefined) return;

var fileName = fileNames[0];

fs.readFile(fileName, 'utf-8', function (err, data) {
console.log("Selected filename " + fileName);
});
});
}

document.querySelector('#fileOpenButton').addEventListener('click', openFile)
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ <h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<button id="fileOpenButton">Open</button>
</body>
<script>
var remote = require('electron').remote;
var dialog = remote.require('electron').dialog;
require('./fileManagement.js')
</script>
</html>

1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const {app, BrowserWindow} = require('electron')
}
})


// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

0 comments on commit 5ec53b9

Please sign in to comment.