diff --git a/package.json b/package.json index 976664c7..fef479c6 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "electron-localshortcut": "^0.6.0", "hyperx": "^2.0.2", "main-loop": "^3.2.0", + "mkdirp": "^0.5.1", "network-address": "^1.1.0", "prettier-bytes": "^1.0.1", "upload-element": "^1.0.1", diff --git a/renderer/index.js b/renderer/index.js index 44c48176..a4d21dd0 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -7,6 +7,7 @@ var electron = require('electron') var EventEmitter = require('events') var fs = require('fs') var mainLoop = require('main-loop') +var mkdirp = require('mkdirp') var networkAddress = require('network-address') var path = require('path') var WebTorrent = require('webtorrent') @@ -283,7 +284,7 @@ function setupIpc () { } // Load state.saved from the JSON state file -function loadState (callback) { +function loadState (cb) { cfg.read(function (err, data) { if (err) console.error(err) console.log('loaded state from ' + cfg.filePath) @@ -293,9 +294,8 @@ function loadState (callback) { state.saved.torrents.forEach(function (torrentSummary) { if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName }) - saveState() - if (callback) callback() + if (cb) cb() }) } @@ -474,7 +474,8 @@ function generateTorrentPoster (torrent, torrentSummary) { torrentPoster(torrent, function (err, buf) { if (err) return onWarning(err) // save it for next time - fs.mkdir(config.CONFIG_POSTER_PATH, function (_) { + mkdirp(config.CONFIG_POSTER_PATH, function (err) { + if (err) return onWarning(err) var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') fs.writeFile(posterFilePath, buf, function (err) { if (err) return onWarning(err)