From 684fa7dee7ce32ec242a5016dc1775c6d09034f5 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 16:19:15 -0700 Subject: [PATCH 1/3] Write poster images into "$CONFIG_PATH/posters" (fix #155) --- bin/cleanup.js | 6 ++---- config.js | 8 +++++++- renderer/index.js | 3 +-- renderer/state.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bin/cleanup.js b/bin/cleanup.js index f99bc2a2..72739b64 100755 --- a/bin/cleanup.js +++ b/bin/cleanup.js @@ -5,15 +5,13 @@ * Useful for developers. */ -var applicationConfigPath = require('application-config-path') var config = require('../config') var os = require('os') var path = require('path') var pathExists = require('path-exists') var rimraf = require('rimraf') -var tmpPath = path.join(pathExists.sync('/tmp') ? '/tmp' : os.tmpDir(), 'webtorrent') -var configPath = applicationConfigPath(config.APP_NAME) +rimraf.sync(config.CONFIG_PATH) -rimraf.sync(configPath) +var tmpPath = path.join(pathExists.sync('/tmp') ? '/tmp' : os.tmpDir(), 'webtorrent') rimraf.sync(tmpPath) diff --git a/config.js b/config.js index 311e0e90..fe0ed762 100644 --- a/config.js +++ b/config.js @@ -1,9 +1,15 @@ +var applicationConfigPath = require('application-config-path') var path = require('path') module.exports = { - APP_NAME: 'WebTorrent', APP_ICON: path.join(__dirname, 'static', 'WebTorrent.png'), + APP_NAME: 'WebTorrent', + + CONFIG_PATH: applicationConfigPath('WebTorrent'), + CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'posters'), + INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'), + SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'), SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'), SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'), diff --git a/renderer/index.js b/renderer/index.js index 6f79b993..f27e1fb6 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -1,7 +1,6 @@ console.time('init') var cfg = require('application-config')('WebTorrent') -var cfgDirectory = require('application-config-path')('WebTorrent') var createTorrent = require('create-torrent') var dragDrop = require('drag-drop') var electron = require('electron') @@ -462,7 +461,7 @@ function generateTorrentPoster (torrent, torrentSummary) { torrentPoster(torrent, function (err, buf) { if (err) return onWarning(err) // save it for next time - var posterFilePath = path.join(cfgDirectory, torrent.infoHash + '.jpg') + var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') fs.writeFile(posterFilePath, buf, function (err) { if (err) return onWarning(err) // show the poster diff --git a/renderer/state.js b/renderer/state.js index fb0d2ba2..312233ec 100644 --- a/renderer/state.js +++ b/renderer/state.js @@ -46,7 +46,7 @@ module.exports = { * * Config path: * - * OS XDG ~/Library/Application Support/WebTorrent/config.json + * OS X ~/Library/Application Support/WebTorrent/config.json * Linux (XDG) $XDG_CONFIG_HOME/WebTorrent/config.json * Linux (Legacy) ~/.config/WebTorrent/config.json * Windows (> Vista) %LOCALAPPDATA%/WebTorrent/config.json From 7738aa2f1636b12956c023841e792c3fed756177 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 16:20:11 -0700 Subject: [PATCH 2/3] rename "npm run cleanup" to "npm run clean" --- bin/{cleanup.js => clean.js} | 0 package.json | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename bin/{cleanup.js => clean.js} (100%) diff --git a/bin/cleanup.js b/bin/clean.js similarity index 100% rename from bin/cleanup.js rename to bin/clean.js diff --git a/package.json b/package.json index b159cee7..e4f60318 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "url": "git://github.com/feross/webtorrent-app.git" }, "scripts": { - "cleanup": "node ./bin/cleanup.js", + "clean": "node ./bin/clean.js", "debug": "DEBUG=* electron .", "package": "npm prune && npm dedupe && node ./bin/package.js", "size": "npm run package -- --darwin && du -ch dist/WebTorrent-darwin-x64 | grep total", From 75841afcb5d78465f9392012f86339e39b738e30 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 16:30:36 -0700 Subject: [PATCH 3/3] ensure Posters/ folder exists --- config.js | 2 +- renderer/index.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.js b/config.js index fe0ed762..6f6cce73 100644 --- a/config.js +++ b/config.js @@ -6,7 +6,7 @@ module.exports = { APP_NAME: 'WebTorrent', CONFIG_PATH: applicationConfigPath('WebTorrent'), - CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'posters'), + CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'Posters'), INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'), diff --git a/renderer/index.js b/renderer/index.js index f27e1fb6..5ceae055 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -290,6 +290,7 @@ function loadState (callback) { state.saved.torrents.forEach(function (torrentSummary) { if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName }) + saveState() if (callback) callback() }) @@ -461,12 +462,15 @@ function generateTorrentPoster (torrent, torrentSummary) { torrentPoster(torrent, function (err, buf) { if (err) return onWarning(err) // save it for next time - var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') - fs.writeFile(posterFilePath, buf, function (err) { + fs.mkdir(config.CONFIG_POSTER_PATH, function (err) { if (err) return onWarning(err) - // show the poster - torrentSummary.posterURL = 'file:///' + posterFilePath - update() + var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') + fs.writeFile(posterFilePath, buf, function (err) { + if (err) return onWarning(err) + // show the poster + torrentSummary.posterURL = 'file:///' + posterFilePath + update() + }) }) }) }