mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 12:42:06 +00:00
lint
This commit is contained in:
@ -1,9 +1,8 @@
|
|||||||
const { globalShortcut, ipcMain } = require("electron");
|
const { globalShortcut } = require("electron");
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
const electronLocalshortcut = require("electron-localshortcut");
|
const electronLocalshortcut = require("electron-localshortcut");
|
||||||
const getSongControls = require("../../providers/song-controls");
|
const getSongControls = require("../../providers/song-controls");
|
||||||
const { setupMPRIS } = require("./mpris");
|
const registerMPRIS = require("./mpris");
|
||||||
const registerCallback = require("../../providers/song-info");
|
|
||||||
|
|
||||||
function _registerGlobalShortcut(webContents, shortcut, action) {
|
function _registerGlobalShortcut(webContents, shortcut, action) {
|
||||||
globalShortcut.register(shortcut, () => {
|
globalShortcut.register(shortcut, () => {
|
||||||
@ -30,7 +29,7 @@ function registerShortcuts(win, options) {
|
|||||||
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
|
||||||
if (is.linux()) registerMPRIS();
|
if (is.linux()) registerMPRIS(win);
|
||||||
|
|
||||||
const { global, local } = options;
|
const { global, local } = options;
|
||||||
const shortcutOptions = { global, local };
|
const shortcutOptions = { global, local };
|
||||||
@ -58,72 +57,6 @@ function registerShortcuts(win, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function registerMPRIS() {
|
|
||||||
try {
|
|
||||||
const secToMicro = n => Math.round(Number(n) * (1000 * 1000));
|
|
||||||
const microToSec = n => Math.round(Number(n) / 1000 / 1000);
|
|
||||||
|
|
||||||
const seekTo = e => win.webContents.send("seekTo", microToSec(e.position));
|
|
||||||
const seek = o => win.webContents.send("seek", microToSec(o));
|
|
||||||
|
|
||||||
const player = setupMPRIS();
|
|
||||||
|
|
||||||
const mprisSeek = player.seeked;
|
|
||||||
|
|
||||||
win.webContents.send("registerOnSeek");
|
|
||||||
|
|
||||||
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
|
|
||||||
|
|
||||||
let currentSeconds = 0;
|
|
||||||
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
|
|
||||||
|
|
||||||
player.getPosition = () => secToMicro(currentSeconds)
|
|
||||||
|
|
||||||
player.on("raise", () => {
|
|
||||||
win.setSkipTaskbar(false);
|
|
||||||
win.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
player.on("play", () => {
|
|
||||||
if (player.playbackStatus !== 'Playing') {
|
|
||||||
player.playbackStatus = 'Playing';
|
|
||||||
playPause()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
player.on("pause", () => {
|
|
||||||
if (player.playbackStatus !== 'Paused') {
|
|
||||||
player.playbackStatus = 'Paused';
|
|
||||||
playPause()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
player.on("playpause", playPause);
|
|
||||||
player.on("next", next);
|
|
||||||
player.on("previous", previous);
|
|
||||||
|
|
||||||
player.on('seek', seek);
|
|
||||||
player.on('position', seekTo);
|
|
||||||
|
|
||||||
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': '/'
|
|
||||||
};
|
|
||||||
if (songInfo.album) data['xesam:album'] = songInfo.album;
|
|
||||||
player.metadata = data;
|
|
||||||
mprisSeek(secToMicro(songInfo.elapsedSeconds))
|
|
||||||
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Error in MPRIS", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = registerShortcuts;
|
module.exports = registerShortcuts;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
const mpris = require("mpris-service");
|
const mpris = require("mpris-service");
|
||||||
|
const { ipcMain } = require("electron");
|
||||||
|
const registerCallback = require("../../providers/song-info");
|
||||||
|
|
||||||
function setupMPRIS() {
|
function setupMPRIS() {
|
||||||
const player = mpris({
|
const player = mpris({
|
||||||
@ -14,6 +16,71 @@ function setupMPRIS() {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
function registerMPRIS(win) {
|
||||||
setupMPRIS,
|
try {
|
||||||
};
|
const secToMicro = n => Math.round(Number(n) * 1e6);
|
||||||
|
const microToSec = n => Math.round(Number(n) / 1e6);
|
||||||
|
|
||||||
|
const seekTo = e => win.webContents.send("seekTo", microToSec(e.position));
|
||||||
|
const seek = o => win.webContents.send("seek", microToSec(o));
|
||||||
|
|
||||||
|
const player = setupMPRIS();
|
||||||
|
|
||||||
|
const mprisSeek = player.seeked;
|
||||||
|
|
||||||
|
win.webContents.send("registerOnSeek");
|
||||||
|
|
||||||
|
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
|
||||||
|
|
||||||
|
let currentSeconds = 0;
|
||||||
|
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
|
||||||
|
|
||||||
|
player.getPosition = () => secToMicro(currentSeconds)
|
||||||
|
|
||||||
|
player.on("raise", () => {
|
||||||
|
win.setSkipTaskbar(false);
|
||||||
|
win.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
player.on("play", () => {
|
||||||
|
if (player.playbackStatus !== 'Playing') {
|
||||||
|
player.playbackStatus = 'Playing';
|
||||||
|
playPause()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
player.on("pause", () => {
|
||||||
|
if (player.playbackStatus !== 'Paused') {
|
||||||
|
player.playbackStatus = 'Paused';
|
||||||
|
playPause()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
player.on("playpause", playPause);
|
||||||
|
player.on("next", next);
|
||||||
|
player.on("previous", previous);
|
||||||
|
|
||||||
|
player.on('seek', seek);
|
||||||
|
player.on('position', seekTo);
|
||||||
|
|
||||||
|
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': '/'
|
||||||
|
};
|
||||||
|
if (songInfo.album) data['xesam:album'] = songInfo.album;
|
||||||
|
player.metadata = data;
|
||||||
|
mprisSeek(secToMicro(songInfo.elapsedSeconds))
|
||||||
|
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Error in MPRIS", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = registerMPRIS;
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const fetch = require('node-fetch');
|
|||||||
|
|
||||||
const registerCallback = require("../../providers/song-info");
|
const registerCallback = require("../../providers/song-info");
|
||||||
|
|
||||||
const secToMilisec = t => Math.round(Number(t) * 1000);
|
const secToMilisec = t => Math.round(Number(t) * 1e3);
|
||||||
const data = {
|
const data = {
|
||||||
cover_url: '',
|
cover_url: '',
|
||||||
title: '',
|
title: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user