Created
October 6, 2022 07:10
-
-
Save xmedeko/a75b996306c7fa1519624f81178fb9a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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"> | |
<!-- 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="error-path-on-purpose" /> | |
<button id="btn">Open path</button> | |
</body> | |
</html> |
This file contains hidden or 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, dialog, shell} = require('electron') | |
const console = require('console') | |
const path = require('path') | |
function createWindow () { | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js'), | |
nodeIntegration: true | |
} | |
}) | |
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) | |
console.log('shell.openPath return code', error) | |
//if (error) | |
// dialog.showErrorBox('Test App', error) | |
}) |
This file contains hidden or 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": "cli-space", | |
"productName": "cli-space", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "xmedeko", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "21.1.0" | |
} | |
} |
This file contains hidden or 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 { 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 contains hidden or 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
// 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. |
This file contains hidden or 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