@@ -250,28 +250,72 @@ let installer = (function () {
250250 } ;
251251} ) ( ) ;
252252
253- function install ( ) {
253+ let _downloadInterval = null ;
254+
255+ async function startDownload ( ) {
256+ const dlBtn = document . querySelector ( '.download-button' ) ;
257+ const installBtn = document . querySelector ( '.install-button' ) ;
258+ if ( ! dlBtn || ! installBtn ) return ;
259+
260+ // UI: disable download and show immediate feedback
261+ dlBtn . disabled = true ;
262+ dlBtn . textContent = 'Downloading...' ;
254263 pulse ( true ) ;
255264 loadingImg ( 0 ) ;
256265
257- // start polling every 0.5s immediately
258- const interval = setInterval ( ( ) => {
259- const status = installer . getStatus ( ) ; // % progress
266+ // start a short interval to update progress UI from installer.getStatus()
267+ _downloadInterval = setInterval ( ( ) => {
268+ const status = installer . getStatus ( ) ; // 0..100
260269 loadingImg ( status ) ;
261-
262- // stop when finished
263- if ( status >= 100 || installer . isFinished ) {
264- clearInterval ( interval ) ;
265- window . location . href = installer . getInstallLink ( ) ;
266- pulse ( false ) ;
267- }
270+ dlBtn . textContent = `Downloading... ${ status } %` ;
268271 } , 500 ) ;
269272
270- // start the install
271- installer . beginInstall ( { repo : "ProStore-iOS/ProStore" , token : null } )
272- . catch ( err => {
273- console . error ( "Install failed:" , err ) ;
274- clearInterval ( interval ) ;
275- pulse ( false ) ;
276- } ) ;
273+ try {
274+ // start the install flow (returns preflight info when finished)
275+ const data = await installer . beginInstall ( { repo : "ProStore-iOS/ProStore" , token : null } ) ;
276+
277+ // finished: stop polling and show install button instead of redirect
278+ clearInterval ( _downloadInterval ) ;
279+ _downloadInterval = null ;
280+ loadingImg ( 100 ) ;
281+ pulse ( false ) ;
282+
283+ // swap the download button for the install button
284+ dlBtn . style . display = 'none' ;
285+ installBtn . style . display = '' ;
286+ installBtn . disabled = false ;
287+ installBtn . textContent = 'Install' ; // could show version/name if you want
288+
289+ // Optionally store data somewhere or show extra info:
290+ // console.log('Preflight data:', data);
291+ } catch ( err ) {
292+ // error handling: re-enable button, clear polling, show message
293+ clearInterval ( _downloadInterval ) ;
294+ _downloadInterval = null ;
295+ pulse ( false ) ;
296+ loadingImg ( 0 ) ;
297+
298+ dlBtn . disabled = false ;
299+ dlBtn . textContent = 'Download' ;
300+ console . error ( 'Install failed:' , err ) ;
301+ alert ( 'Download failed: ' + ( err && err . message ? err . message : err ) ) ;
302+ }
303+ }
304+
305+ // When the user clicks Install, run the itms-services link
306+ function performInstall ( ) {
307+ const installBtn = document . querySelector ( '.install-button' ) ;
308+ if ( ! installBtn ) return ;
309+
310+ const link = installer . getInstallLink ( ) ;
311+ if ( ! link ) {
312+ alert ( 'Install link not available. Please try Download again.' ) ;
313+ return ;
314+ }
315+
316+ installBtn . disabled = true ;
317+ installBtn . textContent = 'Installing...' ;
318+
319+ // Trigger the itms-services install
320+ window . location . href = link ;
277321}
0 commit comments