wallpaper-lockscreen 0.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of wallpaper-lockscreen might be problematic. Click here for more details.

package/index.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ export interface GetOptions {
2
+ /**
3
+ __macOS only.__
4
+
5
+ The screen to get the wallpaper from.
6
+
7
+ Values: `all`, `main`, or the index of a screen from `.screens()`.
8
+
9
+ @default 'main'
10
+ */
11
+ readonly screen?: 'all' | 'main' | number;
12
+ }
13
+
14
+ export interface SetOptions {
15
+ /**
16
+ __macOS only.__
17
+
18
+ The screen to set the wallpaper on.
19
+
20
+ Values: `all`, `main`, or the index of a screen from `.screens()`.
21
+
22
+ *On Linux and Windows it's hard-coded to `main`.*
23
+
24
+ @default 'all'
25
+ */
26
+ readonly screen?: 'all' | 'main' | number;
27
+
28
+ /**
29
+ __macOS only.__
30
+
31
+ Scaling method. Values: `auto` `fill` `fit` `stretch` `center`.
32
+
33
+ @default 'auto'
34
+ */
35
+ readonly scale?: 'auto' | 'fill' | 'fit' | 'stretch' | 'center';
36
+ }
37
+
38
+ /**
39
+ Get the path to the wallpaper image currently set.
40
+
41
+ @returns The path of the current desktop wallpaper.
42
+
43
+ @example
44
+ ```
45
+ import {getWallpaper} from 'wallpaper';
46
+
47
+ await getWallpaper();
48
+ //=> '/Users/sindresorhus/unicorn.jpg'
49
+ ```
50
+ */
51
+ export function getWallpaper(options?: GetOptions): Promise<string>;
52
+
53
+ /**
54
+ Set a new wallpaper.
55
+
56
+ @param imagePath - The path to the image to set as the desktop wallpaper.
57
+
58
+ @example
59
+ ```
60
+ import {setWallpaper} from 'wallpaper';
61
+
62
+ await setWallpaper('unicorn.jpg');
63
+ ```
64
+ */
65
+ export function setWallpaper(
66
+ imagePath: string,
67
+ options?: SetOptions
68
+ ): Promise<void>;
69
+
70
+ /**
71
+ __macOS only.__
72
+
73
+ @returns The available screens.
74
+
75
+ @example
76
+ ```
77
+ import {screens} from 'wallpaper';
78
+
79
+ await screens();
80
+ //=> ['Color LCD']
81
+ ```
82
+ */
83
+ export function screens(): Promise<string[]>;
84
+
85
+ /**
86
+ __macOS only.__
87
+
88
+ Set a solid color.
89
+
90
+ @param color - The color to set as a RGB Hex value. For example, `000000` for black.
91
+
92
+ @example
93
+ ```
94
+ import {setSolidColorWallpaper} from 'wallpaper';
95
+
96
+ await setSolidColorWallpaper('000000');
97
+ ```
98
+ */
99
+ export function setSolidColorWallpaper(
100
+ rgbHexColor: string,
101
+ options?: SetOptions
102
+ ): Promise<void>;
103
+
104
+ export function setLockscreen(imagePath: string): Promise<void>;
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import process from 'node:process';
2
+ import * as macos from './source/macos.js';
3
+ import * as linux from './source/linux/index.js';
4
+ import * as windows from './source/windows.js';
5
+
6
+ let wallpaper;
7
+ if (process.platform === 'darwin') {
8
+ wallpaper = macos;
9
+ } else if (process.platform === 'win32') {
10
+ wallpaper = windows;
11
+ } else {
12
+ wallpaper = linux;
13
+ }
14
+
15
+ export const {getWallpaper, setWallpaper, setSolidColorWallpaper, screens, setLockscreen} = wallpaper;
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "wallpaper-lockscreen",
3
+ "version": "0.0.4",
4
+ "description": "Manage the desktop wallpaper and lockscreen",
5
+ "license": "MIT",
6
+ "repository": "cihantaylan/wallpaper-lockscreen",
7
+ "author": {
8
+ "name": "Cihan TAYLAN",
9
+ "email": "cihantaylan@cihantaylan.com",
10
+ "url": "https://cihantaylan.com"
11
+ },
12
+ "type": "module",
13
+ "exports": "./index.js",
14
+ "engines": {
15
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
16
+ },
17
+ "scripts": {
18
+ "test": "xo --fix && xo && ava && tsd"
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "index.d.ts",
23
+ "source"
24
+ ],
25
+ "keywords": [
26
+ "macos",
27
+ "linux",
28
+ "windows",
29
+ "wallpaper",
30
+ "desktop",
31
+ "background",
32
+ "image",
33
+ "picture",
34
+ "photo"
35
+ ],
36
+ "devDependencies": {
37
+ "ava": "^4.0.1",
38
+ "tsd": "^0.19.1",
39
+ "xo": "^0.47.0"
40
+ },
41
+ "ava": {
42
+ "serial": true
43
+ }
44
+ }
package/readme.md ADDED
@@ -0,0 +1,140 @@
1
+ #### Forked from https://www.npmjs.com/package/wallpaper
2
+
3
+ # wallpaper
4
+
5
+ > Get or set the desktop wallpaper
6
+
7
+ Works on macOS 10.14.4+, Linux, and Windows 10+.
8
+
9
+ _Maintainer needed for the Linux part of the code. No new Linux-related changes will be accepted until someone with good Linux knowledge volunteers._
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install wallpaper
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import { getWallpaper, setWallpaper } from "wallpaper";
21
+
22
+ await setWallpaper("unicorn.jpg");
23
+
24
+ await getWallpaper();
25
+ //=> '/Users/sindresorhus/unicorn.jpg'
26
+ ```
27
+
28
+ ## API
29
+
30
+ ### getWallpaper(options?)
31
+
32
+ Returns a `Promise<string>` with the path of the current desktop wallpaper.
33
+
34
+ #### options
35
+
36
+ Type: `object`
37
+
38
+ ##### screen _(macOS only)_
39
+
40
+ Type: `string | number`\
41
+ Values: `'all'`, `'main'`, or the index of a screen from `.screens()`\
42
+ Default: `'main'`
43
+
44
+ The screen to get the wallpaper from.
45
+
46
+ If you set `'all'` then `getWallpaper()` will return a `Promise<string[]>`.
47
+
48
+ ### setWallpaper(imagePath, options?)
49
+
50
+ Returns a `Promise`.
51
+
52
+ #### imagePath
53
+
54
+ Type: `string`
55
+
56
+ The path to the image to set as the desktop wallpaper.
57
+
58
+ #### options
59
+
60
+ Type: `object`
61
+
62
+ ##### screen _(macOS only)_
63
+
64
+ Type: `string | number`\
65
+ Values: `'all'`, `'main'`, or the index of a screen from `.screens()`
66
+ Default: `'all'`
67
+
68
+ The screen to set the wallpaper on.
69
+
70
+ _On Linux and Windows it's hard-coded to `'main'`._
71
+
72
+ ##### scale _(macOS only)_
73
+
74
+ Type: `string`\
75
+ Values: `'auto' | 'fill' | 'fit' | 'stretch' | 'center'`\
76
+ Default: `'auto'`
77
+
78
+ Scaling method.
79
+
80
+ ### setSolidColorWallpaper(color, options?) _(macOS only)_
81
+
82
+ Returns a `Promise`.
83
+
84
+ #### color
85
+
86
+ Type: `string`
87
+
88
+ The color to set as a RGB Hex value. For example, `000000` for black.
89
+
90
+ #### options
91
+
92
+ Type: `object`
93
+
94
+ ##### screen
95
+
96
+ Type: `string | number`\
97
+ Values: `'all'`, `'main'`, or the index of a screen from `.screens()`
98
+ Default: `'all'`
99
+
100
+ The screen to set the wallpaper on.
101
+
102
+ ```js
103
+ import { setSolidColorWallpaper } from "wallpaper";
104
+
105
+ await setSolidColorWallpaper("000000");
106
+ ```
107
+
108
+ ### screens() _(macOS only)_
109
+
110
+ Returns a `Promise<string[]>` with the available screens.
111
+
112
+ ```js
113
+ import { screens } from "wallpaper";
114
+
115
+ await screens();
116
+ //=> ['Color LCD']
117
+ ```
118
+
119
+ ## FAQ
120
+
121
+ #### How can I set a website as a static wallpaper?
122
+
123
+ If you only need a static snapshot of the website, you can use [`capture-website`](https://github.com/sindresorhus/capture-website) and then pass the result to this package. You can make it semi-dynamic, by capturing the website snapshot every 10 seconds, for example.
124
+
125
+ #### How can I set a website, video, or WebGL as a dynamic wallpaper?
126
+
127
+ You cannot use this package to set a dynamic wallpaper.
128
+
129
+ On macOS, check out [Plash](https://github.com/sindresorhus/Plash), which lets you set any website as your wallpaper. The website could contain a fullscreen video, WebGL, slideshow, animated, etc.
130
+
131
+ You can also do this with Electron on macOS and Linux by using [`new BrowserWindow({type: 'desktop'})`](https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions).
132
+
133
+ On Windows, you can use [Wallpaper Engine](https://wallpaperengine.io). It's available on Steam, HumbleBundle, and Green Man Gaming for around 4 USD.
134
+
135
+ ## Related
136
+
137
+ - [wallpaper-cli](https://github.com/sindresorhus/wallpaper-cli) - CLI for this module
138
+ - [macos-wallpaper](https://github.com/sindresorhus/macos-wallpaper) - macOS binary used in this module
139
+ - [win-wallpaper](https://github.com/sindresorhus/win-wallpaper) - Windows binary used in this module
140
+ - [trash](https://github.com/sindresorhus/trash) - Move files and directories to the trash
@@ -0,0 +1,33 @@
1
+ import {commandExists, execFile, hasLine} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ if (!await commandExists('gsettings')) {
5
+ return false;
6
+ }
7
+
8
+ try {
9
+ const {stdout} = await execFile('gsettings', ['list-schemas']);
10
+ return hasLine(stdout, 'org.cinnamon.desktop.background');
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ export async function get() {
17
+ const {stdout} = await execFile('gsettings', [
18
+ 'get',
19
+ 'org.cinnamon.desktop.background',
20
+ 'picture-uri',
21
+ ]);
22
+
23
+ return stdout.trim().slice(8, -1);
24
+ }
25
+
26
+ export async function set(imagePath) {
27
+ await execFile('gsettings', [
28
+ 'set',
29
+ 'org.cinnamon.desktop.background',
30
+ 'picture-uri',
31
+ `file://${imagePath}`,
32
+ ]);
33
+ }
@@ -0,0 +1,22 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('dconf');
5
+ }
6
+
7
+ export async function get() {
8
+ const {stdout} = await execFile('dconf', [
9
+ 'read',
10
+ '/org/mate/desktop/background/picture-filename',
11
+ ]);
12
+
13
+ return stdout.trim().slice(1, -1);
14
+ }
15
+
16
+ export async function set(imagePath) {
17
+ await execFile('dconf', [
18
+ 'write',
19
+ '/org/mate/desktop/background/picture-filename',
20
+ `"${imagePath}"`,
21
+ ]);
22
+ }
@@ -0,0 +1,14 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('dcop');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('dcop', [
9
+ 'kdesktop',
10
+ 'KBackgroundIface',
11
+ 'setWallpaper',
12
+ `${imagePath} 1`,
13
+ ]);
14
+ }
@@ -0,0 +1,9 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('feh');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('feh', ['--bg-fill', imagePath]);
9
+ }
@@ -0,0 +1,15 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('gconftool-2');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('gconftool-2', [
9
+ '--set',
10
+ '/desktop/gnome/background/picture_filename',
11
+ '--type',
12
+ 'string',
13
+ imagePath,
14
+ ]);
15
+ }
@@ -0,0 +1,24 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('gsettings');
5
+ }
6
+
7
+ export async function get() {
8
+ const {stdout} = await execFile('gsettings', [
9
+ 'get',
10
+ 'org.gnome.desktop.background',
11
+ 'picture-uri',
12
+ ]);
13
+
14
+ return stdout.trim().slice(8, -1);
15
+ }
16
+
17
+ export async function set(imagePath) {
18
+ await execFile('gsettings', [
19
+ 'set',
20
+ 'org.gnome.desktop.background',
21
+ 'picture-uri',
22
+ `file://${imagePath}`,
23
+ ]);
24
+ }
@@ -0,0 +1,12 @@
1
+ export * as cinnamon from './cinnamon.js';
2
+ export * as dconf from './dconf.js';
3
+ export * as dcop from './dcop.js';
4
+ export * as feh from './feh.js';
5
+ export * as gconftool2 from './gconftool-2.js';
6
+ export * as gnome from './gnome.js';
7
+ export * as mate from './mate.js';
8
+ export * as nitrogen from './nitrogen.js';
9
+ export * as pcmanfm from './pcmanfm.js';
10
+ export * as qdbus from './qdbus.js';
11
+ export * as setroot from './setroot.js';
12
+ export * as xfconfquery from './xfconf-query.js';
@@ -0,0 +1,33 @@
1
+ import {commandExists, execFile, hasLine} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ if (!await commandExists('gsettings')) {
5
+ return false;
6
+ }
7
+
8
+ try {
9
+ const {stdout} = await execFile('gsettings', ['list-schemas']);
10
+ return hasLine(stdout, 'org.mate.background');
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ export async function get() {
17
+ const {stdout} = await execFile('gsettings', [
18
+ 'get',
19
+ 'org.mate.background',
20
+ 'picture-filename',
21
+ ]);
22
+
23
+ return stdout.trim().slice(1, -1);
24
+ }
25
+
26
+ export async function set(imagePath) {
27
+ await execFile('gsettings', [
28
+ 'set',
29
+ 'org.mate.background',
30
+ 'picture-filename',
31
+ imagePath,
32
+ ]);
33
+ }
@@ -0,0 +1,23 @@
1
+ import path from 'node:path';
2
+ import os from 'node:os';
3
+ import {commandExists, execFile, readFile} from '../util.js';
4
+
5
+ const homeDirectory = os.homedir();
6
+
7
+ export async function isAvailable() {
8
+ return commandExists('nitrogen');
9
+ }
10
+
11
+ export async function get() {
12
+ const configFile = path.join(homeDirectory, '.config/nitrogen/bg-saved.cfg');
13
+ const config = await readFile(configFile, 'utf8');
14
+ return config.trim().split('\n').find(line => line.startsWith('file=')).replace('file=', '');
15
+ }
16
+
17
+ export async function set(imagePath) {
18
+ await execFile('nitrogen', [
19
+ '--set-zoom-fill',
20
+ '--save',
21
+ imagePath,
22
+ ]);
23
+ }
@@ -0,0 +1,9 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('pcmanfm');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('pcmanfm', ['--set-wallpaper', imagePath]);
9
+ }
@@ -0,0 +1,22 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('qdbus');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('qdbus', [
9
+ 'org.kde.plasmashell',
10
+ '/PlasmaShell',
11
+ 'org.kde.PlasmaShell.evaluateScript',
12
+ `
13
+ var allDesktops = desktops();
14
+ for (var i = 0; i < allDesktops.length; i++) {
15
+ var desktop = allDesktops[i];
16
+ desktop.wallpaperPlugin = 'org.kde.image';
17
+ desktop.currentConfigGroup = ['Wallpaper', 'org.kde.image', 'General'];
18
+ desktop.writeConfig('Image', 'file://${imagePath}');
19
+ }
20
+ `,
21
+ ]);
22
+ }
@@ -0,0 +1,9 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('setroot');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('setroot', [imagePath]);
9
+ }
@@ -0,0 +1,16 @@
1
+ import {commandExists, execFile} from '../util.js';
2
+
3
+ export async function isAvailable() {
4
+ return commandExists('xfconf-query');
5
+ }
6
+
7
+ export async function set(imagePath) {
8
+ await execFile('xfconf-query', [
9
+ '--channel',
10
+ 'xfce4-desktop',
11
+ '--property',
12
+ '/backdrop/screen0/monitor0/image-path',
13
+ '--set',
14
+ `${imagePath}`,
15
+ ]);
16
+ }
@@ -0,0 +1,94 @@
1
+ import path from 'node:path';
2
+ import * as managers from './background-managers/index.js';
3
+
4
+ let availableApps;
5
+
6
+ async function setAvailableApps() {
7
+ availableApps = [];
8
+
9
+ const promises = Object.values(managers).map(async manager => {
10
+ if (await manager.isAvailable()) {
11
+ availableApps.push(manager);
12
+ }
13
+ });
14
+
15
+ await Promise.all(promises);
16
+ }
17
+
18
+ export async function getWallpaper() {
19
+ if (!availableApps) {
20
+ await setAvailableApps();
21
+ return getWallpaper();
22
+ }
23
+
24
+ const wallpapersVoted = new Map();
25
+ const promises = availableApps.map(async app => {
26
+ if (typeof app.get !== 'function') {
27
+ return;
28
+ }
29
+
30
+ const imagePath = await app.get();
31
+
32
+ if (typeof imagePath !== 'undefined') {
33
+ if (!wallpapersVoted.get(imagePath)) {
34
+ wallpapersVoted.set(imagePath, 0);
35
+ }
36
+
37
+ wallpapersVoted.set(imagePath, wallpapersVoted.get(imagePath) + 1);
38
+ }
39
+ });
40
+
41
+ await Promise.all(promises.map(promise => promise.catch(() => {})));
42
+
43
+ let wallpaperMostVoted;
44
+ let wallpaperMostVotedCount;
45
+
46
+ for (const [wallpaper] of wallpapersVoted) {
47
+ if (!wallpaperMostVoted || wallpaperMostVoted[wallpaper] > wallpaperMostVotedCount) {
48
+ wallpaperMostVoted = wallpaper;
49
+ wallpaperMostVotedCount = wallpaperMostVoted[wallpaper];
50
+ }
51
+ }
52
+
53
+ return wallpaperMostVoted;
54
+ }
55
+
56
+ export async function setWallpaper(imagePath) {
57
+ if (typeof imagePath !== 'string') {
58
+ throw new TypeError('Expected a string');
59
+ }
60
+
61
+ if (!availableApps) {
62
+ await setAvailableApps();
63
+ await setWallpaper(imagePath);
64
+ return;
65
+ }
66
+
67
+ const promises = availableApps.map(async app => {
68
+ if (typeof app.set === 'function') {
69
+ await app.set(path.resolve(imagePath));
70
+ }
71
+ });
72
+
73
+ await Promise.allSettled(promises);
74
+ }
75
+
76
+ export async function setLockscreen(imagePath) {
77
+ if (typeof imagePath !== 'string') {
78
+ throw new TypeError('Expected a string');
79
+ }
80
+
81
+ if (!availableApps) {
82
+ await setAvailableApps();
83
+ await setWallpaper(imagePath);
84
+ return;
85
+ }
86
+
87
+ const promises = availableApps.map(async app => {
88
+ if (typeof app.set === 'function') {
89
+ await app.set(path.resolve(imagePath));
90
+ }
91
+ });
92
+
93
+ await Promise.allSettled(promises);
94
+ }
@@ -0,0 +1,28 @@
1
+ import {promisify} from 'node:util';
2
+ import childProcess from 'node:child_process';
3
+ import {promises as fsPromises} from 'node:fs';
4
+
5
+ export const execFile = promisify(childProcess.execFile);
6
+ export const exec = promisify(childProcess.exec);
7
+
8
+ export async function commandExists(command) {
9
+ // `which` all commands and expect stdout to return a positive
10
+ try {
11
+ let {stdout} = await execFile('which', ['-a', command]);
12
+ stdout = stdout.trim();
13
+
14
+ if (!stdout) {
15
+ return false;
16
+ }
17
+
18
+ return true;
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ export function hasLine(string, lineToFind) {
25
+ return string.split('\n').find(line => line.trim() === lineToFind);
26
+ }
27
+
28
+ export const {readFile} = fsPromises;
Binary file
@@ -0,0 +1,71 @@
1
+ import childProcess from 'node:child_process';
2
+ import path from 'node:path';
3
+ import {fileURLToPath} from 'node:url';
4
+ import {promisify} from 'node:util';
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const execFile = promisify(childProcess.execFile);
8
+
9
+ // Binary source → https://github.com/sindresorhus/macos-wallpaper
10
+ const binary = path.join(__dirname, 'macos-wallpaper');
11
+
12
+ export async function getWallpaper({screen = 'main'} = {}) {
13
+ let {stdout} = await execFile(binary, ['get', '--screen', screen]);
14
+ stdout = stdout.trim();
15
+
16
+ if (screen === 'all') {
17
+ return stdout.split('\n');
18
+ }
19
+
20
+ return stdout;
21
+ }
22
+
23
+ export async function setWallpaper(imagePath, {screen = 'all', scale = 'auto'} = {}) {
24
+ if (typeof imagePath !== 'string') {
25
+ throw new TypeError('Expected a string');
26
+ }
27
+
28
+ const arguments_ = [
29
+ 'set',
30
+ path.resolve(imagePath),
31
+ '--screen',
32
+ screen,
33
+ '--scale',
34
+ scale,
35
+ ];
36
+
37
+ await execFile(binary, arguments_);
38
+ }
39
+
40
+ export async function setSolidColorWallpaper(color, {screen = 'all'} = {}) {
41
+ if (typeof color !== 'string') {
42
+ throw new TypeError('Expected a string');
43
+ }
44
+
45
+ const arguments_ = [
46
+ 'set-solid-color',
47
+ color,
48
+ '--screen',
49
+ screen,
50
+ ];
51
+
52
+ await execFile(binary, arguments_);
53
+ }
54
+
55
+ export async function screens() {
56
+ const {stdout} = await execFile(binary, ['screens']);
57
+ return stdout.trim().split('\n').map(line => line.replace(/^\d+ - /, ''));
58
+ }
59
+
60
+ export async function setLockscreen(imagePath) {
61
+ if (typeof imagePath !== 'string') {
62
+ throw new TypeError('Expected a string');
63
+ }
64
+
65
+ const arguments_ = [
66
+ 'set',
67
+ path.resolve(imagePath),
68
+ ];
69
+
70
+ await execFile(binary, arguments_);
71
+ }
Binary file
Binary file
@@ -0,0 +1,32 @@
1
+ import childProcess from 'node:child_process';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { promisify } from 'node:util';
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const execFile = promisify(childProcess.execFile);
8
+
9
+ // Binary source → https://github.com/sindresorhus/win-wallpaper
10
+ const binary = path.join(__dirname, 'windows-wallpaper.exe');
11
+ const binaryForLockscreen = path.join(__dirname, 'windows-lockscreen.exe');
12
+
13
+ export async function getWallpaper() {
14
+ const { stdout } = await execFile(binary);
15
+ return stdout.trim();
16
+ }
17
+
18
+ export async function setWallpaper(imagePath) {
19
+ if (typeof imagePath !== 'string') {
20
+ throw new TypeError('Expected a string');
21
+ }
22
+
23
+ await execFile(binary, [path.resolve(imagePath)]);
24
+ }
25
+
26
+ export async function setLockscreen(imagePath) {
27
+ if (typeof imagePath !== 'string') {
28
+ throw new TypeError('Expected a string');
29
+ }
30
+
31
+ await execFile(binaryForLockscreen, [path.resolve(imagePath)]);
32
+ }