refactor: convert more files to typescript (#16820)
This commit is contained in:
parent
cfbdc40814
commit
01c442de64
16 changed files with 169 additions and 90 deletions
|
@ -10,6 +10,11 @@ common.defineProperties(exports)
|
|||
for (const module of moduleList) {
|
||||
Object.defineProperty(exports, module.name, {
|
||||
enumerable: !module.private,
|
||||
get: common.memoizedGetter(() => require(`@electron/internal/browser/api/${module.file}.js`))
|
||||
get: common.memoizedGetter(() => {
|
||||
const value = require(`@electron/internal/browser/api/${module.file}.js`)
|
||||
// Handle Typescript modules with an "export default X" statement
|
||||
if (value.__esModule) return value.default
|
||||
return value
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
'use strict'
|
||||
|
||||
const { app, session } = require('electron')
|
||||
import { app, session } from 'electron'
|
||||
|
||||
// Global protocol APIs.
|
||||
module.exports = process.atomBinding('protocol')
|
||||
const protocol = process.atomBinding('protocol')
|
||||
|
||||
// Fallback protocol APIs of default session.
|
||||
Object.setPrototypeOf(module.exports, new Proxy({}, {
|
||||
Object.setPrototypeOf(protocol, new Proxy({}, {
|
||||
get (target, property) {
|
||||
if (!app.isReady()) return
|
||||
|
||||
const protocol = session.defaultSession.protocol
|
||||
const protocol = session.defaultSession!.protocol
|
||||
if (!Object.getPrototypeOf(protocol).hasOwnProperty(property)) return
|
||||
|
||||
// Returning a native function directly would throw error.
|
||||
return (...args) => protocol[property](...args)
|
||||
return (...args: any[]) => (protocol[property as keyof Electron.Protocol] as Function)(...args)
|
||||
},
|
||||
|
||||
ownKeys () {
|
||||
if (!app.isReady()) return []
|
||||
|
||||
return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.protocol))
|
||||
return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession!.protocol))
|
||||
},
|
||||
|
||||
getOwnPropertyDescriptor (target) {
|
||||
return { configurable: true, enumerable: true }
|
||||
}
|
||||
}))
|
||||
|
||||
export default protocol
|
Loading…
Add table
Add a link
Reference in a new issue