Skip to content

Instantly share code, notes, and snippets.

@wisniewski94
Created March 22, 2020 19:50
Show Gist options
  • Save wisniewski94/1d468e8c880ac622c7d079bc48ca5b84 to your computer and use it in GitHub Desktop.
Save wisniewski94/1d468e8c880ac622c7d079bc48ca5b84 to your computer and use it in GitHub Desktop.
const {
app, BrowserWindow, TouchBar,
} = require('electron');
const { TouchBarSlider } = TouchBar;
app.on('ready', () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
const slider = new TouchBarSlider({
label: 'Simple slider',
value: 10, // initial value
minValue: 0,
maxValue: 100,
change: (value) => {
console.log(value); // print value inside terminal
win.webContents.send('slider', value);
},
});
const touchBar = new TouchBar({
items: [
slider,
],
});
win.loadFile('index.html');
win.webContents.openDevTools();
win.setTouchBar(touchBar);
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<!-- https://electronjs.org/docs/tutorial/security#csp-meta-tag -->
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<input type="range" min="1" max="100" value="10" class="slider" id="myRange">
<script>
const ipc = require('electron').ipcRenderer;
const slider = document.getElementById('myRange');
ipc.on('slider', (event, message) => {
slider.value = message;
console.log(message);
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment