Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const { app, BrowserWindow, TouchBar } = require('electron');
const { TouchBarLabel, TouchBarButton } = TouchBar;
const count = 8;
const interval = 500;
const colors = [
'#ff0000',
'#00ff00',
'#0000ff',
'#ffff00',
'#ff00ff',
'#00ffff',
'#ffffff',
];
const lights = [];
for (let i = 0; i < count; i++) {
lights.push(
new TouchBarButton({
backgroundColor: colors[i * 3 % colors.length],
})
);
}
const touchBar = new TouchBar([
new TouchBarLabel({label: " "}),
...lights,
]);
app.once('ready', () => {
window = new BrowserWindow({
frame: false,
titleBarStyle: 'hiddenInset',
width: 300,
height: 100,
});
window.loadURL('javascript:document.write("<br><h1>Christmas lights!!!</h1>")');
window.setTouchBar(touchBar);
});
let tick = 0;
setInterval(() => {
for (let i = 0; i < count; i++) {
if (i % 3 === tick % 3) {
let index = colors.indexOf(lights[i].backgroundColor);
index += 1;
if (index >= colors.length) {
index = 0;
}
lights[i].backgroundColor = colors[index];
}
}
tick++;
}, interval);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.