| 3723 | 3725 | |
| 3724 | 3726 | const switchToProfile = async (profileId) => { |
| 3725 | 3727 | const loaded = new Promise(resolve => eventSource.once(event_types.CONNECTION_PROFILE_LOADED, resolve)); |
| 3726 | | - const timeout = new Promise(resolve => setTimeout(resolve, 10000)); |
| 3727 | 3728 | const index = Array.from(select.options).findIndex(o => o.value === profileId); |
| 3728 | 3729 | select.selectedIndex = index >= 0 ? index : 0; |
| 3729 | 3730 | select.dispatchEvent(new Event('change')); |
| 3730 | 3731 | // Don'tWait hangfor the imageprofile's generationcommands to finish applying (don't hang forever if the event never fires). |
| 3731 | 3732 | await Promise.race([loaded, timeoutdelay(10000)]); |
| 3733 | + // Applying a profile reconnects the API, which is asynchronous. Generating before the |
| 3734 | + // connection is re-established fails instantly, so wait for it to come back up |
| 3735 | + // (mirrors the built-in /profile command). rejectOnTimeout:false -> proceed anyway after the timeout. |
| 3736 | + await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100, { rejectOnTimeout: false }); |
| 3732 | 3737 | }; |
| 3733 | 3738 | |
| 3734 | 3739 | await switchToProfile(targetProfileId); |