hrgdavor / jscadui

MIT License
30 stars 7 forks source link

Use progress indicator instead of spinner #101

Closed eevleevs closed 6 months ago

eevleevs commented 6 months ago

sample script to test is:

const jscad = require('@jscad/modeling')
const { intersect, subtract } = jscad.booleans
const { colorize } = jscad.colors
const { cube, sphere } = jscad.primitives

const sendProgress = (progress, note) => globalThis.postMessage?.({ method: 'onProgress', params: [ progress, note] })

async function main() {
  let _resolve
  setTimeout(()=>sendProgress(0.25,'first'), 500)
  setTimeout(()=>sendProgress(0.5,'second'), 1000)
  setTimeout(()=>sendProgress(0.75,'third'), 1500)
  setTimeout(()=>_resolve(), 2000,'DONE')

  await new Promise(resolve=>_resolve = resolve)

  const outer = subtract(
    cube({ size: 10 }),
    sphere({ radius: 6.8 })
  )
  const inner = intersect(
    sphere({ radius: 4 }),
    cube({ size: 7 })
  )
  return [
    colorize([0.65, 0.25, 0.8], outer),
    colorize([0.7, 0.7, 0.1], inner),
  ]
}

module.exports = { main }
eevleevs commented 6 months ago

Not sure about the recent changes in main.js, will leave you to merge.

hrgdavor commented 6 months ago

ok, tweaked the onProgress method signature from const onProgress = ([value, note]) => { to const onProgress = (value, note) => { and the matching postMessage is postMessage({ method: 'onProgress', params: [ progress, note] })

eevleevs commented 6 months ago

ok, tweaked the onProgress method signature from const onProgress = ([value, note]) => { to const onProgress = (value, note) => { and the matching postMessage is postMessage({ method: 'onProgress', params: [ progress, note] })

Updated also the use of onProgress without parameters for reset.