forked from ytmdesktop/ytmdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmediaProvider.js
122 lines (106 loc) · 4.31 KB
/
mediaProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const __ = require( './translateProvider' );
const path = require('path');
function mediaPlayPauseTrack( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: ';' } );
console.log('mediaPlayPause');
}
function mediaStopTrack( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: ';' } );
console.log('mediaStop');
}
function mediaNextTrack( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: 'j' } );
console.log('mediaNext');
}
function mediaPreviousTrack( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: 'k' } );
console.log('mediaPrevious');
}
function mediaUpVote( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: '+' } );
console.log('mediaUpVote');
}
function mediaDownVote( mainWindow ) {
mainWindow.webContents.sendInputEvent( { type:'keydown', keyCode: '-' } );
console.log('mediaDownVote');
}
function createThumbar( mainWindow, type, likeStatus ) {
let thumbsUp = 'assets/img/controls/thumbs-up-button-outline.png';
let thumbsDown = 'assets/img/controls/thumbs-down-button-outline.png';
let thumbsReverse = '';
switch( likeStatus ) {
case 'LIKE':
thumbsUp = 'assets/img/controls/thumbs-up-button.png';
thumbsDown = 'assets/img/controls/thumbs-down-button-outline.png';
thumbsReverse = 'INDIFFERENT';
break;
case 'DISLIKE':
thumbsUp = 'assets/img/controls/thumbs-up-button-outline.png';
thumbsDown = 'assets/img/controls/thumbs-down-button.png';
thumbsReverse = 'INDIFFERENT';
break;
case 'INDIFFERENT':
thumbsUp = 'assets/img/controls/thumbs-up-button-outline.png';
thumbsDown = 'assets/img/controls/thumbs-down-button-outline.png';
thumbsReverse = ( likeStatus == 'LIKE' ) ? 'DISLIKE' : 'LIKE';
break;
}
playOrPause = {
tooltip: __.trans( 'MEDIA_CONTROL_PLAY' ),
icon: path.join( __dirname, 'assets/img/controls/play-button.png' ),
click: function() { mediaPlayPauseTrack( mainWindow.getBrowserView() ) }
}
if ( type !== 'play' ) {
playOrPause.tooltip = __.trans( 'MEDIA_CONTROL_PAUSE' );
playOrPause.icon = path.join( __dirname, 'assets/img/controls/pause-button.png' );
}
mainWindow.setThumbarButtons([
{
tooltip: __.trans( 'MEDIA_CONTROL_THUMBS_DOWN' ),
icon: path.join( __dirname, thumbsDown ),
click: function() { mediaDownVote( mainWindow.getBrowserView(), createThumbar( mainWindow, type, thumbsReverse ) ) }
},
{
icon: path.join( __dirname, 'assets/img/null.png' ),
flags: [ 'disabled', 'nobackground' ]
},
{
tooltip: __.trans( 'MEDIA_CONTROL_PREVIOUS' ),
icon: path.join( __dirname, 'assets/img/controls/play-previous-button.png' ),
click: function() { mediaPreviousTrack( mainWindow.getBrowserView() ) }
},
{
tooltip: playOrPause.tooltip,
icon: playOrPause.icon,
click: function() { mediaPlayPauseTrack( mainWindow.getBrowserView() ) }
},
{
tooltip: __.trans( 'MEDIA_CONTROL_NEXT' ),
icon: path.join( __dirname, 'assets/img/controls/play-next-button.png' ),
click: function() { mediaNextTrack( mainWindow.getBrowserView() ) }
},
{
icon: path.join( __dirname, 'assets/img/null.png' ),
flags: [ 'disabled', 'nobackground' ]
},
{
tooltip: __.trans( 'MEDIA_CONTROL_THUMBS_UP' ),
icon: path.join( __dirname, thumbsUp ),
click: function() { mediaUpVote( mainWindow.getBrowserView(), createThumbar( mainWindow, type, thumbsReverse ) ) },
}
]);
}
function createTouchBar( mainWindow ) {
// TODO: Implement touchbar
// mainWindow.setTouchBar();
}
exports.playPauseTrack = mediaPlayPauseTrack;
exports.stopTrack = mediaStopTrack;
exports.nextTrack = mediaNextTrack;
exports.previousTrack = mediaPreviousTrack;
exports.upVote = mediaUpVote;
exports.downVote = mediaDownVote;
// For Windows
exports.createThumbar = createThumbar;
// For Mac
// exports.createTouchBar = createTouchBar;