Skip to content

Instantly share code, notes, and snippets.

@RikTheunis
Created October 6, 2019 08:47
Show Gist options
  • Save RikTheunis/263e01f09c1cb44da8d8bf28f2f726ce to your computer and use it in GitHub Desktop.
Save RikTheunis/263e01f09c1cb44da8d8bf28f2f726ce to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<div>
<h1>Supports: Win, macOS, Linux <span>|</span> Process: Both</div>
<div>
<div>
<button id="copy-to">Copy</button>
<input id="copy-to-input" aria-label="Click copy" placeholder="Click copy."></input>
</div>
<p>In this example we copy a phrase to the clipboard. After clicking 'Copy' use the text area to paste (CMD + V or CTRL + V) the phrase from the clipboard.</p>
</div>
</div>
</div>
</body>
<script>
require('./renderer.js')
</script>
</html>
const { app, BrowserWindow } = require('electron')
let mainWindow = null
function createWindow () {
const windowOptions = {
width: 600,
height: 400,
title: 'Clipboard copy',
webPreferences: {
nodeIntegration: true
}
}
mainWindow = new BrowserWindow(windowOptions)
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', () => {
createWindow()
})
const {clipboard} = require('electron')
const copyBtn = document.getElementById('copy-to')
const copyInput = document.getElementById('copy-to-input')
copyBtn.addEventListener('click', () => {
if (copyInput.value !== '') copyInput.value = ''
copyInput.placeholder = 'Copied! Paste here to see.'
clipboard.writeText('Electron Demo!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment