新增虾米音源
This commit is contained in:
@@ -2,4 +2,4 @@ global.lx_event = {}
|
||||
|
||||
const Tray = require('./tray')
|
||||
|
||||
if (!global.lx_event.setting) global.lx_event.tray = new Tray()
|
||||
if (!global.lx_event.tray) global.lx_event.tray = new Tray()
|
||||
|
||||
+16
-1
@@ -21,11 +21,13 @@ app.on('second-instance', (event, argv, cwd) => {
|
||||
})
|
||||
|
||||
const isDev = global.isDev = process.env.NODE_ENV !== 'production'
|
||||
const { navigationUrlWhiteList } = require('../common/config')
|
||||
|
||||
app.on('web-contents-created', (event, contents) => {
|
||||
contents.on('will-navigate', (event, navigationUrl) => {
|
||||
if (isDev) return console.log('navigation to url:', navigationUrl)
|
||||
event.preventDefault()
|
||||
if (!navigationUrlWhiteList.some(url => url.test(navigationUrl))) return event.preventDefault()
|
||||
console.log('navigation to url:', navigationUrl)
|
||||
})
|
||||
contents.on('new-window', async(event, navigationUrl) => {
|
||||
event.preventDefault()
|
||||
@@ -33,6 +35,19 @@ app.on('web-contents-created', (event, contents) => {
|
||||
console.log(navigationUrl)
|
||||
await shell.openExternal(navigationUrl)
|
||||
})
|
||||
contents.on('will-attach-webview', (event, webPreferences, params) => {
|
||||
// Strip away preload scripts if unused or verify their location is legitimate
|
||||
delete webPreferences.preload
|
||||
delete webPreferences.preloadURL
|
||||
|
||||
// Disable Node.js integration
|
||||
webPreferences.nodeIntegration = false
|
||||
|
||||
// Verify URL being loaded
|
||||
if (!navigationUrlWhiteList.some(url => url.test(params.src))) {
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// https://github.com/electron/electron/issues/22691
|
||||
|
||||
@@ -12,3 +12,6 @@ require('./getCacheSize')
|
||||
require('./setIgnoreMouseEvent')
|
||||
require('./getEnvParams')
|
||||
require('./tray')
|
||||
require('./updateSetting')
|
||||
|
||||
require('./xm_verify')
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
const { mainOn } = require('../../common/ipc')
|
||||
|
||||
|
||||
mainOn('updateAppSetting', (event, setting) => {
|
||||
if (!setting) return
|
||||
global.appSetting = setting
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
const { BrowserView } = require('electron')
|
||||
const { mainHandle } = require('../../common/ipc')
|
||||
const { getWindowSizeInfo } = require('../utils')
|
||||
|
||||
let view
|
||||
|
||||
const closeView = async() => {
|
||||
if (!view) return
|
||||
// await view.webContents.session.clearCache()
|
||||
if (global.mainWindow) global.mainWindow.removeBrowserView(view)
|
||||
await view.webContents.session.clearStorageData()
|
||||
view.destroy()
|
||||
view = null
|
||||
}
|
||||
|
||||
mainHandle('xm_verify_open', (event, url) => new Promise((resolve, reject) => {
|
||||
if (!global.mainWindow) return reject(new Error('mainwindow is undefined'))
|
||||
if (view) view.destroy()
|
||||
|
||||
view = new BrowserView()
|
||||
view.webContents.on('did-finish-load', () => {
|
||||
if (/punish\?/.test(view.webContents.getURL())) return
|
||||
let ses = view.webContents.session
|
||||
ses.cookies.get({ name: 'x5sec' })
|
||||
.then(async([x5sec]) => {
|
||||
await closeView()
|
||||
if (!x5sec) return reject(new Error('get x5sec failed'))
|
||||
resolve(x5sec.value)
|
||||
}).catch(async err => {
|
||||
await closeView()
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
global.mainWindow.setBrowserView(view)
|
||||
const windowSizeInfo = getWindowSizeInfo(global.appSetting)
|
||||
view.setBounds({ x: (windowSizeInfo.width - 360) / 2, y: ((windowSizeInfo.height - 320 + 52) / 2), width: 360, height: 320 })
|
||||
view.webContents.loadURL(url)
|
||||
}))
|
||||
|
||||
mainHandle('xm_verify_close', async() => {
|
||||
await closeView()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user