Skip to content

Commit

Permalink
fix auto update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 12, 2024
1 parent 6edb0a6 commit 20d1eb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/main/core/profileUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
import { addProfileItem, getProfileConfig, getProfileItem } from '../config'
import { addProfileItem, getCurrentProfileItem, getProfileConfig, getProfileItem } from '../config'

const intervalPool: Record<string, NodeJS.Timeout> = {}

export function initProfileUpdater(): void {
const { items } = getProfileConfig()

for (const item of items) {
const { items, current } = getProfileConfig()
const currentItem = getCurrentProfileItem()
for (const item of items.filter((i) => i.id !== current)) {
if (item.type === 'remote' && item.interval) {
addProfileItem(getProfileItem(item.id))
addProfileItem(item)
intervalPool[item.id] = setInterval(
() => {
addProfileItem(getProfileItem(item.id))
addProfileItem(item)
},
item.interval * 60 * 1000
)
}
}
if (currentItem.type === 'remote' && currentItem.interval) {
addProfileItem(currentItem)
intervalPool[currentItem.id] = setInterval(
() => {
addProfileItem(currentItem)
},
currentItem.interval * 60 * 1000 + 10000 // +10s
)
}
}

export function addProfileUpdater(id: string): void {
const { items } = getProfileConfig()
const item = items.find((i) => i.id === id)
const item = getProfileItem(id)

if (item?.type === 'remote' && item.interval) {
if (item.type === 'remote' && item.interval) {
if (intervalPool[id]) {
clearInterval(intervalPool[id])
}
intervalPool[id] = setInterval(
() => {
addProfileItem(getProfileItem(id))
addProfileItem(item)
},
item.interval * 60 * 1000
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (!gotTheLock) {
startCore().then(() => {
setTimeout(() => {
initProfileUpdater()
}, 30000)
}, 10000)
})
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
Expand Down

0 comments on commit 20d1eb0

Please sign in to comment.