Plugin's Web Worker should be a priority

I use the obsidian-pomodoro-timer and i was pretty happy with it. However, i think an update changed something because now the timer does not run on the background. I’ve written about the issue more in detail in the plugin’s repo:

Upon further testing, it was due to my plugin count. After i close random amount of plugins, the timer starts working normally. The code that is responsible for running the clock uses Worker. Is there a way that it can be a priority if it is being culled by memory management of Obsidian? Or any other fix ideas, like rewriting the plugin without Worker?

I’ve rewritten the Web Worker code and manage to solve this issue. If anyone else having the same error as me:

Changed the web Worker as such:

let running = false
let intervalId: number | undefined
let lowFps = false
let prev = 0

self.onmessage = ({ data }) => {
    if (data.start) {
        lowFps = data.lowFps

        if (!running) {
            running = true
            prev = Date.now()

            const delay = lowFps ? 1000 : 16

            intervalId = setInterval(() => {
                const now = Date.now()
                const delta = now - prev
                prev = now
                self.postMessage(delta)
            }, delay)
        }
    } else {
        running = false
        if (intervalId) {
            clearInterval(intervalId)
            intervalId = undefined
        }
    }
}

I don’t know about JS, so my question is, if I’ve to embed your new code as raw like in the original or if I need to create a new function call for it.

As I see it, your code needs to be embedded as raw because the original self.onmessage call that you modified is just one part of the code in function inlineWorker.

Maybe I’m lazy to insert \n and escape chars to modify your code to raw code, but before I do this, I’d like to get your confirmation as I’m not interested to experiment around. Thanks for the rewrite anyway.