Skip to content

Commit 4362101

Browse files
committed
lint
1 parent 02d5b78 commit 4362101

File tree

3 files changed

+74
-74
lines changed

3 files changed

+74
-74
lines changed

plugins/shortcuts/back.js

+3-70
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const { globalShortcut, ipcMain } = require("electron");
1+
const { globalShortcut } = require("electron");
22
const is = require("electron-is");
33
const electronLocalshortcut = require("electron-localshortcut");
44
const getSongControls = require("../../providers/song-controls");
5-
const { setupMPRIS } = require("./mpris");
6-
const registerCallback = require("../../providers/song-info");
5+
const registerMPRIS = require("./mpris");
76

87
function _registerGlobalShortcut(webContents, shortcut, action) {
98
globalShortcut.register(shortcut, () => {
@@ -30,7 +29,7 @@ function registerShortcuts(win, options) {
3029
_registerLocalShortcut(win, "CommandOrControl+F", search);
3130
_registerLocalShortcut(win, "CommandOrControl+L", search);
3231

33-
if (is.linux()) registerMPRIS();
32+
if (is.linux()) registerMPRIS(win);
3433

3534
const { global, local } = options;
3635
const shortcutOptions = { global, local };
@@ -58,72 +57,6 @@ function registerShortcuts(win, options) {
5857
}
5958
}
6059
}
61-
function registerMPRIS() {
62-
try {
63-
const secToMicro = n => Math.round(Number(n) * (1000 * 1000));
64-
const microToSec = n => Math.round(Number(n) / 1000 / 1000);
65-
66-
const seekTo = e => win.webContents.send("seekTo", microToSec(e.position));
67-
const seek = o => win.webContents.send("seek", microToSec(o));
68-
69-
const player = setupMPRIS();
70-
71-
const mprisSeek = player.seeked;
72-
73-
win.webContents.send("registerOnSeek");
74-
75-
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
76-
77-
let currentSeconds = 0;
78-
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
79-
80-
player.getPosition = () => secToMicro(currentSeconds)
81-
82-
player.on("raise", () => {
83-
win.setSkipTaskbar(false);
84-
win.show();
85-
});
86-
87-
player.on("play", () => {
88-
if (player.playbackStatus !== 'Playing') {
89-
player.playbackStatus = 'Playing';
90-
playPause()
91-
}
92-
});
93-
player.on("pause", () => {
94-
if (player.playbackStatus !== 'Paused') {
95-
player.playbackStatus = 'Paused';
96-
playPause()
97-
}
98-
});
99-
100-
player.on("playpause", playPause);
101-
player.on("next", next);
102-
player.on("previous", previous);
103-
104-
player.on('seek', seek);
105-
player.on('position', seekTo);
106-
107-
registerCallback(songInfo => {
108-
if (player) {
109-
const data = {
110-
'mpris:length': secToMicro(songInfo.songDuration),
111-
'mpris:artUrl': songInfo.imageSrc,
112-
'xesam:title': songInfo.title,
113-
'xesam:artist': songInfo.artist,
114-
'mpris:trackid': '/'
115-
};
116-
if (songInfo.album) data['xesam:album'] = songInfo.album;
117-
player.metadata = data;
118-
mprisSeek(secToMicro(songInfo.elapsedSeconds))
119-
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
120-
}
121-
})
122-
123-
} catch (e) {
124-
console.warn("Error in MPRIS", e);
125-
}
126-
}
12760
}
12861

12962
module.exports = registerShortcuts;

plugins/shortcuts/mpris.js

+70-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const mpris = require("mpris-service");
2+
const { ipcMain } = require("electron");
3+
const registerCallback = require("../../providers/song-info");
24

35
function setupMPRIS() {
46
const player = mpris({
@@ -14,6 +16,71 @@ function setupMPRIS() {
1416
return player;
1517
}
1618

17-
module.exports = {
18-
setupMPRIS,
19-
};
19+
function registerMPRIS(win) {
20+
try {
21+
const secToMicro = n => Math.round(Number(n) * 1e6);
22+
const microToSec = n => Math.round(Number(n) / 1e6);
23+
24+
const seekTo = e => win.webContents.send("seekTo", microToSec(e.position));
25+
const seek = o => win.webContents.send("seek", microToSec(o));
26+
27+
const player = setupMPRIS();
28+
29+
const mprisSeek = player.seeked;
30+
31+
win.webContents.send("registerOnSeek");
32+
33+
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
34+
35+
let currentSeconds = 0;
36+
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
37+
38+
player.getPosition = () => secToMicro(currentSeconds)
39+
40+
player.on("raise", () => {
41+
win.setSkipTaskbar(false);
42+
win.show();
43+
});
44+
45+
player.on("play", () => {
46+
if (player.playbackStatus !== 'Playing') {
47+
player.playbackStatus = 'Playing';
48+
playPause()
49+
}
50+
});
51+
player.on("pause", () => {
52+
if (player.playbackStatus !== 'Paused') {
53+
player.playbackStatus = 'Paused';
54+
playPause()
55+
}
56+
});
57+
58+
player.on("playpause", playPause);
59+
player.on("next", next);
60+
player.on("previous", previous);
61+
62+
player.on('seek', seek);
63+
player.on('position', seekTo);
64+
65+
registerCallback(songInfo => {
66+
if (player) {
67+
const data = {
68+
'mpris:length': secToMicro(songInfo.songDuration),
69+
'mpris:artUrl': songInfo.imageSrc,
70+
'xesam:title': songInfo.title,
71+
'xesam:artist': songInfo.artist,
72+
'mpris:trackid': '/'
73+
};
74+
if (songInfo.album) data['xesam:album'] = songInfo.album;
75+
player.metadata = data;
76+
mprisSeek(secToMicro(songInfo.elapsedSeconds))
77+
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
78+
}
79+
})
80+
81+
} catch (e) {
82+
console.warn("Error in MPRIS", e);
83+
}
84+
}
85+
86+
module.exports = registerMPRIS;

plugins/tuna-obs/back.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fetch = require('node-fetch');
33

44
const registerCallback = require("../../providers/song-info");
55

6-
const secToMilisec = t => Math.round(Number(t) * 1000);
6+
const secToMilisec = t => Math.round(Number(t) * 1e3);
77
const data = {
88
cover_url: '',
99
title: '',

0 commit comments

Comments
 (0)