-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(preload): preload sometimes fails to execute the code inside corr…
…ectly (#362) 1. remove DOMNodeInserted, because in some uncertain situations (may berelated to computer configuration), this methods will not be triggered 2. add rxjs
- Loading branch information
1 parent
de65879
commit 59dea3b
Showing
4 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
setImmediate(() => { | ||
const fixJQueryHosts = ["open.weixin.qq.com"]; | ||
const { ipcRenderer } = require("electron"); | ||
|
||
document.addEventListener("DOMNodeInserted", function DOMNodeInserted() { | ||
if (!window || !location.protocol) { | ||
return; | ||
} | ||
/** | ||
* cannot be used here DOMContentLoaded or DOMNodeInserted | ||
* because in some uncertain situations (may be related to computer configuration), these two methods will not be triggered | ||
*/ | ||
|
||
if (fixJQueryHosts.includes(location.host) && !window.$) { | ||
window.$ = window.jQuery = require("jquery"); | ||
} | ||
/** | ||
* this method will only be triggered on the main page | ||
* see: WindowManager.ts | ||
*/ | ||
ipcRenderer.once("inject-agora-electron-sdk-addon", () => { | ||
window.AgoraRtcEngine = require("agora-electron-sdk").default; | ||
|
||
if ( | ||
(location.protocol === "file:" && | ||
location.pathname.endsWith("static/render/index.html")) || | ||
location.hostname === "localhost" || | ||
location.hostname === "127.0.0.1" | ||
) { | ||
window.AgoraRtcEngine = require("agora-electron-sdk").default; | ||
window.rtcEngine = new window.AgoraRtcEngine(); | ||
window.rtcEngine.initialize(process.env.AGORA_APP_ID); | ||
}); | ||
|
||
window.rtcEngine = new window.AgoraRtcEngine(); | ||
window.rtcEngine.initialize(process.env.AGORA_APP_ID); | ||
} | ||
// delay sending event. prevent the main process from being too late listen for this event | ||
setTimeout(() => { | ||
ipcRenderer.send("preload-load"); | ||
}, 0); | ||
|
||
document.removeEventListener("DOMNodeInserted", DOMNodeInserted); | ||
}); | ||
// because DOMContentLoaded and DOMNodeInserted cannot be used, a new method is adopted to solve the problem of jQuery import failure | ||
Object.defineProperties(window, { | ||
$: { | ||
get() { | ||
return require("jquery"); | ||
}, | ||
}, | ||
jQuery: { | ||
get() { | ||
return require("jquery"); | ||
}, | ||
}, | ||
}); |
This file contains 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
This file contains 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