Search code examples
flashelectron

Electron using SWF works when testing but not after build


I have a simple Electron application that I'm incorporating one HTML page that has a SWF object. I have included the Pepper Flash Player and replicated the main.js code from the tutorial. When I run the application from command prompt / git bash for testing, the SWF works fine. However, once I build the app and run it, the SWF content won't load. The content area simply displays "Couldn't load plugin.".

I've included both 32bit and 64bit versions of the Flash player plugin.

let pluginName;
switch (process.platform) {
  case 'win32':
    if (process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) {
      console.log("64bit");
      pluginName = "PEP/pepflashplayer64_29_0_0_171.dll";
    }
    else{
      console.log("32bit");
      pluginName = "PEP/pepflashplayer32_29_0_0_171.dll";
    }
    break
  case 'darwin':
    pluginName = 'PEP/PepperFlashPlayer.plugin'
    break
}

 app.commandLine.appendSwitch('ppapi-flash-path', path.join(__dirname, pluginName))

Solution

  • I figured out my issues (there were a few) through much trial and error.

    1. The main problem was, when building, I had --asar=true, therefore the app was attempting to pull the plugin from the asar archive, which it could not. To solve this I just added the plugin to the --extraResource flag on build.
    2. In addition to this, in the app I updated the switch statement to determine whether it was a build or testing (from cmd line), as follows:

        switch (process.platform) {
          case 'win32':
            if (basename === "resources") {
              pluginName = "../../pepflashplayer32_29_0_0_171.dll";
            }
            else {
              pluginName = "./plugins/pepflashplayer32_29_0_0_171.dll";
            }
            break
          case 'darwin':
            if (basename === "resources") {
              pluginName = '../../PepperFlashPlayer.plugin'
            }
            else {
              pluginName = './plugins/PepperFlashPlayer.plugin'
            }
            break
        }
      
    3. Finally, as many pointed out in various places I was searching, the 64bit plugin was being used in stead of the 32bit.

    I hope this can save others a bit of time.