Skip to content

Instantly share code, notes, and snippets.

@nvbn
Last active June 5, 2018 19:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvbn/0dd46fc91a4a0db34cd37d454d4cb7ed to your computer and use it in GitHub Desktop.
Save nvbn/0dd46fc91a4a0db34cd37d454d4cb7ed to your computer and use it in GitHub Desktop.
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