(pluginId, justInstalled = false)
| 127 | } |
| 128 | |
| 129 | export async function loadPluginWithTimeout(pluginId, justInstalled = false) { |
| 130 | const pluginState = { settled: false }; |
| 131 | const pluginLoadPromise = loadPlugin(pluginId, justInstalled) |
| 132 | .catch(async (error) => { |
| 133 | pluginState.settled = true; |
| 134 | await markPluginBroken(pluginId, error); |
| 135 | throw error; |
| 136 | }) |
| 137 | .then(async () => { |
| 138 | pluginState.settled = true; |
| 139 | await markPluginLoaded(pluginId, justInstalled); |
| 140 | }); |
| 141 | |
| 142 | try { |
| 143 | // Let app startup continue if a plugin is slow, but keep loading it in |
| 144 | // the background so good plugins on slower devices can still recover. |
| 145 | await Promise.race([ |
| 146 | pluginLoadPromise, |
| 147 | new Promise((_, rej) => |
| 148 | setTimeout( |
| 149 | () => rej(new PluginLoadTimeoutError()), |
| 150 | PLUGIN_LOAD_TIMEOUT, |
| 151 | ), |
| 152 | ), |
| 153 | ]); |
| 154 | return true; |
| 155 | } catch (error) { |
| 156 | if (error instanceof PluginLoadTimeoutError) { |
| 157 | markPluginTimedOut(pluginId, pluginState); |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | throw error; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | async function markPluginLoaded(pluginId, justInstalled = false) { |
| 166 | LOADED_PLUGINS.add(pluginId); |
no test coverage detected