Skip to content

Instantly share code, notes, and snippets.

@xmedeko
Last active March 12, 2021 14:09
Show Gist options
  • Select an option

  • Save xmedeko/b2f8bca876f73f7c1269bd9b7c05d9ad to your computer and use it in GitHub Desktop.

Select an option

Save xmedeko/b2f8bca876f73f7c1269bd9b7c05d9ad to your computer and use it in GitHub Desktop.

Revisions

  1. xmedeko revised this gist Mar 12, 2021. No changes.
  2. xmedeko revised this gist Mar 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <title>openPath error dialog minimized</title>
    </head>
    <body>
    <h1>openPath bug</h1>
    <h1>openPath error dialog minimized</h1>
    <br/>
    <input type="text" id="pathInput" value="%24-error-on-purpose" />
    <button id="btn">Open path</button>
  3. xmedeko revised this gist Mar 12, 2021. No changes.
  4. xmedeko revised this gist Mar 12, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -5,12 +5,12 @@
    <!-- 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 bug</title>
    <title>openPath error dialog minimized</title>
    </head>
    <body>
    <h1>openPath bug</h1>
    <br/>
    <input type="text" id="pathInput" />
    <input type="text" id="pathInput" value="%24-error-on-purpose" />
    <button id="btn">Open path</button>
    </body>
    </html>
  5. xmedeko revised this gist Mar 12, 2021. 2 changed files with 6 additions and 7 deletions.
    9 changes: 4 additions & 5 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,8 @@ app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') app.quit()
    })

    ipcMain.on('app-open-path', (_event, filePath) => {
    shell.openPath(filePath).then(error => {
    if (error)
    dialog.showErrorBox('Test App', error)
    })
    ipcMain.on('app-open-path', async (_event, filePath) => {
    const error = shell.openPath(filePath)
    //if (error)
    // dialog.showErrorBox('Test App', error)
    })
    4 changes: 2 additions & 2 deletions preload.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ 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)
    shell.openPath(filePath)
    //ipcRenderer.send('app-open-path', filePath)
    })
    })
  6. xmedeko created this gist Mar 12, 2021.
    16 changes: 16 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <!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 bug</title>
    </head>
    <body>
    <h1>openPath bug</h1>
    <br/>
    <input type="text" id="pathInput" />
    <button id="btn">Open path</button>
    </body>
    </html>
    30 changes: 30 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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', (_event, filePath) => {
    shell.openPath(filePath).then(error => {
    if (error)
    dialog.showErrorBox('Test App', error)
    })
    })
    12 changes: 12 additions & 0 deletions preload.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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)
    })
    })
    6 changes: 6 additions & 0 deletions renderer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    // 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.
    1 change: 1 addition & 0 deletions styles.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    /* Empty */