-
Notifications
You must be signed in to change notification settings - Fork 576
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
Support MPRIS loop and volume change #749
Conversation
const delta = ((newIdx - curIdx) % 3 + 3) % 3; | ||
|
||
manuallySwitchingStatus = true; | ||
songControls.switchRepeat(delta); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is a bit of a hack (it presses the button the appropriate number of times to go to the desired state), but I can't see a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried making it work using the youtube api, but its weird and doesn't visually change the button state
So your solution is probably the best bet
plugins/shortcuts/mpris.js
Outdated
const newIdx = switches.indexOf(status); | ||
|
||
// Get a delta in the range [0,2] | ||
const delta = ((newIdx - curIdx) % 3 + 3) % 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of the first modulo? (newIdx - curIdx)
can only be in the range (-2, 2) then adding 3 is the exact result we need
Can be simplified to just
const delta = (newIdx - curIdx + 3) % 3;
See calc
0 = (0 - 0) % 3 + 3) % 3
0 = (0 - 0 + 3) % 3
2 = (0 - 1) % 3 + 3) % 3
2 = (0 - 1 + 3) % 3
1 = (0 - 2) % 3 + 3) % 3
1 = (0 - 2 + 3) % 3
1 = (1 - 0) % 3 + 3) % 3
1 = (1 - 0 + 3) % 3
0 = (1 - 1) % 3 + 3) % 3
0 = (1 - 1 + 3) % 3
2 = (1 - 2) % 3 + 3) % 3
2 = (1 - 2 + 3) % 3
2 = (2 - 0) % 3 + 3) % 3
2 = (2 - 0 + 3) % 3
1 = (2 - 1) % 3 + 3) % 3
1 = (2 - 1 + 3) % 3
0 = (2 - 2) % 3 + 3) % 3
0 = (2 - 2 + 3) % 3
for (let a = 0; a <= 2; a++) {
for (let b = 0; b <= 2; b++) {
console.log(`${((a - b) % 3 + 3) % 3} = (${a} - ${b}) % 3 + 3) % 3`);
console.log(`${(a - b + 3) % 3} = (${a} - ${b} + 3) % 3`);
}
}
also, I personally think that short variable names aren't helpful, its better if they are clear and informative
could maybe be named currentIndex
and targetIndex
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of the first modulo?
I originally had just (newIdx - curIdx) % 3
, but that has the wrong sign. I then simply added the general code. Good catch.
providers/song-controls.js
Outdated
@@ -20,7 +20,10 @@ module.exports = (win) => { | |||
go1sBack: () => pressKey(win, "h", ["shift"]), | |||
go1sForward: () => pressKey(win, "l", ["shift"]), | |||
shuffle: () => pressKey(win, "s"), | |||
switchRepeat: () => pressKey(win, "r"), | |||
switchRepeat: (n = 1) => { | |||
for (let i = 0; i != n; ++i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++i
is useless here since the value isn't used
i++
is more appropriate in this scenario (tho ultimately it's the same, the syntax is more clear)
also instead of i != n
you should use i < n
to avoid edge cases (this is standard)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny. I come from a C++ background, and if someone wrote for (auto i = 0; i < n; i++)
I would have requested it changed to the way I wrote it, as that's the standard there :D
LGTM (but can't personally test it since I don't have access to Linux currently) |
Anything I could do to help it get merged? |
I've just pushed another fix for a bug when using |
In javascript we always use (and could you change those? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok overall, could be worth applying Araxeus' suggestion on using ===
- feel free to apply the change, otherwise I can merge and do the fix afterwards
I've changed it. Do you want me to clean up the commits and force push? |
you should also change it in plugins/shortcuts/mpris.js lines 43-45-47 |
Volume change support is now implemented as well. |
Can this be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the contribution! ✅
This PR supports MPRIS loop status on linux, enabling
playerctl loop
to fetch andplayerctl loop None/Track/Playlist
to set.