Open all file types with Default OS program

问题: Is there a way to link to open all file extensions with default OS program instead of internal to Electron? My file names are loaded from JSON file. (Value.url IS the fil...

问题:

Is there a way to link to open all file extensions with default OS program instead of internal to Electron?

My file names are loaded from JSON file. (Value.url IS the file name pulled in dynamically during a search)

I modified my code below to link the click event to the openBtnId, but now i'm receivING "electron is not defined". I have const shell = require('electron').shell; in my mainJS.

function renderHTML(data) {
    var htmlString = "";
    $('#aceCategory').empty();
    for (i = 0; i < data.length; i++) {
        htmlString += "<p class='categoryName'>" + data[i].category + "</p>" + "<tr>" + "<td class='feedDesc'>" + "<b>" + data[i].name +
            "</b>" + "<br>" + data[i].desc + "</br>" + "<br>" + "<input type='button' id='openBtn' style='border-radius: 25px; outline: none' value='Open Link'  >" + "</td>" +
            "</tr>";

    }
    aceFeedTable.insertAdjacentHTML('beforeend', htmlString)
    $(document).on("click", "#openBtn", function() {
        electron.shell.openItem(data[i].url);
    });
}

回答1:

You can use shell.openItem(fullPath) for that.

const {shell} = require("electron");
shell.openItem("/path/to/my/file");

This has to be done either in the main process or in a BrowserWindow that has nodeIntegration set to true.

  • 发表于 2019-12-25 16:16
  • 阅读 ( 118 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除