Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9296fd7
commit 16bc00f
Showing
9 changed files
with
113 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ language: node_js | |
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
'use strict'; | ||
const util = require('util'); | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
const pify = require('pify'); | ||
|
||
const execFile = pify(childProcess.execFile); | ||
const execFile = util.promisify(childProcess.execFile); | ||
|
||
// Binary source → https://github.com/sindresorhus/macos-wallpaper | ||
const bin = path.join(__dirname, 'macos-wallpaper'); | ||
|
||
exports.get = () => execFile(bin, ['get']).then(x => x.trim()); | ||
exports.get = async () => { | ||
const {stdout} = await execFile(bin, ['get']); | ||
return stdout.trim(); | ||
}; | ||
|
||
exports.set = (imagePath, opts) => { | ||
exports.set = async (imagePath, options) => { | ||
if (typeof imagePath !== 'string') { | ||
return Promise.reject(new TypeError('Expected a string')); | ||
} | ||
|
||
opts = opts || {}; | ||
|
||
const args = ['set', path.resolve(imagePath)]; | ||
|
||
if (opts.screen) { | ||
args.push('--screen', opts.screen); | ||
} | ||
|
||
if (opts.scale) { | ||
args.push('--scale', opts.scale); | ||
throw new TypeError('Expected a string'); | ||
} | ||
|
||
return execFile(bin, args); | ||
options = { | ||
screen: 'all', | ||
scale: 'auto', | ||
...options | ||
}; | ||
|
||
const args = [ | ||
'set', | ||
path.resolve(imagePath), | ||
'--screen', | ||
options.screen, | ||
'--scale', | ||
options.scale | ||
]; | ||
|
||
await execFile(bin, args); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
'use strict'; | ||
const util = require('util'); | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
const pify = require('pify'); | ||
|
||
const execFile = pify(childProcess.execFile); | ||
const execFile = util.promisify(childProcess.execFile); | ||
|
||
// Binary source → https://github.com/sindresorhus/win-wallpaper | ||
const bin = path.join(__dirname, 'win-wallpaper.exe'); | ||
|
||
exports.get = () => execFile(bin).then(x => x.trim()); | ||
exports.get = async () => { | ||
const {stdout} = await execFile(bin); | ||
return stdout.trim(); | ||
}; | ||
|
||
exports.set = imagePath => { | ||
exports.set = async imagePath => { | ||
if (typeof imagePath !== 'string') { | ||
return Promise.reject(new TypeError('Expected a string')); | ||
throw new TypeError('Expected a string'); | ||
} | ||
|
||
return execFile(bin, [path.resolve(imagePath)]); | ||
await execFile(bin, [path.resolve(imagePath)]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import m from '.'; | ||
import wallpaper from '.'; | ||
|
||
test('main', async t => { | ||
const orignalImagePath = await m.get(); | ||
const orignalImagePath = await wallpaper.get(); | ||
|
||
await m.set('fixture.jpg'); | ||
t.is(await m.get(), path.resolve('fixture.jpg')); | ||
await wallpaper.set('fixture.jpg'); | ||
t.is(await wallpaper.get(), path.resolve('fixture.jpg')); | ||
|
||
await m.set(orignalImagePath); | ||
await wallpaper.set(orignalImagePath); | ||
}); |