Merge branch 'local-upstream/master' into use-ToastXML

This commit is contained in:
Araxeus
2023-02-09 23:54:32 +02:00
4 changed files with 94 additions and 60 deletions

View File

@ -65,31 +65,48 @@ jobs:
with: with:
run: yarn test run: yarn test
- name: Build on Mac # Build and release if it's the main repository
if: startsWith(matrix.os, 'macOS') - name: Build and release on Mac
if: startsWith(matrix.os, 'macOS') && github.repository == 'th-ch/youtube-music'
env: env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: | run: |
yarn run release:mac yarn run release:mac
- name: Build on Linux - name: Build and release on Linux
if: startsWith(matrix.os, 'ubuntu') if: startsWith(matrix.os, 'ubuntu') && github.repository == 'th-ch/youtube-music'
env: env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: | run: |
yarn run release:linux yarn run release:linux
- name: Build on Windows - name: Build and release on Windows
if: startsWith(matrix.os, 'windows') if: startsWith(matrix.os, 'windows') && github.repository == 'th-ch/youtube-music'
env: env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: | run: |
yarn run release:win yarn run release:win
# Only build without release if it is a fork
- name: Build on Mac
if: startsWith(matrix.os, 'macOS') && github.repository != 'th-ch/youtube-music'
run: |
yarn run build:mac
- name: Build on Linux
if: startsWith(matrix.os, 'ubuntu') && github.repository != 'th-ch/youtube-music'
run: |
yarn run build:linux
- name: Build on Windows
if: startsWith(matrix.os, 'windows') && github.repository != 'th-ch/youtube-music'
run: |
yarn run build:win
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Release YouTube Music name: Release YouTube Music
if: github.ref == 'refs/heads/master' if: github.repository == 'th-ch/youtube-music' && github.ref == 'refs/heads/master'
needs: build needs: build
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ node_modules
/assets/generated /assets/generated
electron-builder.yml electron-builder.yml
.vscode/settings.json .vscode/settings.json
.idea
.pnp.* .pnp.*
.yarn/* .yarn/*

View File

@ -1,5 +1,5 @@
const mpris = require("mpris-service"); const mpris = require("mpris-service");
const { ipcMain } = require("electron"); const {ipcMain} = require("electron");
const registerCallback = require("../../providers/song-info"); const registerCallback = require("../../providers/song-info");
const getSongControls = require("../../providers/song-controls"); const getSongControls = require("../../providers/song-controls");
const config = require("../../config"); const config = require("../../config");
@ -21,7 +21,7 @@ function setupMPRIS() {
/** @param {Electron.BrowserWindow} win */ /** @param {Electron.BrowserWindow} win */
function registerMPRIS(win) { function registerMPRIS(win) {
const songControls = getSongControls(win); const songControls = getSongControls(win);
const { playPause, next, previous, volumeMinus10, volumePlus10 } = songControls; const {playPause, next, previous, volumeMinus10, volumePlus10, shuffle} = songControls;
try { try {
const secToMicro = n => Math.round(Number(n) * 1e6); const secToMicro = n => Math.round(Number(n) * 1e6);
const microToSec = n => Math.round(Number(n) / 1e6); const microToSec = n => Math.round(Number(n) / 1e6);
@ -43,33 +43,23 @@ function registerMPRIS(win) {
let currentSeconds = 0; let currentSeconds = 0;
ipcMain.on('timeChanged', (_, t) => currentSeconds = t); ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
let currentLoopStatus = undefined;
let manuallySwitchingStatus = false;
ipcMain.on("repeatChanged", (_, mode) => { ipcMain.on("repeatChanged", (_, mode) => {
if (manuallySwitchingStatus) if (mode === "NONE")
return; player.loopStatus = mpris.LOOP_STATUS_NONE;
else if (mode === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
if (mode === "Repeat off") player.loopStatus = mpris.LOOP_STATUS_PLAYLIST;
currentLoopStatus = "None"; else if (mode === "ALL")
else if (mode === "Repeat one") player.loopStatus = mpris.LOOP_STATUS_TRACK;
currentLoopStatus = "Track";
else if (mode === "Repeat all")
currentLoopStatus = "Playlist";
player.loopStatus = currentLoopStatus;
}); });
player.on("loopStatus", (status) => { player.on("loopStatus", (status) => {
// switchRepeat cycles between states in that order // switchRepeat cycles between states in that order
const switches = ["None", "Playlist", "Track"]; const switches = [mpris.LOOP_STATUS_NONE, mpris.LOOP_STATUS_PLAYLIST, mpris.LOOP_STATUS_TRACK];
const currentIndex = switches.indexOf(currentLoopStatus); const currentIndex = switches.indexOf(player.loopStatus);
const targetIndex = switches.indexOf(status); const targetIndex = switches.indexOf(status);
// Get a delta in the range [0,2] // Get a delta in the range [0,2]
const delta = (targetIndex - currentIndex + 3) % 3; const delta = (targetIndex - currentIndex + 3) % 3;
manuallySwitchingStatus = true;
songControls.switchRepeat(delta); songControls.switchRepeat(delta);
manuallySwitchingStatus = false;
}) })
player.getPosition = () => secToMicro(currentSeconds) player.getPosition = () => secToMicro(currentSeconds)
@ -80,19 +70,19 @@ function registerMPRIS(win) {
}); });
player.on("play", () => { player.on("play", () => {
if (player.playbackStatus !== 'Playing') { if (player.playbackStatus !== mpris.PLAYBACK_STATUS_PLAYING) {
player.playbackStatus = 'Playing'; player.playbackStatus = mpris.PLAYBACK_STATUS_PLAYING;
playPause() playPause()
} }
}); });
player.on("pause", () => { player.on("pause", () => {
if (player.playbackStatus !== 'Paused') { if (player.playbackStatus !== mpris.PLAYBACK_STATUS_PAUSED) {
player.playbackStatus = 'Paused'; player.playbackStatus = mpris.PLAYBACK_STATUS_PAUSED;
playPause() playPause()
} }
}); });
player.on("playpause", () => { player.on("playpause", () => {
player.playbackStatus = player.playbackStatus === 'Playing' ? "Paused" : "Playing"; player.playbackStatus = player.playbackStatus === mpris.PLAYBACK_STATUS_PLAYING ? mpris.PLAYBACK_STATUS_PAUSED : mpris.PLAYBACK_STATUS_PLAYING;
playPause(); playPause();
}); });
@ -102,40 +92,66 @@ function registerMPRIS(win) {
player.on('seek', seekBy); player.on('seek', seekBy);
player.on('position', seekTo); player.on('position', seekTo);
ipcMain.on('volumeChanged', (_, value) => { player.on('shuffle', (enableShuffle) => {
player.volume = value; shuffle();
}); });
player.on('volume', (newVolume) => {
if (config.plugins.isEnabled('precise-volume')) {
// With precise volume we can set the volume to the exact value.
win.webContents.send('setVolume', newVolume)
} else {
// With keyboard shortcuts we can only change the volume in increments of 10, so round it.
const deltaVolume = Math.round((newVolume - player.volume) / 10);
if (deltaVolume > 0) { let mprisVolNewer = false;
for (let i = 0; i < deltaVolume; i++) let autoUpdate = false;
volumePlus10(); ipcMain.on('volumeChanged', (_, newVol) => {
if (parseInt(player.volume * 100) !== newVol) {
if (mprisVolNewer) {
mprisVolNewer = false;
autoUpdate = false;
} else { } else {
for (let i = 0; i < -deltaVolume; i++) autoUpdate = true;
volumeMinus10(); player.volume = parseFloat((newVol / 100).toFixed(2));
mprisVolNewer = false;
autoUpdate = false;
} }
} }
}); });
registerCallback(songInfo => { player.on('volume', (newVolume) => {
if (player) { if (config.plugins.isEnabled('precise-volume')) {
const data = { // With precise volume we can set the volume to the exact value.
'mpris:length': secToMicro(songInfo.songDuration), let newVol = parseInt(newVolume * 100);
'mpris:artUrl': songInfo.imageSrc, if (parseInt(player.volume * 100) !== newVol) {
'xesam:title': songInfo.title, if (!autoUpdate){
'xesam:artist': [songInfo.artist], mprisVolNewer = true;
autoUpdate = false;
win.webContents.send('setVolume', newVol);
}
}
} else {
// With keyboard shortcuts we can only change the volume in increments of 10, so round it.
let deltaVolume = Math.round((newVolume - player.volume) * 10);
while (deltaVolume !== 0 && deltaVolume > 0) {
volumePlus10();
player.volume = player.volume + 0.1;
deltaVolume--;
}
while (deltaVolume !== 0 && deltaVolume < 0) {
volumeMinus10();
player.volume = player.volume - 0.1;
deltaVolume++;
}
}
});
registerCallback(songInfo => {
if (player) {
const data = {
'mpris:length': secToMicro(songInfo.songDuration),
'mpris:artUrl': songInfo.imageSrc,
'xesam:title': songInfo.title,
'xesam:artist': [songInfo.artist],
'mpris:trackid': '/' 'mpris:trackid': '/'
}; };
if (songInfo.album) data['xesam:album'] = songInfo.album; if (songInfo.album) data['xesam:album'] = songInfo.album;
player.metadata = data; player.metadata = data;
player.seeked(secToMicro(songInfo.elapsedSeconds)) player.seeked(secToMicro(songInfo.elapsedSeconds));
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing" player.playbackStatus = songInfo.isPaused ? mpris.PLAYBACK_STATUS_PAUSED : mpris.PLAYBACK_STATUS_PLAYING;
} }
}) })

View File

@ -37,12 +37,12 @@ module.exports.setupTimeChangedListener = singleton(() => {
module.exports.setupRepeatChangedListener = singleton(() => { module.exports.setupRepeatChangedListener = singleton(() => {
const repeatObserver = new MutationObserver(mutations => { const repeatObserver = new MutationObserver(mutations => {
ipcRenderer.send('repeatChanged', mutations[0].target.title); ipcRenderer.send('repeatChanged', mutations[0].target.__dataHost.getState().queue.repeatMode);
}); });
repeatObserver.observe($('#right-controls .repeat'), { attributeFilter: ["title"] }); repeatObserver.observe($('#right-controls .repeat'), { attributeFilter: ["title"] });
// Emit the initial value as well; as it's persistent between launches. // Emit the initial value as well; as it's persistent between launches.
ipcRenderer.send('repeatChanged', $('#right-controls .repeat').title); ipcRenderer.send('repeatChanged', $('ytmusic-player-bar').getState().queue.repeatMode);
}); });
module.exports.setupVolumeChangedListener = singleton((api) => { module.exports.setupVolumeChangedListener = singleton((api) => {
@ -58,11 +58,11 @@ module.exports = () => {
ipcRenderer.on("setupTimeChangedListener", async () => { ipcRenderer.on("setupTimeChangedListener", async () => {
this.setupTimeChangedListener(); this.setupTimeChangedListener();
}); });
ipcRenderer.on("setupRepeatChangedListener", async () => { ipcRenderer.on("setupRepeatChangedListener", async () => {
this.setupRepeatChangedListener(); this.setupRepeatChangedListener();
}); });
ipcRenderer.on("setupVolumeChangedListener", async () => { ipcRenderer.on("setupVolumeChangedListener", async () => {
this.setupVolumeChangedListener(apiEvent.detail); this.setupVolumeChangedListener(apiEvent.detail);
}); });
@ -70,7 +70,7 @@ module.exports = () => {
ipcRenderer.on("setupSeekedListener", async () => { ipcRenderer.on("setupSeekedListener", async () => {
this.setupSeekedListener(); this.setupSeekedListener();
}); });
const video = $('video'); const video = $('video');
// name = "dataloaded" and abit later "dataupdated" // name = "dataloaded" and abit later "dataupdated"
apiEvent.detail.addEventListener('videodatachange', (name, _dataEvent) => { apiEvent.detail.addEventListener('videodatachange', (name, _dataEvent) => {