Skip to content

Commit

Permalink
replace drivelist-scanner with drivelist-scan
Browse files Browse the repository at this point in the history
drivelist-scanner gives errors on Windows, replace with new custom module
  • Loading branch information
davidferguson committed Dec 29, 2017
1 parent 7871c03 commit 9febd9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
68 changes: 35 additions & 33 deletions app/pibakery.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var fs = require('fs-extra')
var isOnline = require('is-online')
var umount = require('umount')
var shellParser = require('node-shell-parser')
var drivelistScanner = require('drivelist-scanner')
var scanner = require('drivelist-scan')
var path = require('path')
var wget = require('wget-improved')
var md5File = require('md5-file')
Expand Down Expand Up @@ -887,52 +887,54 @@ function getExtractedPath (callback, filepath, currentNumber) {
})
}

var scanner = new drivelistScanner({interval: 1000})
scanner.on('add', function (drives) {
if (drives.mountpoints.length === 0) {
scanner.driveAdded = function (drive) {
if (drive.mountpoints.length === 0) {
return
}
console.log(drives)
console.log('added', drive)
setTimeout(function () {
if (! workspace) {
var loadedInterval = setInterval(function () {
if (workspace) {
clearInterval(loadedInterval)
importExisting(drives)
importExisting(drive)
}
}, 1000)
}else {
importExisting(drives)
importExisting(drive)
}
}, 1000)
})
scanner.on('remove', function (drives) {
if ((! drives.system) && (currentMode == 'update')) {
if (currentMode = 'update') {
var blockFile = piBakeryPath + 'blocks.xml'
fs.stat(blockFile, function (error, stat) {
if (error) {
console.error(error)
if (!! document.getElementById('onnextboot')) {
document.getElementById('hat').removeChild(document.getElementById('onnextboot'))
var newBlock = document.createElement('block')
newBlock.setAttribute('id', 'onfirstboot')
newBlock.setAttribute('type', 'onfirstboot')
document.getElementById('hat').appendChild(newBlock)
}
workspace.updateToolbox(document.getElementById('toolbox'))
Blockly.mainWorkspace.clear()
currentMode = 'write'
firstBoot = true
document.getElementById('flashSD').addEventListener('click', writeToSd)
document.getElementById('flashSD').removeEventListener('click', updateSd)
document.getElementById('flashSD').children[1].innerText = 'Write'
document.getElementById('sdImage').src = 'img/write-to-sd.png'
}

scanner.driveRemoved = function (drive) {
console.log('removed', drive)
if (currentMode == 'update') {
var blockFile = piBakeryPath + 'blocks.xml'
fs.stat(blockFile, function (error, stat) {
if (error) {
console.error(error)
if (!! document.getElementById('onnextboot')) {
document.getElementById('hat').removeChild(document.getElementById('onnextboot'))
var newBlock = document.createElement('block')
newBlock.setAttribute('id', 'onfirstboot')
newBlock.setAttribute('type', 'onfirstboot')
document.getElementById('hat').appendChild(newBlock)
}
})
}
workspace.updateToolbox(document.getElementById('toolbox'))
Blockly.mainWorkspace.clear()
currentMode = 'write'
firstBoot = true
document.getElementById('flashSD').addEventListener('click', writeToSd)
document.getElementById('flashSD').removeEventListener('click', updateSd)
document.getElementById('flashSD').children[1].innerText = 'Write'
document.getElementById('sdImage').src = 'img/write-to-sd.png'
}
})
}
})
}

// start the scaner with a 5 second delay between scans
scanner.begin(5000)

/**
* @desc called when a new drive has been added, used to import blocks from an
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"chmod": "^0.2.1",
"drivelist": "^5.0.16",
"drivelist-scanner": "https://github.com/davidferguson/drivelist-scanner/tarball/master",
"drivelist-scan": "https://github.com/davidferguson/drivelist-scan/tarball/master",
"electron-localshortcut": "^0.6.1",
"extract-zip": "^1.5.0",
"fs-extra": "^0.30.0",
Expand Down

0 comments on commit 9febd9b

Please sign in to comment.