electron 相关

2020-12-28  本文已影响0人  别过经年

1. 用vscode调试electron主线程

拷贝项目electron-react-boilerplate@v2.0.1,其实做了配置,但是运行Electron: All并没有走进main.dev.ts中的断点,参考修改launch.json做如下修改:

package.json script新增:

    "start-main-debug": "yarn start:main --inspect=5858 --remote-debugging-port=9223"

launch.json

launch.json

vscode 需要安装Debugger for Chrome,并且需要用如下配置或者启动Chrome:

Attach
With "request": "attach", you must launch Chrome with remote debugging enabled in order for the extension to attach to it. Here's how to do that:

Windows
Right click the Chrome shortcut, and select properties
In the "target" field, append --remote-debugging-port=9222
Or in a command prompt, execute <path to chrome>/chrome.exe --remote-debugging-port=9222

macOS
In a terminal, execute /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

2. electron 制作右下角提示框

通常我们会

         const myNotification = new Notification('开始', {
             icon: 'img'
         });

但win10企业版 LTSC 1809中,无通知弹出,所以用BrowserWindow去模拟,但是有两个问题

     const { width, height } = screen.getPrimaryDisplay().workAreaSize;
     const msgBoxHeight = 100
        let browserWindow: BrowserWindow|null = new BrowserWindow({   
            width: 400,
            height: msgBoxHeight,
            x:width - 400,
            y:height - msgBoxHeight, 
            frame: false,
            alwaysOnTop:true,
            autoHideMenuBar: true,
            show: false,
            minimizable: false,
            maximizable: false,
            closable: true,
            title: "Dialog",
            webPreferences: {
                nodeIntegration: true,
            } })
            browserWindow.once("ready-to-show", () => {
              browserWindow && browserWindow.show();
            });
上一篇 下一篇

猜你喜欢

热点阅读