Created
February 4, 2025 19:19
-
-
Save dtkav/d2cd81340a8378a7793229f3e9f6ae5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patchWebviewer(): void { | |
// eslint-disable-next-line | |
const plugin = this; | |
try { | |
if (this.webviewerPatched) { | |
return; | |
} | |
const webviewer = (this.app as any).internalPlugins?.plugins?.webviewer; | |
if (!webviewer?.instance) { | |
this.warn("Webviewer plugin not found or not initialized"); | |
return; | |
} | |
const options = webviewer.instance.options; | |
const originalDesc = Object.getOwnPropertyDescriptor( | |
options, | |
"openExternalURLs", | |
); | |
if (!originalDesc) { | |
this.warn("Could not find openExternalURLs property"); | |
return; | |
} | |
Object.defineProperty(options, "openExternalURLs", { | |
get() { | |
const currentEvent = window.event as any; | |
if (currentEvent?.type === "open-url" && currentEvent?.detail?.url) { | |
const url = currentEvent.detail.url; | |
for (const pattern of plugin.interceptedUrls) { | |
if ( | |
(typeof pattern === "string" && url.startsWith(pattern)) || | |
(pattern instanceof RegExp && pattern.test(url)) | |
) { | |
this.log( | |
"Intercepted webviewer, opening in default browser", | |
currentEvent.detail.url, | |
); | |
return false; | |
} | |
} | |
} | |
return originalDesc.value; | |
}, | |
set(value) { | |
originalDesc.value = value; | |
}, | |
configurable: true, | |
}); | |
this.register(() => { | |
Object.defineProperty(options, "openExternalURLs", originalDesc); | |
}); | |
// Add default google auth URL | |
const re = this.loginManager.webviewIntercept(); | |
this.debug("Intercepting Webviewer for URL pattern", re.source); | |
this.interceptedUrls.push(re); | |
this.webviewerPatched = true; | |
this.debug("patched webviewer options"); | |
} catch (error) { | |
this.error("Failed to patch webviewer:", error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment