-
-
Notifications
You must be signed in to change notification settings - Fork 727
/
Copy pathtouchbar.js
62 lines (60 loc) · 2.1 KB
/
touchbar.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
const TouchBar = require('electron').TouchBar
const nativeImage = require('electron').nativeImage
const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar
function buildTouchBar () {
if (process.platform !== 'darwin') {
return null
}
function getTouchBarIcon (name) {
// the icons created by nativeImage are too big by default, shrink them to the correct size for the touchbar
var image = nativeImage.createFromNamedImage(name, [-1, 0, 1])
var size = image.getSize()
return image.resize({
width: Math.round(size.width * 0.65),
height: Math.round(size.height * 0.65)
})
}
return new TouchBar({
items: [
new TouchBarButton({
accessibilityLabel: l('goBack'),
icon: getTouchBarIcon('NSImageNameTouchBarGoBackTemplate'),
click: function () {
sendIPCToWindow(windows.getCurrent(), 'goBack')
}
}),
new TouchBarButton({
accessibilityLabel: l('goForward'),
icon: getTouchBarIcon('NSImageNameTouchBarGoForwardTemplate'),
click: function () {
sendIPCToWindow(windows.getCurrent(), 'goForward')
}
}),
new TouchBarSpacer({ size: 'flexible' }),
new TouchBarButton({
icon: getTouchBarIcon('NSImageNameTouchBarSearchTemplate'),
iconPosition: 'left',
// TODO this is really hacky, find a better way to set the size
label: ' ' + l('searchbarPlaceholder') + ' ',
click: function () {
sendIPCToWindow(windows.getCurrent(), 'openEditor')
}
}),
new TouchBarSpacer({ size: 'flexible' }),
new TouchBarButton({
icon: getTouchBarIcon('NSImageNameTouchBarAdd'),
accessibilityLabel: l('newTabAction'),
click: function () {
sendIPCToWindow(windows.getCurrent(), 'addTab')
}
}),
new TouchBarButton({
accessibilityLabel: l('viewTasks'),
icon: getTouchBarIcon('NSImageNameTouchBarListViewTemplate'),
click: function () {
sendIPCToWindow(windows.getCurrent(), 'toggleTaskOverlay')
}
})
]
})
}