Skip to content

Commit

Permalink
reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
samizdatco committed Dec 1, 2024
1 parent fc9db55 commit 3c30f42
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions lib/classes/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ class App extends RustClass{
}
}

launch(){
checkSupport()
clearImmediate(GUI.launcher)
this.#launched = true
if (this.#active){
console.error('Application is already running')
}else{
this.#active = true
this.#render(args => {
this.#dispatch(JSON.parse(args))
return [
JSON.stringify( GUI.windows.map(win => win.state) ),
GUI.windows.map(win => core(win.canvas.pages[win.page-1]) )
]
})
}

}

#render(roundtrip){
// run the event loop and get a flag signaling whether it should continue
let active = this.ƒ('activate', roundtrip)

if (active || this.eventLoop=='node'){
// schedule next frame update if there are still active windows or a event loop is node-based
// (in which case it can keep running even without windows but unref'd to allow process to exit)
GUI.frameTimer = setTimeout(() => this.#render(roundtrip))
if (this.eventLoop=='node' && !active) GUI.frameTimer.unref()
}else{
// for native event loop with no remaining windows, await a new window + launch() before resuming
this.#active = false
GUI.launcher = null
}
}

#dispatch({ui, state, geom}){
// merge autogenerated window locations into newly opened windows
if (geom) for (const [id, {top, left}] of Object.entries(geom)){
Expand Down Expand Up @@ -147,41 +182,6 @@ class App extends RustClass{
this.ƒ('setRate', GUI.needsFrameUpdates() ? this.#fps : 0)
}

launch(){
checkSupport()
clearImmediate(GUI.launcher)
this.#launched = true
if (this.#active){
console.error('Application is already running')
}else{
this.#active = true
this.#render(args => {
this.#dispatch(JSON.parse(args))
return [
JSON.stringify( GUI.windows.map(win => win.state) ),
GUI.windows.map(win => core(win.canvas.pages[win.page-1]) )
]
})
}

}

#render(roundtrip){
// run the event loop and get a flag signaling whether it should continue
let active = this.ƒ('activate', roundtrip)

if (active || this.eventLoop=='node'){
// schedule next frame update if there are still active windows or a event loop is node-based
// (in which case it can keep running even without windows but unref'd to allow process to exit)
GUI.frameTimer = setTimeout(() => this.#render(roundtrip))
if (this.eventLoop=='node' && !active) GUI.frameTimer.unref()
}else{
// for native event loop with no remaining windows, await a new window + launch() before resuming
this.#active = false
GUI.launcher = null
}
}

quit(){
this.ƒ("quit")
}
Expand Down

0 comments on commit 3c30f42

Please sign in to comment.