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

added swaybg support #93

Merged
merged 7 commits into from
Oct 14, 2023
Merged

added swaybg support #93

merged 7 commits into from
Oct 14, 2023

Conversation

VardanHeroic
Copy link
Contributor

@VardanHeroic VardanHeroic commented Sep 8, 2023

Added swaybg support

@sindresorhus
Copy link
Owner

Please fix the reported lint issues and also follow the style of the other platforms.

@VardanHeroic
Copy link
Contributor Author

Also I promisified 'spawn'

}

export async function set(imagePath) {
await spawn('swaybg', ['-i', imagePath, '-m', 'fill']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use long-flags if possible, for readbility.

}

export async function set(imagePath) {
await spawn('swaybg', ['-i', imagePath, '-m', 'fill']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any why can't you use the existing execFile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because swaybg must work constantly to set wallpaper. When I use execFile the serWallpaper function never completes due to which any code written after the function is not executed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For swaymsg you must install sway but you can use swaybg without sway

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

export async function set(imagePath) {
await spawn('swaybg', ['-i', imagePath, '-m', 'fill']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args,
) => new Promise(resolve => {
const cp = childProcess.spawn(cmd, args);
cp.on('spawn', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a code comment on why we resolve on spawn, which makes no sense without the context.

Comment on lines 17 to 23
if (code) {
console.log(`swaybg exited with ${code} code`);
}

if (signal) {
console.log(`swaybg exited with ${signal} signal`);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be properly handled with reject/resolve and not log.

Copy link
Contributor Author

@VardanHeroic VardanHeroic Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that then I realized that swaybg can't exit from invalid argument and the only way that user can stop swaybg(accidentally or not) is writing wrong flag or killing it by themself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I just removed that part of code

await spawn('swaybg', ['--image', imagePath, '--mode', 'fill']);
} catch (error) {
console.error(error);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't catch and log the error.

cp.stderr.on('data', data => {
if (data.includes('Failed to load image')) {
cp.kill('SIGINT');
reject();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to preserve the error message. Promise rejecting without anything is very useless to an end-user using this library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recovered the error message, but I don't understand why I need this error message if I didn't catch it.

@sindresorhus sindresorhus merged commit 96fd60f into sindresorhus:main Oct 14, 2023
sunjw pushed a commit to sunjw/npm-wallpaper that referenced this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants