-
Notifications
You must be signed in to change notification settings - Fork 487
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
Changes from 1 commit
6e1c50e
bba4990
9932fd7
e7e8738
2499f57
d9c5106
dfba3d9
0f96da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,35 @@ function registerMPRIS(win) { | |
let currentSeconds = 0; | ||
ipcMain.on('timeChanged', (_, t) => currentSeconds = t); | ||
|
||
let currentLoopStatus = undefined; | ||
let manuallySwitchingStatus = false; | ||
ipcMain.on("repeatChanged", (_, mode) => { | ||
if (manuallySwitchingStatus) | ||
return; | ||
|
||
if (mode == "Repeat off") | ||
currentLoopStatus = "None"; | ||
else if (mode == "Repeat one") | ||
currentLoopStatus = "Track"; | ||
else if (mode == "Repeat all") | ||
currentLoopStatus = "Playlist"; | ||
|
||
player.loopStatus = currentLoopStatus; | ||
}); | ||
player.on("loopStatus", (status) => { | ||
// switchRepeat cycles between states in that order | ||
const switches = ["None", "Playlist", "Track"]; | ||
const curIdx = switches.indexOf(currentLoopStatus); | ||
const newIdx = switches.indexOf(status); | ||
|
||
// Get a delta in the range [0,2] | ||
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 commentThe 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 commentThe 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 |
||
manuallySwitchingStatus = false; | ||
}) | ||
|
||
player.getPosition = () => secToMicro(currentSeconds) | ||
|
||
player.on("raise", () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
also instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny. I come from a C++ background, and if someone wrote |
||
pressKey(win, "r"); | ||
}, | ||
// General | ||
volumeMinus10: () => pressKey(win, "-"), | ||
volumePlus10: () => pressKey(win, "="), | ||
|
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 needCan be simplified to just
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
also, I personally think that short variable names aren't helpful, its better if they are clear and informative
could maybe be named
currentIndex
andtargetIndex
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.
I originally had just
(newIdx - curIdx) % 3
, but that has the wrong sign. I then simply added the general code. Good catch.