-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
135 lines (102 loc) · 3.33 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { app, BrowserWindow, Menu, dialog,ipcMain } = require('electron');
const path = require('path');
let mainWindow;
console.log(process.version,process.platform,process.arch)
//获得插件信息
const getFlashPlugin = () => {
if (process.platform === "win32") {
//x64和ia32
if (process.arch === "x64") {
return {
pluginPath: path.join(__dirname, 'plugins', 'win_x64','pepflashplayer64_34_0_0_267.dll'),
version: "34.0.0.267",
};
}
return {
pluginPath: path.join(__dirname, 'plugins', 'win_x86','pepflashplayer32_34_0_0_267.dll'),
version: "32.0.0.267",
};
}
//苹果系统
if (process.platform === "darwin") {
return {
pluginPath: path.join(__dirname, 'plugins', 'mac','PepperFlashPlayer.plugin'),
version: "30.0.0.127",
};
}
if (process.platform === "linux") {
if (process.arch === "ia32" || process.arch === "x32" ) {
return {
pluginPath: path.join(__dirname, 'plugins', 'linux_x86','libpepflashplayer-i386.so'),
version: "32.0.0.363",
};
}
if (process.arch === "x64") {
return {
pluginPath: path.join(__dirname, 'plugins', 'linux_x64','libpepflashplayer-x86_64.so'),
version: "32.0.0.363",
};
}
if (process.arch === "arm" || process.arch === "arm64" || process.arch === "aarch64" || process.arch === "armhf" ) {
return {
pluginPath: path.join(__dirname, 'plugins', 'linux_armhf','libpepflashplayer.so'),
version: "27.0.0.187",
};
}
}
return null;
};
// 获得系统里面flash插件的位置
const { pluginPath, version } = getFlashPlugin();
console.log(pluginPath,version)
app.commandLine.appendSwitch("ppapi-flash-path", pluginPath);
app.commandLine.appendSwitch("ppapi-flash-version", version);
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
plugins: true, //启用插件
preload: path.join(__dirname, 'preload.js'), // 可选的预加载脚本
contextIsolation: true, // 启用上下文隔离以提高安全性
enableRemoteModule: false, // 禁用远程模块以提高安全性
},
});
// 监听来自渲染进程的消息
ipcMain.on('navigate-to-url', (event, url) => {
console.log(event,url)
// 检查 URL 是否有效(这里只是简单的检查,实际中可能需要更复杂的验证)
if (url.startsWith('http://') || url.startsWith('https://')) {
createNewWindow(url);
} else {
mainWindow.webContents.send('invalid-url', '请输入一个有效的 HTTP 或 HTTPS URL。');
}
});
mainWindow.loadFile('pages/index.html');
//mainWindow.loadURL('https://www.4399.com/');
// 默认打开开发者工具
//mainWindow.webContents.openDevTools();
}
function createNewWindow(url) {
const newWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
plugins: true, //启用插件
}
});
newWindow.loadURL(url);
}
app.on('ready', () => {
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});