Last active
June 5, 2018 19:03
-
-
Save nvbn/0dd46fc91a4a0db34cd37d454d4cb7ed to your computer and use it in GitHub Desktop.
This file contains 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 } = 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