pause only for limited time

This commit is contained in:
2021-05-15 16:32:12 +02:00
parent 928b69b4fb
commit 6fba47a4f8
6 changed files with 131 additions and 83 deletions

View File

@@ -8,13 +8,15 @@ import { productName } from '../../package.json'
const autoLaunch = new AutoLaunch({ name: productName, mac: { useLaunchAgent: true } })
import { DEV } from '.'
import ms from 'ms'
import dayjs from 'dayjs'
const store = new Store()
const defaults = {
every: 20,
duration: 20,
boot: true,
paused: false,
paused: 0,
lastRun: 0,
autoClose: false,
}
@@ -26,7 +28,7 @@ const normalizers: Record<SettingKeys, (x: any) => any> = {
duration: IntNormalizer,
boot: BoolNormalizer,
autoClose: BoolNormalizer,
paused: BoolNormalizer,
paused: IntNormalizer,
lastRun: IntNormalizer,
}
@@ -82,4 +84,17 @@ export default class Settings {
Settings.win.webContents.openDevTools()
}
}
static getStatus(): [boolean, number] {
const paused: number = Settings.load('paused')
const now = Date.now()
if (paused > now) {
return [true, paused - now]
}
const every = Settings.load('every')
const lastRun = Settings.load('lastRun')
const diff = every * 60 * 1000 - dayjs(now).diff(dayjs(lastRun), 'ms')
return [false, diff]
}
}