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 } ) ( ) ;
0 commit comments