electron/docs/fiddles/system/clipboard/copy/main.js
2023-02-01 12:59:16 +01:00

38 lines
811 B
JavaScript

const { app, BrowserWindow, ipcMain, clipboard } = require('electron')
const path = require('path')
let mainWindow = null
function createWindow () {
const windowOptions = {
width: 600,
height: 400,
title: 'Clipboard copy',
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
}
mainWindow = new BrowserWindow(windowOptions)
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
}
ipcMain.handle('clipboard:writeText', (event, text) => {
clipboard.writeText(text)
})
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})