1
- const { globalShortcut, ipcMain } = require ( "electron" ) ;
1
+ const { globalShortcut } = require ( "electron" ) ;
2
2
const is = require ( "electron-is" ) ;
3
3
const electronLocalshortcut = require ( "electron-localshortcut" ) ;
4
4
const getSongControls = require ( "../../providers/song-controls" ) ;
5
- const { setupMPRIS } = require ( "./mpris" ) ;
6
- const registerCallback = require ( "../../providers/song-info" ) ;
5
+ const registerMPRIS = require ( "./mpris" ) ;
7
6
8
7
function _registerGlobalShortcut ( webContents , shortcut , action ) {
9
8
globalShortcut . register ( shortcut , ( ) => {
@@ -30,7 +29,7 @@ function registerShortcuts(win, options) {
30
29
_registerLocalShortcut ( win , "CommandOrControl+F" , search ) ;
31
30
_registerLocalShortcut ( win , "CommandOrControl+L" , search ) ;
32
31
33
- if ( is . linux ( ) ) registerMPRIS ( ) ;
32
+ if ( is . linux ( ) ) registerMPRIS ( win ) ;
34
33
35
34
const { global, local } = options ;
36
35
const shortcutOptions = { global, local } ;
@@ -58,72 +57,6 @@ function registerShortcuts(win, options) {
58
57
}
59
58
}
60
59
}
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
- }
127
60
}
128
61
129
62
module . exports = registerShortcuts ;
0 commit comments