kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.38k stars 127 forks source link

Modals show() only after other commands like setFrame() #245

Open Taikuh opened 4 years ago

Taikuh commented 4 years ago

In the following code, setFrame() happens before show() even though it is written after.

Modal.build({
    duration: 1,
    animationDuration: 0,
    origin: function (mFrame) {return {x:0, y:0};},
    text: 'Some Text'
}).show();
Window.focused().setFrame(...);

It might not be so obvious because setFrame occurs so quickly. But I have an animate function that calls setFrame in quick succession using a series of intermediate frames. It's more apparent in that situation: show executes after all the setFrames.

Modal.build(...).show();
animateSetFrame(...);

function animateSetFrame(window, origFrame, destFrame) {
    ... // a set loop of window.setFrame()
}

Interestingly, if I wrap setFrame in a zero-delay Timer, show() will fire before setFrame.

Modal.build(...).show();
new Timer(0, false, () => Window.focused().setFrame(...)); // or using animateSetFrame()

I don't mind refactoring my code and functions to account for the necessary Timers, but it will just make my code a lot less readable and easy to understand. I'm also wondering if I'm using the API incorrectly somehow, leading to these effects. In addition, the same things happen when I assign the Modal or Timer to a variable.