Comparing version 2.0.0 to 2.1.0
@@ -8,3 +8,3 @@ 'use strict'; | ||
} else { | ||
module.exports = require('pify').all(require('./lib/linux')); | ||
module.exports = require('./lib/linux'); | ||
} |
'use strict'; | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
const pify = require('pify'); | ||
const cp = pify.all(childProcess); | ||
@@ -17,18 +19,15 @@ const appsList = [ | ||
], | ||
transform: imagePath => imagePath.trim().slice(8, -1) | ||
transform: imagePath => imagePath.slice(8, -1) | ||
}, | ||
{ | ||
cmd: 'setroot', | ||
set: ['%s'], | ||
get: null | ||
set: ['%s'] | ||
}, | ||
{ | ||
cmd: 'pcmanfm', | ||
set: ['-w %s'], | ||
get: null | ||
set: ['-w %s'] | ||
}, | ||
{ | ||
cmd: 'feh', | ||
set: ['--bg-scale', '%s'], | ||
get: null | ||
set: ['--bg-scale', '%s'] | ||
}, | ||
@@ -40,4 +39,3 @@ { | ||
'-s %s' | ||
], | ||
get: null | ||
] | ||
}, | ||
@@ -50,4 +48,3 @@ { | ||
'%s' | ||
], | ||
get: null | ||
] | ||
}, | ||
@@ -60,4 +57,3 @@ { | ||
'%s 1' | ||
], | ||
get: null | ||
] | ||
}, | ||
@@ -72,3 +68,3 @@ { | ||
], | ||
transform: imagePath => imagePath.trim().slice(1, -1) | ||
transform: imagePath => imagePath.slice(1, -1) | ||
} | ||
@@ -79,4 +75,5 @@ ]; | ||
function setAvailableApps(cb) { | ||
function setAvailableApps() { | ||
const availableAppsDict = {}; | ||
availableApps = []; | ||
@@ -92,3 +89,5 @@ | ||
childProcess.exec(whichCmd, (err, stdout) => { | ||
return cp.exec(whichCmd).then(stdout => { | ||
stdout = stdout.trim(); | ||
if (!stdout) { | ||
@@ -100,3 +99,3 @@ throw new Error('None of the apps were found'); | ||
// and only the executable name. i.e. 'foo' from /bin/foo | ||
stdout = stdout.trim().split('\n'); | ||
stdout = stdout.split('\n'); | ||
@@ -113,62 +112,38 @@ stdout.forEach(el => { | ||
}); | ||
cb(availableApps); | ||
}); | ||
} | ||
exports.get = function get(cb) { | ||
exports.get = function get() { | ||
if (!availableApps) { | ||
return setAvailableApps(() => { | ||
get(cb); | ||
}); | ||
return setAvailableApps().then(get); | ||
} | ||
cb = cb || function () {}; | ||
const app = availableApps.find(app => app.get); | ||
let found = false; | ||
return cp.execFile(app.cmd, app.get).then(stdout => { | ||
stdout = stdout.trim(); | ||
availableApps.forEach(app => { | ||
if (!app.get || found) { | ||
return; | ||
if (typeof app.transform === 'function') { | ||
return app.transform(stdout); | ||
} | ||
childProcess.execFile(app.cmd, app.get, (err, stdout) => { | ||
if (err || !stdout || found) { | ||
return; | ||
} | ||
found = true; | ||
if (typeof app.transform === 'function') { | ||
stdout = app.transform(stdout); | ||
} | ||
cb(null, stdout); | ||
}); | ||
return stdout; | ||
}); | ||
}; | ||
exports.set = function set(imagePath, cb) { | ||
exports.set = function set(imagePath) { | ||
if (typeof imagePath !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
return Promise.reject(new TypeError('Expected a string')); | ||
} | ||
if (!availableApps) { | ||
return setAvailableApps(() => set(imagePath, cb)); | ||
return setAvailableApps().then(() => set(imagePath)); | ||
} | ||
cb = cb || function () {}; | ||
const app = availableApps.find(app => app.set); | ||
const params = app.set.slice(); | ||
imagePath = path.resolve(imagePath); | ||
params[params.length - 1] = params[params.length - 1].replace('%s', path.resolve(imagePath)); | ||
availableApps.forEach(app => { | ||
if (!app.set) { | ||
return; | ||
} | ||
const params = JSON.parse(JSON.stringify(app.set)); | ||
params[params.length - 1] = params[params.length - 1].replace('%s', imagePath); | ||
childProcess.execFile(app.cmd, params, err => cb(err)); | ||
}); | ||
return cp.execFile(app.cmd, params); | ||
}; |
{ | ||
"name": "wallpaper", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Get or set the desktop wallpaper", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
33018
152