Skip to content

Commit 7473677

Browse files
Sem VissscherSem Vissscher
Sem Vissscher
authored and
Sem Vissscher
committed
touchbar plugin - fixed code style
1 parent c3e2c13 commit 7473677

File tree

1 file changed

+67
-52
lines changed

1 file changed

+67
-52
lines changed

plugins/touchbar/back.js

+67-52
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,76 @@
1-
const { TouchBar } = require('electron')
1+
const {
2+
TouchBar
3+
} = require('electron');
24
const {
35
TouchBarButton,
46
TouchBarLabel,
57
TouchBarSpacer,
68
TouchBarSegmentedControl,
7-
TouchBarScrubber
8-
} = TouchBar
9+
TouchBarScrubber
10+
} = TouchBar;
911

10-
// this selects the title
11-
const titleSelector = '.title.style-scope.ytmusic-player-bar'
12+
// This selects the title
13+
const titleSelector = '.title.style-scope.ytmusic-player-bar';
1214

13-
// these keys will be used to go backwards, pause and skip songs
14-
const keys = ['k','space','j']
15+
// These keys will be used to go backwards, pause and skip songs
16+
const keys = ['k', 'space', 'j'];
1517

1618
const presskey = (window, key) => {
17-
window.webContents.sendInputEvent({
18-
type: "keydown",
19-
keyCode: key
20-
})
21-
}
22-
23-
// grab the title using the selector
24-
const getTitle = (win) => {
25-
return win.webContents.executeJavaScript(
26-
`document.querySelector('` + titleSelector + `').innerText`
27-
).catch(e => {
28-
console.log(e)
29-
})
30-
}
31-
32-
module.exports = (win) => {
33-
// songtitle label
34-
let songTitle = new TouchBarLabel({label: ''})
35-
36-
// the song control buttons (keys to press are in the same order)
37-
const buttons = new TouchBarSegmentedControl({
38-
mode: 'buttons',
39-
segments: [
40-
new TouchBarButton({label: '<'}),
41-
new TouchBarButton({label: '⏯️'}),
42-
new TouchBarButton({label: '>'})
43-
],
44-
change: (i) => presskey(win,keys[i])
45-
})
46-
47-
// this is the touchbar object, this combines everything with proper layout
48-
const touchBar = new TouchBar({
49-
items: [
50-
new TouchBarScrubber({items: [songTitle], continuous: false}),
51-
new TouchBarSpacer({size:'flexible'}),
52-
buttons
53-
]
54-
})
55-
56-
// if the page title changes, update touchbar and song title
57-
win.on("page-title-updated", async () => {
58-
songTitle.label = await getTitle(win)
59-
win.setTouchBar(touchBar)
60-
})
61-
}
19+
window.webContents.sendInputEvent({
20+
type: 'keydown',
21+
keyCode: key
22+
});
23+
};
24+
25+
// Grab the title using the selector
26+
const getTitle = win => {
27+
return win.webContents.executeJavaScript(
28+
'document.querySelector(\'' + titleSelector + '\').innerText'
29+
).catch(error => {
30+
console.log(error);
31+
});
32+
};
33+
34+
module.exports = win => {
35+
// Songtitle label
36+
const songTitle = new TouchBarLabel({
37+
label: ''
38+
});
39+
40+
// The song control buttons (keys to press are in the same order)
41+
const buttons = new TouchBarSegmentedControl({
42+
mode: 'buttons',
43+
segments: [
44+
new TouchBarButton({
45+
label: '<'
46+
}),
47+
new TouchBarButton({
48+
label: '⏯️'
49+
}),
50+
new TouchBarButton({
51+
label: '>'
52+
})
53+
],
54+
change: i => presskey(win, keys[i])
55+
});
56+
57+
// This is the touchbar object, this combines everything with proper layout
58+
const touchBar = new TouchBar({
59+
items: [
60+
new TouchBarScrubber({
61+
items: [songTitle],
62+
continuous: false
63+
}),
64+
new TouchBarSpacer({
65+
size: 'flexible'
66+
}),
67+
buttons
68+
]
69+
});
70+
71+
// If the page title changes, update touchbar and song title
72+
win.on('page-title-updated', async () => {
73+
songTitle.label = await getTitle(win);
74+
win.setTouchBar(touchBar);
75+
});
76+
};

0 commit comments

Comments
 (0)