mirror of
https://github.com/cupcakearmy/ora.git
synced 2025-09-06 08:10:40 +00:00
progress
This commit is contained in:
@@ -3,7 +3,7 @@ import dayjs from 'dayjs'
|
||||
|
||||
import { dashboard } from '../shared/utils'
|
||||
import { insertLog, normalizeTimestamp, DB } from '../shared/db'
|
||||
import { getUsageForHost, percentagesToBool } from '../shared/lib'
|
||||
import { getSettingsWithDefaults, getUsageForHost, percentagesToBool } from '../shared/lib'
|
||||
|
||||
browser.browserAction.onClicked.addListener(() => browser.tabs.create({ url: dashboard, active: true }))
|
||||
|
||||
@@ -18,22 +18,33 @@ async function log() {
|
||||
const window = windows.find((window) => window.id === tab.windowId)
|
||||
return tab.active && window.focused
|
||||
})
|
||||
.map(({ id, title, url }) => {
|
||||
.map(({ url, audible, mutedInfo }) => {
|
||||
const { host } = new URL(url)
|
||||
return { id, title, host }
|
||||
return { host, audio: audible && !mutedInfo.muted }
|
||||
})
|
||||
.filter((x) => x.host)
|
||||
|
||||
await Promise.all(
|
||||
active.map(({ host }) => {
|
||||
if (host)
|
||||
return insertLog({
|
||||
timestamp: normalizeTimestamp(new Date()),
|
||||
host,
|
||||
seconds: (frequency / 1000) | 0,
|
||||
})
|
||||
if (active.length === 0) return
|
||||
|
||||
const settings = await getSettingsWithDefaults()
|
||||
let idle = false
|
||||
if (settings.idleTimeout > 0) {
|
||||
idle = dayjs(settings.lastActivity).add(settings.idleTimeout, 'minutes').isBefore(dayjs())
|
||||
}
|
||||
|
||||
const inserted = active
|
||||
.filter((tab) => !idle || tab.audio)
|
||||
.map((tab) => {
|
||||
return insertLog({
|
||||
timestamp: normalizeTimestamp(new Date()),
|
||||
host: tab.host,
|
||||
seconds: (frequency / 1000) | 0,
|
||||
})
|
||||
})
|
||||
)
|
||||
} catch {}
|
||||
await Promise.all(inserted)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteOldLogs() {
|
||||
|
Reference in New Issue
Block a user