spacedrive/scripts/utils/spinner.mjs
Vítor Vasconcellos b4d1a295ff [ENG-1840, ENG-1842] Add native dependencies for iOS (#2693)
* Implement dowload of mobile native deps
 - Add a spinner animation to `pnpm prep`
 - Change abandoned dependency @iarna/toml with smol-toml
 - Validate cargo config.toml after generating it from mustache template
 - Disabled HTTP2 downloads with udici, it is very broken

* Initial ios native deps xcframework logic

* Remove logic for handling dynamic iOS libs, using static libs now

* Fix PATH in build-rust.sh
 - Remove app.json

* Restore crates/images/src/pdf.rs

* minor fix .editorconfig

* Finally ios successfully compiles with ffmpeg enabled
 - Change SDCore.podspec to add extra libraries required by ffmpeg
 - Fix heif linking for ios in config.toml template
 - Add symlink logic for extra libraries required to compile ios in build-rust.sh
2024-09-17 02:27:42 +00:00

45 lines
1.2 KiB
JavaScript

/**
* Simple function that implements a spinner animation in the terminal.
* It receives an AbortController as argument and return a promise that resolves when the AbortController is signaled.
* @param {AbortController} abortController
* @returns {Promise<void>}
*/
export function spinnerAnimation(abortController) {
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
let frameIndex = 0
return new Promise(resolve => {
const intervalId = setInterval(() => {
process.stdout.write(`\r${frames[frameIndex++]}`)
frameIndex %= frames.length
}, 100)
const onAbort = () => {
clearInterval(intervalId)
process.stdout.write('\r \r') // Clear spinner
resolve()
}
if (abortController.signal.aborted) {
onAbort()
} else {
abortController.signal.addEventListener('abort', onAbort)
}
})
}
/**
* Wrap a long running task with a spinner animation.
* @template T
* @param {Promise<T>} promise
* @returns {Promise<T>}
*/
export async function spinTask(promise) {
const spinnerControl = new AbortController()
const [, result] = await Promise.all([
spinnerAnimation(spinnerControl),
promise.finally(() => spinnerControl.abort('Task is over')),
])
return result
}