协议的注册和处理
const {app, protocol} = require('electron')
const path = require('path')
app.on('ready', () => {
protocol.registerFileProtocol('atom', (request, callback) => {
const url = request.url.substr(7)
callback({path: path.normalize(`${__dirname}/${url}`)})
}, (error) => {
if (error) console.error('无法注册协议')
})
})方法
protocol.registerStandardSchemes(schemes[, options])
protocol.registerStandardSchemes(schemes[, options])protocol.registerServiceWorkerSchemes(schemes)
protocol.registerServiceWorkerSchemes(schemes)protocol.registerFileProtocol(scheme, handler[, completion])
protocol.registerFileProtocol(scheme, handler[, completion])protocol.registerBufferProtocol(scheme, handler[, completion])
protocol.registerBufferProtocol(scheme, handler[, completion])protocol.registerStringProtocol(scheme, handler[, completion])
protocol.registerStringProtocol(scheme, handler[, completion])protocol.registerHttpProtocol(scheme, handler[, completion])
protocol.registerHttpProtocol(scheme, handler[, completion])protocol.unregisterProtocol(scheme[, completion])
protocol.unregisterProtocol(scheme[, completion])protocol.isProtocolHandled(scheme, callback)
protocol.isProtocolHandled(scheme, callback)protocol.interceptFileProtocol(scheme, handler[, completion])
protocol.interceptFileProtocol(scheme, handler[, completion])protocol.interceptStringProtocol(scheme, handler[, completion])
protocol.interceptStringProtocol(scheme, handler[, completion])protocol.interceptBufferProtocol(scheme, handler[, completion])
protocol.interceptBufferProtocol(scheme, handler[, completion])protocol.interceptHttpProtocol(scheme, handler[, completion])
protocol.interceptHttpProtocol(scheme, handler[, completion])protocol.uninterceptProtocol(scheme[, completion])
protocol.uninterceptProtocol(scheme[, completion])Last updated