Skip to content

Instantly share code, notes, and snippets.

@wisniewski94
Last active March 22, 2020 18:34
Show Gist options
  • Save wisniewski94/0d0937d5189433021d2b27cb8db91d53 to your computer and use it in GitHub Desktop.
Save wisniewski94/0d0937d5189433021d2b27cb8db91d53 to your computer and use it in GitHub Desktop.
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