-
-
Save codebytere/0f0e776b138452d6815ef4efc16aa0d1 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<button onclick="window.print();" style="display: block; background-color: darkgreen; color: white; padding: 16px 32px; cursor: pointer;">WINDOW PRINT</button> | |
<button onclick="printMe()" style="display: block; background-color: purple; color: white; padding: 16px 32px; cursor: pointer;">WEBCONTENTS PRINT</button> | |
<h1>Hello World!</h1> | |
<!-- All of the Node.js APIs are available in this renderer process. --> | |
We are using Node.js <script>document.write(process.versions.node)</script>, | |
Chromium <script>document.write(process.versions.chrome)</script>, | |
and Electron <script>document.write(process.versions.electron)</script>. | |
<script> | |
// You can also require other files to run in this process | |
const { ipcRenderer } = require('electron') | |
function printMe() { | |
ipcRenderer.send('wc-print') | |
} | |
</script> | |
</body> | |
</html> |
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, ipcMain} = require('electron') | |
let mainWindow | |
function createWindow () { | |
mainWindow = new BrowserWindow({ | |
webPreferences: { | |
nodeIntegration: true, | |
contextIsolation: false, | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
mainWindow.on('closed', () => { | |
mainWindow = null | |
}) | |
} | |
ipcMain.on('wc-print', async () => { | |
const win = new BrowserWindow({show: false}) | |
await win.loadURL('http://example.com/') | |
win.webContents.print({}, (success, reason) => { | |
console.log(`printing ${success ? 'did' : 'did not'} succeed: ${reason}`) | |
}) | |
win.on('closed', () => { win = null }) | |
}) | |
app.on('ready', createWindow) | |
app.on('window-all-closed', () => { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
app.on('activate', () => { | |
if (mainWindow === null) createWindow() | |
}) |
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
{ | |
"name": "painful-dad-fly-nck7l", | |
"productName": "painful-dad-fly-nck7l", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "codebytere", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "999999999999.9.9" | |
} | |
} |
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
// Empty |
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
// Empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment