Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows shell with forever #25

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions lib/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const fs = pify(fileSystem);
const appsList = [
{
cmd: 'gsettings',
set: ['set',
set: [
'set',
'org.gnome.desktop.background',
'picture-uri',
'file://%s'
],
get: ['get',
get: [
'get',
'org.gnome.desktop.background',
'picture-uri'
],
Expand Down Expand Up @@ -67,7 +69,8 @@ const appsList = [
cmd: 'dconf',
set: ['write',
'/org/mate/desktop/background/picture-filename',
'"%s"'],
'"%s"'
],
get: ['read',
'/org/mate/desktop/background/picture-filename'
],
Expand Down Expand Up @@ -122,6 +125,14 @@ function isCinnamon() {
.catch(() => {});
}

function isMATE() {
const args = ['writable', 'org.mate.background', 'picture-filename'];

return cp.execFile('gsettings', args)
.then(out => out.trim() === 'true')
.catch(() => {});
}

exports.get = function get() {
if (!availableApps) {
return setAvailableApps().then(get);
Expand All @@ -137,20 +148,28 @@ exports.get = function get() {
}

if (app.cmd === 'gsettings') {
return isCinnamon().then(cinnamon => {
const getArgs = app.get.slice();
const getArgs = app.get.slice();
return isCinnamon()
.then(cinnamon => {
if (cinnamon) {
getArgs[1] = 'org.cinnamon.desktop.background';
}
return cp.execFile(app.cmd, getArgs).then(stdout => {
stdout = stdout.trim();
})
.then(() => isMATE())
.then(mate => {
if (mate) {
getArgs.splice(1, 2, 'org.mate.background', 'picture-filename');
}
})
.then(() => cp.execFile(app.cmd, getArgs))
.then(stdout => {
stdout = stdout.trim();

if (typeof app.transform === 'function') {
return app.transform(stdout);
}
if (typeof app.transform === 'function') {
return app.transform(stdout);
}

return stdout;
});
return stdout;
});
}

Expand Down Expand Up @@ -180,12 +199,19 @@ exports.set = function set(imagePath) {
params[params.length - 1] = params[params.length - 1].replace('%s', path.resolve(imagePath));

if (app.cmd === 'gsettings') {
return isCinnamon().then(cinnamon => {
return isCinnamon()
.then(cinnamon => {
if (cinnamon) {
params[1] = 'org.cinnamon.desktop.background';
}
return cp.execFile(app.cmd, params);
});
})
.then(() => isMATE())
.then(mate => {
if (mate) {
params.splice(1, 3, 'org.mate.background', 'picture-filename', params[3].replace(/^file:\/\//, ''));
}
})
.then(() => cp.execFile(app.cmd, params));
}

return cp.execFile(app.cmd, params);
Expand Down
21 changes: 20 additions & 1 deletion lib/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const childProcess = require('child_process');
const pify = require('pify');

const spawn = childProcess.spawn;
const execFile = pify(childProcess.execFile);

// Binary source → https://github.com/sindresorhus/win-wallpaper
Expand All @@ -15,5 +16,23 @@ exports.set = imagePath => {
return Promise.reject(new TypeError('Expected a string'));
}

return execFile(bin, [path.resolve(imagePath)]);
return new Promise((resolve, reject) => {
const proc = spawn(bin, [path.resolve(imagePath)], {
detached: true
});

let err = '';

proc.stderr.on('data', data => {
err += data;
});

proc.on('close', code => {
if (code === 0) {
resolve();
} else {
reject(new Error('Program terminated with code ' + code + ':\n' + err));
}
});
});
};