electron-webpack
electron-webpack copied to clipboard
electron-webpack dev not works for flash plugin
- Version:
{
"name": "electron-webpack-quick-start",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
"compile": "electron-webpack",
"dist": "yarn compile && electron-builder",
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null"
},
"dependencies": {
"source-map-support": "^0.5.16"
},
"devDependencies": {
"electron": "4.2.12",
"electron-builder": "^22.4.1",
"electron-webpack": "^2.8.2",
"webpack": "~4.42.1"
}
}
- Target: Windows
I want to build a electron app which support flash. So I use an old electron 4.2.12. And write the main code like the following.
'use strict'
const { app, BrowserWindow } = require('electron')
const path = require('path')
const fs = require('fs')
const isDevelopment = process.env.NODE_ENV !== 'production'
console.info(isDevelopment)
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow
function createMainWindow() {
console.info(`createMainWindow`)
const window = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: false,
plugins: true,
}
})
if (isDevelopment) {
window.webContents.openDevTools()
}
window.loadURL(
'https://www.ultrasounds.com/'
);
window.on('closed', () => {
mainWindow = null
})
window.webContents.on('devtools-opened', () => {
window.focus()
setImmediate(() => {
window.focus()
})
})
return window
}
// Specify flash path, supposing it is placed in the same directory with main.js.
const flash_version = '27_0_0_159';
const arch = process.arch === 'x64' ? '64' : '32';
let pluginName;
switch (process.platform) {
case 'win32':
pluginName = `pepflashplayer${arch}_${flash_version}.dll`
break
case 'darwin':
pluginName = `PepperFlashPlayer${arch}_${flash_version}.plugin`
break
case 'linux':
pluginName = `libpepflashplayer${arch}_${flash_version}.so`
break
}
const flash_path = path.join(__dirname, 'pepper_flash', pluginName);
console.info(`try to use flash_version: ${flash_version}, flash_path: ${flash_path}`);
if (!fs.existsSync(flash_path)) {
console.error(`flash_path ${flash_path} does not exists!`);
}
else {
console.info(`flash_path ${flash_path} ok!`);
}
app.commandLine.appendSwitch('ppapi-flash-path', flash_path)
// Optional: Specify flash version
app.commandLine.appendSwitch('ppapi-flash-version', flash_version)
// app.commandLine.appendSwitch('--enable-sandbox')
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow()
})
The strange thing is when I run yarn electron src/main.js or yarn compile && yarn electron dist/main/main.js. The console always showed NOT SANDBOXED (https://github.com/electron/electron/issues/1779) and the flash plugin loaded successfully.
However, when I run yarn dev, the console did not show NOT SANDBOXED, and the webpage showed Couldn't load plugin.

const path = require('path');
const fs = require('fs');
const basedir = __dirname.endsWith('app.asar')
? path.resolve(__dirname, '..', 'app.asar.unpacked')
: __dirname;
function getBundledFlashInfo() {
let pluginName;
let pluginVersion;
switch (process.platform) {
case 'win32':
pluginName = 'pepflashplayer.dll';
pluginVersion = '26.0.0.137';
break;
case 'darwin':
pluginName = 'PepperFlashPlayer.plugin';
pluginVersion = '26.0.0.131';
break;
case 'linux':
pluginName = 'libpepflashplayer.so';
pluginVersion = '32.0.0.101';
break;
}
return {
path: path.join(basedir, 'vendor', pluginName),
version: pluginVersion,
};
}
function loadFlash(app, flashPath) {
app.commandLine.appendSwitch('ppapi-flash-path', flashPath);
}
function setFlashVersion(app, version) {
app.commandLine.appendSwitch('ppapi-flash-version', version);
}
function setupPlugins(app) {
// Load Flash plugin
try {
let systemFlashPath = app.getPath('pepperFlashSystemPlugin');
fs.accessSync(systemFlashPath, fs.R_OK);
loadFlash(app, systemFlashPath);
} catch (err) {
console.log('Access system flash failed.');
let info = getBundledFlashInfo();
loadFlash(app, info.path);
setFlashVersion(app, info.version);
}
}
module.exports = {
setupPlugins,
};
// main.js
// plugin.setupPlugins(app);
#remember copy flash binary cp vendor/libpepflashplayer.so app/vendor/
builder.yaml
asarUnpack:
- 'node_modules/*.{node,dll}'
- 'vendor'