Merge pull request #163 from feross/poster-image-folder

Write poster images into "$CONFIG_PATH/Posters"
This commit is contained in:
Feross Aboukhadijeh
2016-03-19 16:42:05 -07:00
5 changed files with 20 additions and 13 deletions

View File

@@ -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)

View File

@@ -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'),

View File

@@ -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",

View File

@@ -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')
@@ -291,6 +290,7 @@ function loadState (callback) {
state.saved.torrents.forEach(function (torrentSummary) {
if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName
})
saveState()
if (callback) callback()
})
@@ -462,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(cfgDirectory, 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()
})
})
})
}

View File

@@ -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