(
cwd: string,
options: { emitRefreshEvent?: boolean | undefined; warningLabel: string },
)
| 22 | } |
| 23 | |
| 24 | function startShellIndexSync( |
| 25 | cwd: string, |
| 26 | options: { emitRefreshEvent?: boolean | undefined; warningLabel: string }, |
| 27 | ) { |
| 28 | const syncPromise = syncShellIndex(cwd) |
| 29 | .then((syncResult) => { |
| 30 | if (syncResult.complete) { |
| 31 | syncedShellIndexes.add(cwd) |
| 32 | } |
| 33 | |
| 34 | if (syncResult.didSync && (options.emitRefreshEvent ?? true)) { |
| 35 | emitDesktopEvent({ type: 'shell-state-refresh' }) |
| 36 | } |
| 37 | |
| 38 | return syncResult.complete |
| 39 | }) |
| 40 | .catch((error) => { |
| 41 | console.warn(options.warningLabel, error) |
| 42 | return false |
| 43 | }) |
| 44 | .finally(() => { |
| 45 | inFlightShellIndexSyncs.delete(cwd) |
| 46 | }) |
| 47 | |
| 48 | inFlightShellIndexSyncs.set(cwd, syncPromise) |
| 49 | return syncPromise |
| 50 | } |
| 51 | |
| 52 | export function scheduleShellIndexSync(cwd: string) { |
| 53 | if (syncedShellIndexes.has(cwd) || inFlightShellIndexSyncs.has(cwd)) { |
no test coverage detected