export function printCurrentPage() {
  return new Promise((resolve, reject) => {
    let remote = window.nodeRequire("electron").remote;
    document.querySelector("#app").style = "display: none";
    remote.getCurrentWindow().webContents.printToPDF(
      {
        marginsType: 1,
        pageSize: "A4",
        printBackground: false,
        landscape: false,
      },
      (error, data) => {
        document.querySelector("#app").style = "display: block";
        if (error) {
          reject(error);
        }

        // this.isPrint = false;

        //Synchronous
        // let filename = dialog.showSaveDialog(WIN, options);
        // // console.log(filename);
        // if (!filename) return;
        const tmpFolder = window.nodeRequire("os").tmpdir();
        const filename = tmpFolder + "/提交答案-" + Date.now() + ".pdf";

        const fs = window.nodeRequire("fs");
        // TODO: choose pdf file name
        // 按数据模型文档，此处没有file name，所以暂时只能是固定的名称
        fs.writeFile(filename, data, error => {
          if (error) {
            // this.$alert(error, "失败", {
            //   confirmButtonText: "确定",
            // });
            // throw error;
            reject(error);
          }
          console.log("Write PDF successfully." + filename);
          resolve(filename);
          // this.$alert("导出PDF成功", "成功", {
          //   confirmButtonText: "确定",
          // });
        });
      }
    );
  });
}
