首页 > 解决方案 > 在电子上以角度运行打印关闭主进程

问题描述

我正在尝试<div>在角度电子应用程序中打印,当我单击打印时(有时当我关闭新窗口时)它也会关闭主进程。我无法登录,以检查导致此问题的原因。

main.ts

win = new BrowserWindow({
    x: 0,
    y: 0,
    width: size.width,
    height: size.height,
    webPreferences: {
        nativeWindowOpen: true, // set as true
        nodeIntegration: true,
        allowRunningInsecureContent: (serve) ? true : false,
        enableRemoteModule: true
    },
});
...
app.on('window-all-closed', (e) => {
    e.preventDefault(); // added this line
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

details.component.ts

printFees() {
    var prtContent = document.getElementById('print-section');
    var WinPrint = window.open('', '_blank', 'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.open();
    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.setTimeout(function () {
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
    }, 1000);
}

标签: javascriptangularelectron

解决方案


推荐阅读