| 36 | |
| 37 | // Define start sequence. |
| 38 | async start () { |
| 39 | Log.info(`Starting module: ${this.name}`); |
| 40 | |
| 41 | this.lastComplimentIndex = -1; |
| 42 | |
| 43 | if (this.config.remoteFile !== null) { |
| 44 | const response = await this.loadComplimentFile(); |
| 45 | this.config.compliments = JSON.parse(response); |
| 46 | this.updateDom(); |
| 47 | if (this.config.remoteFileRefreshInterval !== 0) { |
| 48 | if ((this.config.remoteFileRefreshInterval >= this.refreshMinimumDelay) || window.mmTestMode === "true") { |
| 49 | setInterval(async () => { |
| 50 | const response = await this.loadComplimentFile(); |
| 51 | if (response) { |
| 52 | this.compliments_new = JSON.parse(response); |
| 53 | } |
| 54 | else { |
| 55 | Log.error(`[compliments] ${this.name} remoteFile refresh failed`); |
| 56 | } |
| 57 | }, |
| 58 | this.config.remoteFileRefreshInterval); |
| 59 | } else { |
| 60 | Log.error(`[compliments] ${this.name} remoteFileRefreshInterval less than minimum`); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | let minute_sync_delay = 1; |
| 65 | // loop thru all the configured when events |
| 66 | for (let m of Object.keys(this.config.compliments)) { |
| 67 | // if it is a cron entry |
| 68 | if (this.isCronEntry(m)) { |
| 69 | // we need to synch our interval cycle to the minute |
| 70 | minute_sync_delay = (60 - (moment().second())) * 1000; |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | // Schedule update timer. sync to the minute start (if needed), so minute based events happen on the minute start |
| 75 | setTimeout(() => { |
| 76 | setInterval(() => { |
| 77 | this.updateDom(this.config.fadeSpeed); |
| 78 | }, this.config.updateInterval); |
| 79 | }, |
| 80 | minute_sync_delay); |
| 81 | }, |
| 82 | |
| 83 | // check to see if this entry could be a cron entry which contains spaces |
| 84 | isCronEntry (entry) { |