Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//Replace Old Wallpaper
// fs.unlinkSync(path);
await setImgName();
console.log(" 2. Image Should Be Replaced");
//Set Wallpaper
await wallpaper.set(path);
console.log(" 3. Image Should Be Set");
declareStatus();
} else if(err.code == 'ENOENT') {
await setImgName();
console.log(" 2. Image Should Be Saved");
//Set Wallpaper
await wallpaper.set(path);
console.log(" 3. Image Should Be Set");
declareStatus();
}
});
}
if (fs.existsSync(img) && !quiet) {
spinner.stop();
printBlock(chalk`Hey! That photo is already on your computer!`);
const a = await prompt([
{
name: "again",
message: "Do you want to download it again?",
prefix: chalk.green("%"),
type: "confirm"
}
]);
if (!a.again) {
if (setAsWallpaper) wallpaper.set(img);
// Display 'shot by ...'
console.log();
showCopy(photo, info);
return;
}
spinner.start();
}
const file = fs.createWriteStream(img);
try {
https.get(url, response => {
response.pipe(file).on("finish", () => {
}
if (!command) {
console.clear();
if (!flags.me && !flags.updateMe && !flags.set) spinner.start('Connecting to Unsplash');
if (flags.set) {
const filePath = pathFixer(flags.set);
if (fs.existsSync(filePath) && isImage(filePath)) {
let options = {};
if (flags.scale) options.scale = flags.scale;
if (flags.screen) options.screen = flags.screen;
wallpaper.set(filePath, options);
return printBlock('Wallpaper updated!');
}
return errorHandler('File not found.');
}
try {
let photo = false;
// here you can add your own custom flags
if (flags.day) {
photo = await Unsplash.shared.picOfTheDay();
} else if (flags.curated) {
const response = await Unsplash.shared.getRandomPhoto({ collection: 317099 });
const photos = await response.json();
#!/usr/bin/env node
const wallpaper = require('wallpaper');
const fs = require('fs');
const path = require('path');
const images = fs.readdirSync(path.join(__dirname, 'img'));
const index = Math.floor(Math.random() * images.length);
wallpaper.set(path.join(__dirname, 'img', images[index])).then(() => {
console.log('Your day just got hassel of a lot better.');
});
response.pipe(file).on('finish', () => {
wallpaper.set(pic_dir + '/' + photo_name + '.jpg');
spinner.succeed();
if ( program.info ) {
console.log('');
console.log(`ID: ${photo.id.yellow}`);
console.log('');
if ( photo.exif !== undefined ) {
if (photo.exif.make) {
console.log('Make: '.yellow.bold + photo.exif.make);
} else {
console.log('Make: '.yellow.bold + '--');
}
if (photo.exif.model) {
console.log('Model: '.yellow.bold + photo.exif.model);
} else {
(async () => {
if (input) {
if (isUrl(input)) {
const file = tempfile(path.extname(input));
got
.stream(input)
.pipe(fs.createWriteStream(file))
.on('finish', async () => {
await wallpaper.set(file, cli.flags);
});
} else {
await wallpaper.set(input, cli.flags);
}
} else {
console.log(await wallpaper.get());
}
})();
function maybeSetWallpaper() {
if (!opts.wallpaper) return;
verbose('Setting wallpaper...');
//require('wallpaper').set(opts.output, {scale: 'tile'});
require('wallpaper').set(opts.output);
}
fs.writeFile(imgPath, base64, "base64", function(err){
if(err){
return show_error_message("Failed to set as desktop background: couldn't write temporary image file.", err);
}
wallpaper.set(imgPath, function(err){
if(err){
show_error_message("Failed to set as desktop background!", err);
}
});
});
}else{
export default function (opts, path) {
if (path) {
return wallpaper.set(path);
}
return wallpaper.get();
}