Skip to content

Commit ce2f417

Browse files
xero08sindresorhus
authored andcommitted
Fix setting wallpaper for dark style on Gnome (sindresorhus#96)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent ea12e5e commit ce2f417

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

source/linux/background-managers/gnome.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
'use strict';
2-
const {commandExists, execFile} = require('../util.js');
2+
const {commandExists, execFile, hasLine} = require('../util.js');
33

44
exports.isAvailable = () => commandExists('gsettings');
55

6+
async function isDarkStyle() {
7+
const {stdout} = await execFile('gsettings', [
8+
'get',
9+
'org.gnome.desktop.interface',
10+
'color-scheme',
11+
]);
12+
13+
return Boolean(hasLine(stdout, '\'prefer-dark\''));
14+
}
15+
616
exports.set = async imagePath => {
17+
const keyForStyle = (await isDarkStyle()) ? 'picture-uri-dark' : 'picture-uri';
18+
719
await execFile('gsettings', [
820
'set',
921
'org.gnome.desktop.background',
10-
'picture-uri',
22+
keyForStyle,
1123
`file://${imagePath}`
1224
]);
1325
};
1426

1527
exports.get = async () => {
28+
const keyForStyle = (await isDarkStyle()) ? 'picture-uri-dark' : 'picture-uri';
29+
1630
const {stdout} = await execFile('gsettings', [
1731
'get',
1832
'org.gnome.desktop.background',
19-
'picture-uri'
33+
keyForStyle
2034
]);
2135

2236
return stdout.trim().slice(8, -1);

source/linux/background-managers/swww.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function initialize() {
1313

1414
throw new Error(`Failed to set image for swww: ${error.stderr}`);
1515
}
16-
};
16+
}
1717

1818
exports.get = async () => {
1919
await initialize();

0 commit comments

Comments
 (0)