Last active
March 22, 2020 18:34
-
-
Save wisniewski94/0d0937d5189433021d2b27cb8db91d53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
app, BrowserWindow, TouchBar, nativeImage, | |
} = require('electron'); | |
const { TouchBarButton } = TouchBar; | |
app.on('ready', () => { | |
const win = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
nodeIntegration: true, | |
}, | |
}); | |
let counter = 0; | |
const image = nativeImage.createFromPath('./m.png').resize({ height: 30 }); | |
const update = () => { | |
counter += 1; | |
button.label = `Count: ${counter}`; | |
}; | |
const button = new TouchBarButton({ | |
label: `Count: ${counter}`, | |
accessibilityLabel: 'Counter', | |
backgroundColor: '#6ab04c', | |
click: () => { | |
update(); | |
}, | |
}); | |
const button2 = new TouchBarButton({ | |
icon: image, | |
iconPosition: 'left', | |
label: 'How to use TouchBar API in ElectronJS?', | |
accessibilityLabel: 'Button looking like a label', | |
backgroundColor: '#000', | |
click: () => { | |
win.loadURL('https://medium.com/p/c58914a5518a'); | |
}, | |
}); | |
const touchBar = new TouchBar({ | |
items: [ | |
button, | |
button2, | |
], | |
}); | |
win.loadFile('index.html'); | |
win.setTouchBar(touchBar); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment