|
5 | 5 | Main entry point |
6 | 6 | */ |
7 | 7 |
|
| 8 | +setAppId(); |
| 9 | + |
8 | 10 |
|
9 | 11 | import { engine } from './modules/babylon.js'; |
10 | 12 | import * as CORE from './modules/core.js'; |
@@ -57,3 +59,37 @@ engine.init(adapter && CORE.preferences.isWebGPU()).then(eng => { |
57 | 59 |
|
58 | 60 |
|
59 | 61 | export let scene = undefined; |
| 62 | + |
| 63 | + |
| 64 | +function setAppId() { |
| 65 | + const THRESHOLD = 3.6e+6; // ms == 60 min |
| 66 | + |
| 67 | + function getQueryParam(name) { |
| 68 | + const urlParams = new URLSearchParams(window.location.search); |
| 69 | + return urlParams.get(name); |
| 70 | + } |
| 71 | + |
| 72 | + // update query param without reloading |
| 73 | + function updateQueryParam(name, value) { |
| 74 | + const url = new URL(window.location); |
| 75 | + url.searchParams.set(name, value); |
| 76 | + window.history.replaceState(null, '', url.toString()); |
| 77 | + } |
| 78 | + |
| 79 | + const appId = localStorage.getItem('appid'); |
| 80 | + const now = Date.now(); |
| 81 | + |
| 82 | + if (getQueryParam('id')) { |
| 83 | + if (!appId || (now - parseInt(appId, 10) > THRESHOLD)) { |
| 84 | + // update url, no reload needed |
| 85 | + localStorage.setItem('appid', now.toString()); |
| 86 | + updateQueryParam('id', now.toString()); |
| 87 | + } else { |
| 88 | + // recent url, no action needed |
| 89 | + } |
| 90 | + } else { |
| 91 | + // fresh url, assign a new id |
| 92 | + localStorage.setItem('appid', now.toString()); |
| 93 | + updateQueryParam('id', now.toString()); |
| 94 | + } |
| 95 | +} |
0 commit comments