Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clock face logic disappearing when using Apps

I'm developing a clock face that has items appear on screen daily (i.e. text, button, event listeners), disappear at night, and reappear the next morning & so on. I'm running into an issue where if an App is opened/run (Exercise), accidentally or otherwise (i.e. gesturing to open the Clocks app), the text and event listeners disappear from the main clock face and do not return until the following morning. What would be the proper way to reinstate these items upon returning to the clock face after the App is closed? Thanks in advance.

Best Answer
0 Votes
7 REPLIES 7

Check the time in your startup code, and set the items' .style.display based on that. I thought you'd have to do that anyway, in case a user starts your clockface at night.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Hi @dbe5007  - when an app is initiated the exit from the clock face can be trapped in the on unload. You can save the state of things and at start up reapply them.

 

That way you have full continuity allowing users to leave and come back to the clock face.

Author | ch, passion for improvement.

Best Answer
0 Votes

Thanks for the suggestion. I’m not completely clear on the syntax using the document API so apologies if this question is confusing. When you say “the state of things”, do you mean save the entire current view as some variable that can be applied on startup or each individual item? Would something similar to below accomplish your suggestion?

 

document.onunload = (evt) => { 
  console.log(“on unload called”);
  evt.preventDefault();

  let textItem = document.getElementById("textItem");
  textItem.style.opacity = 1;

  // Set Button Event Listener
  button.style.opacity = 1;
  button._eventListener = () => {
    dataFunction(button);
  }; 
  
  button.addEventListener("click", button._eventListener );
}
Best Answer
0 Votes

@dbe5007- you need to save the state of the clock face variables on exit and restore them on start so that the interruption is transparent and things can carry on irrespective of the interruption, otherwise you will always start at the same place each time the clock face starts.

 

Any app that is started on purpose or inadvertently will stop the clock face.

Author | ch, passion for improvement.

Best Answer
0 Votes

While I agree that state data that needs to persist should be saved and reloaded, my understanding of the original problem is the opposite of this. Elements need to be initialised to be displayed or hidden based on the time at which the clockface starts, not the time at which it was last closed.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana - if it's at clock face start this would be a pure initialisation issue or even a default setting if at clock face start as opposed to time of clock face start.

 

The question seems to be a reinitialisation issue if the clock face is ended and restarted though.

Author | ch, passion for improvement.

Best Answer
0 Votes

I understood the issue like Gondwana described. But it might not work as he doesn't observe the state having switched until next event.
In this case I'd say it depends on where the check is placed and in which interval or what he checks exactly for in his code. 

Best Answer
0 Votes