Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Last active October 9, 2018 09:57
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 davidsharp/ab95fae39a6a53b5a0f877891cc78ff4 to your computer and use it in GitHub Desktop.
Save davidsharp/ab95fae39a6a53b5a0f877891cc78ff4 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist – trying to debug code given at https://discuss.atom.io/t/how-do-i-close-a-frameless-child-window/59159
<!DOCTYPE html>
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
-webkit-user-select: none;
-webkit-app-region: drag;
background-image: linear-gradient(180deg, #171717 25%, #0f0f0f 25%, #0f0f0f 50%, #171717 50%, #171717 75%, #0f0f0f 75%, #0f0f0f 100%);
background-size: 80.00px 80.00px;
}
.topnav {
overflow: hidden;
background-color: black;
height:20px;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 5px 16px;
text-decoration: none;
font-size: 10px;
}
.topnav a.active {
background-color: black;
color: white;
}
#search{
width: 150px;
height: 20px;
}
</style>
</head>
<body>
<div class="topnav">
<a class="active" href="#home">Screener</a>
<img src="img/screenerExit.png" width="20" height="20" style="float: right;" id="screenerExit">
</div>
<script type="text/javascript" src="renderer.js"></script>
</body>
</html>
const { app, BrowserWindow } = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow () {
// Create the browser window.
win = new BrowserWindow({frame: false})
win.maximize()
// and load the index.html of the app.
win.loadFile('index.html')
// Open the DevTools.
//win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
'use strict'
var {ipcRenderer, remote, screen, webContents} = require('electron');
screenerExit.addEventListener( "click", e => {
var window = remote.getCurrentWindow();
window.close();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment