Skip to content

Instantly share code, notes, and snippets.

@gerhardberger
Last active November 5, 2016 12:27
Show Gist options
  • Save gerhardberger/5c7a2966b0f354c50281d4270ddd7d62 to your computer and use it in GitHub Desktop.
Save gerhardberger/5c7a2966b0f354c50281d4270ddd7d62 to your computer and use it in GitHub Desktop.
protocol what
const { app, session, protocol, BrowserWindow } = require('electron')
app.on('ready', () => {
protocol.registerStringProtocol ('img', (request, callback) => {
let imgurl = request.url.replace(/img:\/\//i, '')
callback({
mimeType: 'text/html',
charset: 'utf-8',
data: `
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
background-image: url('file://${imgurl}');
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
}
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body></body>
</html>
`
})
}, (error) => {
if (error) console.error('Failed to register img protocol')
})
let win = new BrowserWindow({
width: 800, height: 600,
webPreferences: {
webSecurity: false
}
})
win.loadURL('img:///Users/gerhard/Desktop/170270.jpeg')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment