|
1 |
| -import { addProfileItem, getProfileConfig, getProfileItem } from '../config' |
| 1 | +import { addProfileItem, getCurrentProfileItem, getProfileConfig, getProfileItem } from '../config' |
2 | 2 |
|
3 | 3 | const intervalPool: Record<string, NodeJS.Timeout> = {}
|
4 | 4 |
|
5 |
| -export function initProfileUpdater(): void { |
6 |
| - const { items } = getProfileConfig() |
7 |
| - |
8 |
| - for (const item of items) { |
| 5 | +export async function initProfileUpdater(): Promise<void> { |
| 6 | + const { items, current } = getProfileConfig() |
| 7 | + const currentItem = getCurrentProfileItem() |
| 8 | + for (const item of items.filter((i) => i.id !== current)) { |
9 | 9 | if (item.type === 'remote' && item.interval) {
|
10 |
| - addProfileItem(getProfileItem(item.id)) |
| 10 | + await addProfileItem(item) |
11 | 11 | intervalPool[item.id] = setInterval(
|
12 |
| - () => { |
13 |
| - addProfileItem(getProfileItem(item.id)) |
| 12 | + async () => { |
| 13 | + await addProfileItem(item) |
14 | 14 | },
|
15 | 15 | item.interval * 60 * 1000
|
16 | 16 | )
|
17 | 17 | }
|
18 | 18 | }
|
| 19 | + if (currentItem.type === 'remote' && currentItem.interval) { |
| 20 | + await addProfileItem(currentItem) |
| 21 | + intervalPool[currentItem.id] = setInterval( |
| 22 | + async () => { |
| 23 | + await addProfileItem(currentItem) |
| 24 | + }, |
| 25 | + currentItem.interval * 60 * 1000 + 10000 // +10s |
| 26 | + ) |
| 27 | + } |
19 | 28 | }
|
20 | 29 |
|
21 | 30 | export function addProfileUpdater(id: string): void {
|
22 |
| - const { items } = getProfileConfig() |
23 |
| - const item = items.find((i) => i.id === id) |
| 31 | + const item = getProfileItem(id) |
24 | 32 |
|
25 |
| - if (item?.type === 'remote' && item.interval) { |
| 33 | + if (item.type === 'remote' && item.interval) { |
26 | 34 | if (intervalPool[id]) {
|
27 | 35 | clearInterval(intervalPool[id])
|
28 | 36 | }
|
29 | 37 | intervalPool[id] = setInterval(
|
30 |
| - () => { |
31 |
| - addProfileItem(getProfileItem(id)) |
| 38 | + async () => { |
| 39 | + await addProfileItem(item) |
32 | 40 | },
|
33 | 41 | item.interval * 60 * 1000
|
34 | 42 | )
|
|
0 commit comments