Skip to content

Instantly share code, notes, and snippets.

@JeroenSormani
Created August 6, 2017 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeroenSormani/be238d972ccb2ff0b1b967a43ad511ba to your computer and use it in GitHub Desktop.
Save JeroenSormani/be238d972ccb2ff0b1b967a43ad511ba to your computer and use it in GitHub Desktop.
Related to https://github.com/electron/electron/issues/8847 - showing a imprint / shadow of the previous state prior to show/hide
<!DOCTYPE html>
<html>
<head>
<style>
body {
background: rgba(255, 0, 0, 0.5);
font-size: 30px;
}
</style>
</head>
<body>
<div id="content" class="content">
Hello World
</div>
</body>
<script>
const ipc = require('electron').ipcRenderer
ipc.on('set-content', function() {
document.body.insertBefore( document.createElement('br'), document.body.firstChild )
document.getElementById('content').outerHTML = '<div id="content" class="content">test</div>'
})
ipc.on('set-content2', function() {
document.body.insertBefore( document.createElement('br'), document.body.firstChild )
document.getElementById('content').outerHTML = '<div id="content" class="content">Hello World</div>'
})
</script>
</html>
const electron = require('electron')
const {app, BrowserWindow, ipcMain, globalShortcut} = electron
var windo, window2
var counter = 000
app.on('ready', function() {
createWindow()
globalShortcut.register('Cmd+1', () => {
window.show()
window2.show()
})
globalShortcut.register('Cmd+2', () => {
window.hide()
window2.hide()
})
globalShortcut.register('Cmd+3', () => {
window.webContents.send('set-content')
window2.webContents.send('set-content')
})
globalShortcut.register('Cmd+4', () => {
window.webContents.send('set-content2')
window2.webContents.send('set-content2')
})
})
function createWindow() {
window = new BrowserWindow({
transparent: true,
x: 1100,
y: 200,
height: 600,
width: 500,
alwaysOnTop: true,
minimizable: false,
maximizable: false,
frame: true,
// show: false,
hasShadow: false
})
window.loadURL(`file://${__dirname}/index.html`)
window2 = new BrowserWindow({
transparent: true,
x: 600,
y: 200,
height: 600,
width: 500,
alwaysOnTop: true,
minimizable: false,
maximizable: false,
frame: true,
})
window2.loadURL(`file://${__dirname}/index.html`)
}
ipcMain.on('show-window', function() {
window.show()
window2.show()
})
ipcMain.on('hide-window', function() {
window.hide()
window2.hide()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment