Skip to content

Commit 483090e

Browse files
committed
fix: refactor launch button logic for reliable navigation
1 parent 8829b75 commit 483090e

File tree

2 files changed

+55
-102
lines changed

2 files changed

+55
-102
lines changed

landing.js

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -23,106 +23,5 @@
2323

2424

2525

26-
function showRecheckInProgress() {
27-
if (window.launchButton) {
28-
window.launchButton.disabled = true;
29-
window.launchButton.setAttribute('aria-disabled', 'true');
30-
window.launchButton.dataset.state = 'pending';
31-
}
32-
if (window.dependencyLight) {
33-
window.dependencyLight.dataset.state = 'pending';
34-
window.dependencyLight.setAttribute('aria-label', 'Re-checking requirements');
35-
}
36-
if (window.dependencySummary) window.dependencySummary.textContent = 'Re-checking your setup…';
37-
if (window.dependencyList) {
38-
window.dependencyList.querySelectorAll('.dependency-item').forEach((item) => {
39-
item.dataset.state = 'pending';
40-
const statusElement = item.querySelector('.dependency-status');
41-
if (statusElement) statusElement.textContent = 'Checking…';
42-
});
43-
}
44-
window.setStatusMessage('Running the readiness scan again…', 'info');
45-
}
46-
47-
48-
49-
function handleRecheckClick() {
50-
showRecheckInProgress();
51-
window.evaluateDependencies({ announce: true });
52-
}
53-
54-
function ensureTrailingSlash(value) {
55-
if (typeof value !== 'string' || !value) return '';
56-
return value.endsWith('/') ? value : `${value}/`;
57-
}
58-
59-
function resolveAppLaunchUrl() {
60-
// Fixed version — ensures the correct relative path works on all browsers
61-
const configuredBase =
62-
typeof window.__talkToUnityAssetBase === 'string' && window.__talkToUnityAssetBase
63-
? window.__talkToUnityAssetBase
64-
: '';
65-
let base = ensureTrailingSlash(configuredBase);
66-
67-
if (!base) {
68-
try {
69-
base = ensureTrailingSlash(new URL('.', window.location.href).toString());
70-
} catch {
71-
console.warn('Unable to determine Talk to Unity base path. Falling back to relative navigation.');
72-
base = '';
73-
}
74-
}
75-
76-
try {
77-
// ✅ Fixed: Always points to ./AI/index.html with proper slash
78-
return new URL('./AI/index.html', base || window.location.href).toString();
79-
} catch (error) {
80-
console.warn('Failed to resolve Talk to Unity application URL. Using a relative fallback.', error);
81-
return './AI/index.html';
82-
}
83-
}
84-
85-
function handleLaunchEvent(event) {
86-
const detail = event?.detail ?? {};
87-
const { allMet = false, missing = [] } = detail;
88-
if (typeof window !== 'undefined') window.__talkToUnityLaunchIntent = detail;
89-
90-
const summary = window.formatDependencyList(missing);
91-
const tone = allMet ? 'success' : 'warning';
92-
const launchMessage = allMet
93-
? 'All systems look good. Launching Talk to Unity…'
94-
: summary
95-
? `Launching Talk to Unity. Some features may be limited until we resolve: ${summary}.`
96-
: 'Launching Talk to Unity. Some features may be limited because certain capabilities are unavailable.';
97-
98-
window.setStatusMessage(launchMessage, tone);
99-
document.cookie = 'checks-passed=true;path=/';
100-
window.dependencyLight?.setAttribute('aria-label', allMet
101-
? 'All dependencies satisfied. Launching Talk to Unity'
102-
: `Launching with limited functionality: ${summary}`
103-
);
104-
105-
if (window.launchButton) {
106-
window.launchButton.disabled = true;
107-
window.launchButton.setAttribute('aria-disabled', 'true');
108-
window.launchButton.dataset.state = 'pending';
109-
}
110-
111-
if (window.startApplication) {
112-
window.startApplication();
113-
} else {
114-
const launchUrl = resolveAppLaunchUrl();
115-
if (launchUrl) {
116-
window.location.href = launchUrl;
117-
}
118-
}
119-
}
120-
121-
window.addEventListener('talk-to-unity:launch', handleLaunchEvent);
122-
123-
if (window.launchButton) {
124-
window.launchButton.addEventListener('click', window.handleLaunchButtonClick);
125-
}
126-
12726

12827
})();

scripts/shared.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,61 @@ window.handleLaunchButtonClick = function handleLaunchButtonClick(event) {
158158
const result = window.evaluateDependencies({ announce: true });
159159
if (!result) return;
160160
const { allMet, missing, results } = result;
161-
window.dispatchEvent(new CustomEvent('talk-to-unity:launch', { detail: { allMet, missing, results } }));
161+
162+
// Update UI based on dependency check results
163+
window.setStatusMessage(allMet
164+
? 'All systems look good. Launching Talk to Unity…'
165+
: `Launching Talk to Unity. Some features may be limited until we resolve: ${window.formatDependencyList(missing)}.`, allMet ? 'success' : 'warning');
166+
document.cookie = 'checks-passed=true;path=/';
167+
window.dependencyLight?.setAttribute('aria-label', allMet
168+
? 'All dependencies satisfied. Launching Talk to Unity'
169+
: `Launching with limited functionality: ${window.formatDependencyList(missing)}`);
170+
171+
if (window.launchButton) {
172+
window.launchButton.disabled = true;
173+
window.launchButton.setAttribute('aria-disabled', 'true');
174+
window.launchButton.dataset.state = 'pending';
175+
}
176+
177+
if (window.startApplication) {
178+
window.startApplication();
179+
} else {
180+
const launchUrl = resolveAppLaunchUrl();
181+
if (launchUrl) {
182+
window.location.href = launchUrl;
183+
}
184+
}
185+
}
186+
187+
function resolveAppLaunchUrl() {
188+
// Fixed version — ensures the correct relative path works on all browsers
189+
const configuredBase =
190+
typeof window.__talkToUnityAssetBase === 'string' && window.__talkToUnityAssetBase
191+
? window.__talkToUnityAssetBase
192+
: '';
193+
let base = ensureTrailingSlash(configuredBase);
194+
195+
if (!base) {
196+
try {
197+
base = ensureTrailingSlash(new URL('.', window.location.href).toString());
198+
} catch {
199+
console.warn('Unable to determine Talk to Unity base path. Falling back to relative navigation.');
200+
base = '';
201+
}
202+
}
203+
204+
try {
205+
// ✅ Fixed: Always points to ./AI/index.html with proper slash
206+
return new URL('./AI/index.html', base || window.location.href).toString();
207+
} catch (error) {
208+
console.warn('Failed to resolve Talk to Unity application URL. Using a relative fallback.', error);
209+
return './AI/index.html';
210+
}
211+
}
212+
213+
function ensureTrailingSlash(value) {
214+
if (typeof value !== 'string' || !value) return '';
215+
return value.endsWith('/') ? value : `${value}/`;
162216
}
163217

164218
window.initializeSharedDependencies = function() {

0 commit comments

Comments
 (0)