Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions AI/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,86 @@ window.addEventListener('focus', () => {
}
});

function normalizeLaunchResults(detail) {
if (!detail || typeof detail !== 'object') {
return null;
}

const normalizedResults = Array.isArray(detail.results)
? detail.results
.map((item) => {
if (!item || typeof item !== 'object') {
return null;
}

const id = typeof item.id === 'string' ? item.id : undefined;
if (!id) {
return null;
}

return {
id,
label: item.label || item.friendlyName || id,
met: Boolean(item.met)
};
})
.filter(Boolean)
: null;

if (!normalizedResults || normalizedResults.length === 0) {
return null;
}

const inferredAllMet = normalizedResults.every((result) => result.met);
const allMet = typeof detail.allMet === 'boolean' ? detail.allMet : inferredAllMet;

return {
results: normalizedResults,
allMet
};
}

async function handleTalkToUnityLaunch(detail) {
const normalized = normalizeLaunchResults(detail);

if (normalized) {
updateDependencyUI(normalized.results, normalized.allMet, { announce: false });
} else if (!appStarted) {
evaluateDependencies();
}

if (appStarted) {
if (typeof window !== 'undefined') {
delete window.__talkToUnityLaunchIntent;
}
return;
}

try {
await startApplication();
} catch (error) {
console.error('Failed to start the Talk to Unity experience:', error);
appStarted = false;
throw error;
} finally {
if (typeof window !== 'undefined') {
delete window.__talkToUnityLaunchIntent;
}
}
}

window.addEventListener('talk-to-unity:launch', (event) => {
handleTalkToUnityLaunch(event?.detail).catch((error) => {
console.error('Error while handling Talk to Unity launch event:', error);
});
});

if (typeof window !== 'undefined' && window.__talkToUnityLaunchIntent) {
handleTalkToUnityLaunch(window.__talkToUnityLaunchIntent).catch((error) => {
console.error('Failed to honor pending Talk to Unity launch intent:', error);
});
}

function evaluateDependencies({ announce = false } = {}) {
const results = dependencyChecks.map((descriptor) => {
let met = false;
Expand Down
4 changes: 4 additions & 0 deletions landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@
const detail = event?.detail ?? {};
const { allMet = false, missing = [] } = detail;

if (typeof window !== 'undefined') {
window.__talkToUnityLaunchIntent = detail;
}

const summary = formatDependencyList(missing);
const tone = allMet ? 'success' : 'warning';
const launchMessage = allMet
Expand Down