• hi,

    the "alarm and timer ETA" widget currently dont show stopwatch e.g. "stopwatch touch" at the status bar.

    I would like to change that.

    indeed with the "digital clock widget", we can have clock in status bar and stopwatch in the app;
    so i wish at the clock face, we can have time + stopwatch too.

    ps: this beat the legends like casio f-91, which can only show either clock OR stopwatch, but not both:

    I briefly asked gpt4,
    let's see how good it is later.
    :
    You can extend the widget to support the stopwatch by modifying the code to consider the stopwatch's state and time. Here is a modified version of your provided code that should incorporate the stopwatch's display into the widget. The main idea is to read the stopwatch's state and remaining time from its JSON storage and display it on the widget if it's running.

    1. Update the loadSettings function to also load the stopwatch settings.
    2. Modify the draw function to consider the stopwatch state and display its time if it's running.
    3. Make necessary adjustments in other parts of the code to accommodate the stopwatch display.

    Here is the modified version of your provided widget code to incorporate the stopwatch:

    javascript
    (() => {
      let config, stopwatchConfig;
    
      function loadSettings() {
        config = Object.assign({
          // ... (your existing settings)
        }, require("Storage").readJSON("widalarmeta­.json",1) || {});
    
        stopwatchConfig = require("Storage").readJSON("stopwatch.j­son",1) || {};
    
        // ... (your existing code to load fonts, etc.)
      }
      loadSettings();
    
      // ... (your existing functions like getNextAlarm)
    
      function draw(_w, fromInterval) {
        let next;
    
        if (stopwatchConfig.state && stopwatchConfig.state.running) {
          next = Date.now() - stopwatchConfig.state.start;
        } else {
          if (this.nextAlarm === undefined) {
            let alarm = getNextAlarm();
            // ... (your existing code)
          }
          next = this.nextAlarm !== undefined ? require("sched").getTimeToAlarm(this.nex­tAlarm) : 0;
        }
    
        // ... (your existing code to display time, handle font and width calculations, etc.)
    
        // Add an additional condition to redraw if the stopwatch is running
        const period = stopwatchConfig.state.running ? 1000 :
                       next === 0 ? 3600000 :
                       (drawSeconds ? 1000 : 60000);
    
        // ... (your existing code to set timeout and redraw, etc.)
      }
    
      // ... (your existing code to add the widget and other functionalities, etc.)
    })();
    

    Changes made:

    • Loaded the stopwatch settings along with the alarm settings.
    • Checked if the stopwatch is running and updated the next variable accordingly.
    • Added an additional condition to set the redraw period to every second if the stopwatch is running to update the stopwatch display in real-time.

    You might need to adjust the display format or layout as per your needs. Ensure to test thoroughly to make sure it works as expected and doesn’t interfere with other functionalities.

About

Avatar for ccchan @ccchan started