refactor: add invoke helpers in window-setup (#18233)
This commit is contained in:
parent
2b4ad2cb09
commit
af0ad4454e
1 changed files with 24 additions and 10 deletions
|
@ -81,9 +81,7 @@ class LocationProxy {
|
||||||
// It's right, that's bad, but we're doing it anway.
|
// It's right, that's bad, but we're doing it anway.
|
||||||
(guestURL as any)[propertyKey] = newVal
|
(guestURL as any)[propertyKey] = newVal
|
||||||
|
|
||||||
return this.ipcRenderer.sendSync(
|
return this._invokeWebContentsMethodSync('loadURL', guestURL.toString())
|
||||||
'ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC',
|
|
||||||
this.guestId, 'loadURL', guestURL.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -102,7 +100,7 @@ class LocationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getGuestURL (): URL | null {
|
private getGuestURL (): URL | null {
|
||||||
const urlString = ipcRendererInternal.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, 'getURL')
|
const urlString = this._invokeWebContentsMethodSync('getURL') as string
|
||||||
try {
|
try {
|
||||||
return new URL(urlString)
|
return new URL(urlString)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -111,6 +109,10 @@ class LocationProxy {
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _invokeWebContentsMethodSync (method: string, ...args: any[]) {
|
||||||
|
return ipcRendererInternal.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, method, ...args)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BrowserWindowProxy {
|
class BrowserWindowProxy {
|
||||||
|
@ -127,7 +129,7 @@ class BrowserWindowProxy {
|
||||||
}
|
}
|
||||||
public set location (url: string | any) {
|
public set location (url: string | any) {
|
||||||
url = resolveURL(url)
|
url = resolveURL(url)
|
||||||
ipcRendererInternal.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, 'loadURL', url)
|
this._invokeWebContentsMethodSync('loadURL', url)
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (guestId: number) {
|
constructor (guestId: number) {
|
||||||
|
@ -145,23 +147,35 @@ class BrowserWindowProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus () {
|
public focus () {
|
||||||
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'focus')
|
this._invokeWindowMethod('focus')
|
||||||
}
|
}
|
||||||
|
|
||||||
public blur () {
|
public blur () {
|
||||||
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'blur')
|
this._invokeWindowMethod('blur')
|
||||||
}
|
}
|
||||||
|
|
||||||
public print () {
|
public print () {
|
||||||
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'print')
|
this._invokeWebContentsMethod('print')
|
||||||
}
|
}
|
||||||
|
|
||||||
public postMessage (message: any, targetOrigin: any) {
|
public postMessage (message: any, targetOrigin: any) {
|
||||||
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, toString(targetOrigin), window.location.origin)
|
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, toString(targetOrigin), window.location.origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
public eval (...args: any[]) {
|
public eval (code: string) {
|
||||||
ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript', ...args)
|
this._invokeWebContentsMethod('executeJavaScript', code)
|
||||||
|
}
|
||||||
|
|
||||||
|
private _invokeWindowMethod (method: string, ...args: any[]) {
|
||||||
|
return ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, method, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
private _invokeWebContentsMethod (method: string, ...args: any[]) {
|
||||||
|
return ipcRendererInternal.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, method, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
private _invokeWebContentsMethodSync (method: string, ...args: any[]) {
|
||||||
|
return ipcRendererInternal.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, method, ...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue