Skip to content

Commit

Permalink
Support scale option on Windows (#87)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
beyluta and sindresorhus authored Jun 23, 2023
1 parent 9c06521 commit a6408ab
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
12 changes: 8 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ export interface SetOptions {
readonly screen?: 'all' | 'main' | number;

/**
__macOS only.__
__macOS & Windows__
Scaling method.
Scaling method. Values: `auto` `fill` `fit` `stretch` `center`.
macOS Values: `auto` `fill` `fit` `stretch` `center`.
Windows Values: `stretch` `center` `tile` `span` `max` `crop-to-fit` `keep-aspect-ratio`.
@default 'auto'
@default 'auto' for macOS
@default 'span' for Windows
*/
readonly scale?: 'auto' | 'fill' | 'fit' | 'stretch' | 'center';
readonly scale?: 'auto' | 'fill' | 'fit' | 'stretch' | 'center' | 'tile' | 'span';
}

/**
Expand Down
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ The screen to set the wallpaper on.

*On Linux and Windows it's hard-coded to `'main'`.*

##### scale *(macOS only)*
##### scale *(macOS & Windows)*

Type: `string`\
Values: `'auto' | 'fill' | 'fit' | 'stretch' | 'center'`\
Default: `'auto'`
macOS Values: `'auto' | 'fill' | 'fit' | 'stretch' | 'center'`\
Windows Values: `'center' | 'stretch' | 'tile' | 'span' | 'fit' | 'fill'`\
Default macOS: `'auto'`\
Default Windows: `'span'`

Scaling method.

Expand Down
Binary file added source/windows-wallpaper-x86-64.exe
Binary file not shown.
Binary file removed source/windows-wallpaper.exe
Binary file not shown.
19 changes: 15 additions & 4 deletions source/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const execFile = promisify(childProcess.execFile);

// Binary source → https://github.com/sindresorhus/win-wallpaper
const binary = path.join(__dirname, 'windows-wallpaper.exe');
const binary = path.join(__dirname, 'windows-wallpaper-x86-64.exe');

export async function getWallpaper() {
const {stdout} = await execFile(binary);
const arguments_ = [
'get',
];

const {stdout} = await execFile(binary, arguments_);
return stdout.trim();
}

export async function setWallpaper(imagePath) {
export async function setWallpaper(imagePath, {scale = 'fill'} = {}) {
if (typeof imagePath !== 'string') {
throw new TypeError('Expected a string');
}

await execFile(binary, [path.resolve(imagePath)]);
const arguments_ = [
'set',
path.resolve(imagePath),
'--scale',
scale,
];

await execFile(binary, arguments_);
}

0 comments on commit a6408ab

Please sign in to comment.