Skip to content

Commit

Permalink
fix: ensure auto connect is only run in webview environment
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshydra committed Feb 17, 2024
1 parent 81ea3e5 commit 41a8b6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
alwaysAllowUpdate : false, // Always show "reinstall app" buttonregardless of the version
autoReload: false // Automatically reload watch after app App Loader actions (removes "Hold button" prompt)
};
window.__getInstalledApps_resolve = null;
window.getInstalledApps = () => new Promise((resolve) => {
window.__getInstalledApps_resolve = resolve;
});
if (typeof Android !== "undefined") {
window.__getInstalledApps_resolve = null;
window.getInstalledApps = () => new Promise((resolve) => {
window.__getInstalledApps_resolve = resolve;
});
}
</script>
<script src="https://banglejs.com/apps/core/js/utils.js"></script>
<script src="https://banglejs.com/apps/webtools/puck.js"></script>
Expand Down
9 changes: 4 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ function Entry() {
const sync = useEspruinoDeviceInfoStore(state => state.sync);
const connect = useEspruinoDeviceInfoStore(state => state.connect);
useEffect(() => {
connect().then(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.__getInstalledApps_resolve();
});
if ('__getInstalledApps_resolve' in window && typeof window.__getInstalledApps_resolve === "function") {
const resolve = window.__getInstalledApps_resolve;
connect().then(() => resolve());
}

const timeoutId = setTimeout(() => {
EspruinoComms.watchConnectionChange(() => {
Expand Down

0 comments on commit 41a8b6f

Please sign in to comment.