nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 278 forks source link

ipc renderer or ipc main function stop working on electron:build #311

Closed nickfan closed 5 years ago

nickfan commented 5 years ago

Describe the bug i build my app with vue-cli-plugin-electron-builder it works fine when i'm develop with electron:serve aka vue-cli-service electron:serve but when i'm try to release the app,and run the app ipc renderer or ipc main function seems stop working on electron:build other function seems work fine(shell.openExternal,shell.showItemInFolder on the client side)

at first i thought it might be the custom protocol problem,i switch back to 'app://./',it didn't work.

and i got nothing respone from log file or the devtools console, so i install devtron,and open the ipc panel: and i found message send from renderer but nothing responsed. and i could not find where to read from app(main) console, so how could i debug the problem?

image

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen. ipcmain and ipcrenderer send and receive message from each side.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

module.exports = {
  lintOnSave: true,
  pluginOptions: {
    electronBuilder: {
      customFileProtocol: "bzwb://./",
      // customFileProtocol: 'file://./',
      removeElectronJunk: false,
      builderOptions: {
        // options placed here will be merged with default configuration and passed to electron-builder
        appId: "com.example.app",
        productName: "MyExample",
        protocols: [
          {
            name: "My Example URL",
            schemes: ["bzwb"]
          }
        ],
        mac: {
          target: "default"
        },
        nsis: {
          oneClick: false,
          perMachine: true,
          allowToChangeInstallationDirectory: true
        },
        win: {
          target: [
            {
              target: "nsis",
              arch: ["x64", "ia32"]
            }
          ]
        }
      }
    }
  }
};

Additional context Add any other context about the problem here.

nklayman commented 5 years ago

Can you upload your background.js as well? I've used IPC without issue before, so I want to see how you implement it.

nickfan commented 5 years ago

ok,i found the reason,it's my design problem, i build my event listeners regist depends on the class name,in the DEV mode,it's fine for that,but after asar or webpack uglify plugin minify the production file,it will change the class name so my listeners regist flow stop working.

and i found that the only way to avoid that is

class SomeClass {
  static getClassName(){ return 'SomeClass'; }
  getClassName(){ return this.constructor.getClassName(); }
  constructor() {}
}

reference:

https://stackoverflow.com/questions/29310530/get-the-class-name-of-es6-class-instance