首先 按需要下載32位或者64位的 pepflashplayer.dll
將pepflashplayer.dll放到項目中
然後在main.js中註冊
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
let pluginName;
switch (process.platform) {
case 'win32':
pluginName = 'pepflashplayer64_32_0_0_270.dll'
break
case 'darwin':
pluginName = 'PepperFlashPlayer.plugin'
break
case 'linux':
pluginName = 'libpepflashplayer.so'
break
}
let plugins = path.join( __dirname, pluginName);
if (__dirname.includes(".asar")) {
plugins = path.join(process.resourcesPath + '/' + pluginName)
}
app.commandLine.appendSwitch('ppapi-flash-path', plugins)
function createWindow() {
// let img = nativeImage.createFromPath( '512.jpg')
// Create the browser window.
mainWindow = new BrowserWindow({
// fullscreen: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
// webSecurity : false,
// allowRunningInsecureContent: false,
// nativeWindowOpen: true ,
plugins: true
},
titleBarStyle: "hiddenInset",
// icon: img
})
mainWindow.maximize();
// and load the index.html of the app.
mainWindow.loadFile('index.html')
//mainWindow.loadURL('http://www.baidu.com')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
// const request = net.request('http://127.0.0.1:8081/')
// request.on('response', function(response){
// response.on('data', (chunk) => {
// console.log(`BODY: ${chunk}`)
// })
// })
// request.end()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
下面的判斷必須有 否則打包後等着哭吧
if (__dirname.includes(".asar")) {
plugins = path.join(process.resourcesPath + '/' + pluginName)
}
這個路徑指向 打包後的resouces文件下的pepflashplayer.dll
注意需要打包配置中配置 "extraResources": ["pepflashplayer64_32_0_0_270.dll"] 纔會在打包後的resources文件夾中出現 此文件
如果忘記配置 手動複製進去也可以