Почему электрон не создал файл? - PullRequest
0 голосов
/ 20 апреля 2020

Я создаю приложение на электроне и сейчас пытаюсь создать простой файл. Вот JS:

const app = require("electron").remote;
var dialog = app.dialog;
var fs = require("fs");

document.getElementById('save_project').onclick=() => {

    dialog.showSaveDialog((filename) => {
      if(filename === undefined){
        console.log("You didnt save the file");
        return;
      };  

      var content = "hello there";

      fs.writeFile(filename, content, (err) => {
        if(err) console.log(err);
        alert("The file has been successfully saved.")
      })

    });
};

Это окно откроется как положено: enter image description here

Затем я написал, например: "hello.txt" в введите имя и нажмите «Сохранить».

На консоли нет ни журнала, ни файла, записанного в каталоге

Редактировать: с этим js происходит то же самое ():

  const fs = require("fs");
  const {dialog} = require("electron").remote;

document.getElementById("save_project").addEventListener("click", () => {

  dialog.showSaveDialog((filename) => {
    if(filename === undefined){
      console.log("nop");
      return;
    }

    fs.writeFile(filename, content, (err) => {
      if(err){
        console.log(err);
        return;
      }

      alert("file created");
    });
  });
}, false);

Отредактировано: вот createWindow ()

function createWindow () {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 1920,
    height: 1080,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      nodeIntegration: true
    },
  });

  const childWindow = new  BrowserWindow ({ width: 1600, height: 800, parent: mainWindow, modal: true, show : false});



  // and load the index.html of the app.
  mainWindow.loadFile("index.html");
  childWindow.loadFile("welcome.html");

  childWindow.once("ready-to-show", () =>  {
  childWindow.show();
  });

  // Open the DevTools.
  mainWindow.webContents.openDevTools();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...