簡體   English   中英

雙擊打開文件 electron

[英]Opening files with electron from double click

是的,有點重復,但該代碼不再適用於我的情況。

所以我正在構建一個照片查看器,當圖像文件設置為默認打開時,我希望能夠查看文件,但我也制作了自定義 window 控件,它當然有圖像,除此之外, 使用 electron 打開文件中列出的腳本通過將這些圖像讀取為從main.js發送的數據來搞亂這些圖像,並且搞砸了

應用加載時的外觀圖片在此處輸入圖像描述

如果有人能找到解決此問題的解決方法,將不勝感激,謝謝。

我想通了,我花了很長時間才理解文檔以及我做錯了什么!

主要問題是安置

main.js

這個腳本實際上會 go 在 function 中創建 window 而不是在外面,所以像:

    let mainWindow;
    function createWindow() {
    // creating the window and specifying fields here
    // mainWindow = new BrowserWindow({/*fields here*/});
    // then adding the ipc listener here
        ipcMain.on('get-file-data', function(event) {
            var data = null
            if (process.platform == 'win32' && process.argv.length >= 2) {
              var openFilePath = process.argv[1];
              data = openFilePath;
            }
            event.returnValue = data;
        });
    }

    // then app.on listeners down here

renderer.js

const img = document.getElementById("image id");
var data = ipcRenderer.sendSync('get-file-data')
if (data ===  null) {
    console.log("There is no file")
} else {
    console.log(data);
    img.src = data;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM