Skip to content

Instantly share code, notes, and snippets.

@xmedeko
Last active March 12, 2021 14:09
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 xmedeko/b2f8bca876f73f7c1269bd9b7c05d9ad to your computer and use it in GitHub Desktop.
Save xmedeko/b2f8bca876f73f7c1269bd9b7c05d9ad to your computer and use it in GitHub Desktop.
Electron openPath error dialog minimized
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>openPath error dialog minimized</title>
</head>
<body>
<h1>openPath error dialog minimized</h1>
<br/>
<input type="text" id="pathInput" value="%24-error-on-purpose" />
<button id="btn">Open path</button>
</body>
</html>
const {app, BrowserWindow, ipcMain, dialog, shell} = require('electron')
const path = require('path')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
mainWindow.webContents.openDevTools()
}
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()
})
ipcMain.on('app-open-path', async (_event, filePath) => {
const error = shell.openPath(filePath)
//if (error)
// dialog.showErrorBox('Test App', error)
})
const { ipcRenderer, shell } = require("electron");
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const btn = document.getElementById('btn')
btn.addEventListener('click', () => {
const filePath = document.getElementById('pathInput').value
shell.openPath(filePath)
//ipcRenderer.send('app-open-path', filePath)
})
})
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// \`nodeIntegration\` is turned off. Use \`preload.js\` to
// selectively enable features needed in the rendering
// process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment