| 201 | * Call this at app startup to pre-load the Tauri HTTP plugin. |
| 202 | */ |
| 203 | export const initPlatformFetch = async (): Promise<void> => { |
| 204 | if (!isDesktop()) return; |
| 205 | |
| 206 | if (tauriFetchLoading) { |
| 207 | await tauriFetchLoading; |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | tauriFetchLoading = (async () => { |
| 212 | try { |
| 213 | const { fetch } = await import('@tauri-apps/plugin-http'); |
| 214 | tauriFetchFn = fetch; |
| 215 | Logger.info('platform', 'Tauri HTTP plugin loaded for desktop localhost requests'); |
| 216 | } catch (err) { |
| 217 | console.warn('[Platform] Failed to load Tauri HTTP plugin:', err); |
| 218 | } |
| 219 | })(); |
| 220 | |
| 221 | await tauriFetchLoading; |
| 222 | }; |
| 223 | |
| 224 | /** |
| 225 | * Platform-aware fetch for local/private network requests. |