pause only for limited time

This commit is contained in:
cupcakearmy 2021-05-15 16:32:12 +02:00
parent 928b69b4fb
commit 6fba47a4f8
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
6 changed files with 131 additions and 83 deletions

View File

@ -14,7 +14,7 @@ To combat and alleviate the symptoms there is the famous 20/20/20 rule that aims
This is not medical advice. Read more [here](https://en.wikipedia.org/wiki/Computer_vision_syndrome) and [here](https://www.aoa.org/healthy-eyes/eye-and-vision-conditions/computer-vision-syndrome).
## 📦 Installation
## 💻 Installation
Head to the [release page](https://github.com/cupcakearmy/unpixel/releases) and grab the latest for your platform.
@ -22,16 +22,17 @@ Head to the [release page](https://github.com/cupcakearmy/unpixel/releases) and
- For `Windows` download the `.exe`.
- For `Linux` either the `.AppImage` or `.deb`, you will know what fits you 😉.
## Building / Development
## 🛠 Building / Development
1. Clone the repo
2. `yarn install`
3. `yarn dist` to build for all platforms
Alternatevly you can run `yarn build` and the `yarn electron-builder -m` for `macOS`, `-l` fir `linux` or `-w` for `windows`.
Alternatively you can run `yarn build` and the `yarn electron-builder -m` for `macOS`, `-l` fir `linux` or `-w` for `windows`.
## RELEASE
## 📦 Release
1. Create a draft release with the new version. (e.g. tag with `v1.2.3`).
2. Push to master and github workflow will build and upload assets to the draft matching the version of `package.json` and draft.
3. When ready publish release.
1. Bump version in `package.json`
2. Create a draft release with the new version. (e.g. tag with `v1.2.3`).
3. Push to master and github workflow will build and upload assets to the draft matching the version of `package.json` and draft.
4. When ready publish release.

View File

@ -11,14 +11,14 @@
"repository": {
"url": "https://github.com/cupcakearmy/unpixel"
},
"version": "1.0.5",
"version": "1.1.0",
"main": "./dist/back/index.js",
"scripts": {
"start": "electron .",
"watch:front": "parcel watch --target front --no-hmr --no-cache ./src/front/banner/index.html ./src/front/settings/index.html",
"watch:front": "parcel watch --target front --no-hmr --no-cache ./src/front/*/index.html",
"watch:back": "parcel watch --target back --no-hmr --no-cache ./src/back/index.ts",
"dev": "run-p watch:*",
"build:front": "parcel build --target front ./src/front/banner/index.html ./src/front/settings/index.html",
"build:front": "parcel build --target front ./src/front/*/index.html",
"build:back": "parcel build --target back ./src/back/index.ts",
"build": "run-s build:*",
"pack": "electron-builder -mwl",
@ -44,6 +44,7 @@
"dayjs": "^1.10.4",
"electron-log": "^4.3.2",
"electron-store": "^7.0.2",
"ms": "^2.1.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"semver": "^7.3.5",
@ -53,6 +54,7 @@
"devDependencies": {
"@babel/core": "^7.0.0-0",
"@types/auto-launch": "^5.0.1",
"@types/ms": "^0.7.31",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@types/semver": "^7.3.4",

View File

@ -3,6 +3,7 @@ import os from 'os'
import { BrowserWindow, BrowserWindowConstructorOptions, ipcMain } from 'electron'
import dayjs from 'dayjs'
import logger from 'electron-log'
import ms from 'ms'
import { DEV } from '.'
import Settings from './settings'
@ -15,24 +16,16 @@ export default class Banner {
static init() {
if (this.interval) return
this.interval = setInterval(this.check, 1000)
this.check()
ipcMain.on('close', () => {
this.close()
})
}
static check() {
const paused: boolean = Settings.load('paused')
if (paused) {
TrayUtility.setStatus('Paused')
return
}
const every = Settings.load('every')
const now = dayjs()
const lastRun = Settings.load('lastRun')
const diff = every - now.diff(dayjs(lastRun), 'minutes')
TrayUtility.setStatus(`Next break: ${diff}m`)
if (diff < 1) {
TrayUtility.build()
const [paused, interval] = Settings.getStatus()
if (!paused && interval < 1000) {
Banner.open()
}
}

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]
}
}

View File

@ -1,53 +1,61 @@
import { Tray, Menu, nativeImage } from 'electron'
import path from 'path'
import ms from 'ms'
import Banner from './banner'
import Settings from './settings'
enum Items {
Status = 'status',
Pause = 'pause',
Run = 'run',
}
export default class TrayUtility {
static menu: Parameters<typeof Menu['buildFromTemplate']>[0] = [
{ label: 'Status', type: 'normal', enabled: false, id: Items.Status },
static tray: Tray | null = null
static build() {
const [paused, interval] = Settings.getStatus()
const status = paused ? `Paused for: ${ms(interval)}` : `Next break: ${ms(interval)}`
const template: Parameters<typeof Menu['buildFromTemplate']>[0] = [
{ label: status, type: 'normal', enabled: false },
{ type: 'separator' },
{
label: 'Take a break now',
type: 'normal',
id: Items.Run,
click: () => Banner.open(),
},
{ label: 'Pause', type: 'checkbox', id: Items.Pause },
{ label: 'Settings', type: 'normal', click: () => Settings.open() },
{ type: 'separator' },
{ label: 'Quit', type: 'normal', role: 'quit' },
]
static tray: Tray | null = null
template.push(
paused
? {
label: 'Break pause',
click: () => {
Settings.save('paused', 0)
this.build()
},
}
: {
label: 'Pause for...',
submenu: Menu.buildFromTemplate(
// Minutes to pause
[10, 30, 60, 120, 360]
.map((minutes) => minutes * 60 * 1000)
.map((time) => ({
label: ms(time),
click: () => {
Settings.save('paused', Date.now() + time)
this.build()
},
}))
),
}
)
static setStatus(status: string) {
this.menu[0].label = status
this.tray?.setContextMenu(this.build())
}
template.push(
{ label: 'Settings', click: () => Settings.open() },
{ type: 'separator' },
{ label: 'Quit', role: 'quit' }
)
private static build() {
const menu = Menu.buildFromTemplate(this.menu)
for (const item of menu.items) {
if (item.id === Items.Pause) {
let initial = Settings.load('paused')
item.checked = initial
item.click = () => {
initial = !initial
item.checked = initial
Settings.save('paused', initial)
}
break
}
}
return menu
const menu = Menu.buildFromTemplate(template)
this.tray?.setContextMenu(menu)
}
static init() {
@ -58,7 +66,7 @@ export default class TrayUtility {
height: 24,
})
this.tray = new Tray(icon)
this.tray.setContextMenu(this.build())
this.build()
}
}
}

View File

@ -1621,11 +1621,21 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21"
integrity sha512-1z8k4wzFnNjVK/tlxvrWuK5WMt6mydWWP7+zvH5eFep4oj+UkrfiJTRtjCeBXNpwaA/FYqqtb4/QS4ianFpIRA==
"@types/node@*", "@types/node@^14.6.2":
"@types/ms@^0.7.31":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==
"@types/node@*":
version "14.14.37"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.37.tgz#a3dd8da4eb84a996c36e331df98d82abd76b516e"
integrity sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==
"@types/node@^14.6.2":
version "14.14.43"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.43.tgz#26bcbb0595b305400e8ceaf9a127a7f905ae49c8"
integrity sha512-3pwDJjp1PWacPTpH0LcfhgjvurQvrZFBrC6xxjaUEZ7ifUtT32jtjPxEMMblpqd2Mvx+k8haqQJLQxolyGN/cQ==
"@types/plist@^3.0.1":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/plist/-/plist-3.0.2.tgz#61b3727bba0f5c462fe333542534a0c3e19ccb01"
@ -1651,7 +1661,7 @@
dependencies:
"@types/react" "*"
"@types/react@*", "@types/react@^17.0.3":
"@types/react@*":
version "17.0.3"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.3.tgz#ba6e215368501ac3826951eef2904574c262cc79"
integrity sha512-wYOUxIgs2HZZ0ACNiIayItyluADNbONl7kt8lkLjVK8IitMH5QMyAh75Fwhmo37r1m7L2JaFj03sIfxBVDvRAg==
@ -1660,15 +1670,24 @@
"@types/scheduler" "*"
csstype "^3.0.2"
"@types/react@^17.0.3":
version "17.0.4"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.4.tgz#a67c6f7a460d2660e950d9ccc1c2f18525c28220"
integrity sha512-onz2BqScSFMoTRdJUZUDD/7xrusM8hBA2Fktk2qgaTYPCgPvWnDEgkrOs8hhPUf2jfcIXkJ5yK6VfYormJS3Jw==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"
"@types/scheduler@*":
version "0.16.1"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==
"@types/semver@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb"
integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ==
version "7.3.5"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.5.tgz#74deebbbcb1e86634dbf10a5b5e8798626f5a597"
integrity sha512-iotVxtCCsPLRAvxMFFgxL8HD2l4mAZ2Oin7/VJ2ooWO0VOK4EGOGmZWZn1uCq7RofR3I/1IOSjCHlFT71eVK0Q==
"@types/verror@^1.10.3":
version "1.10.4"
@ -2722,11 +2741,16 @@ core-js-compat@^3.8.1, core-js-compat@^3.9.0:
browserslist "^4.16.3"
semver "7.0.0"
core-js@^3.2.1, core-js@^3.6.5:
core-js@^3.2.1:
version "3.10.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.10.0.tgz#9a020547c8b6879f929306949e31496bbe2ae9b3"
integrity sha512-MQx/7TLgmmDVamSyfE+O+5BHvG1aUGj/gHhLn1wVtm2B5u1eVIPvh7vkfjwWKNCjrTJB8+He99IntSQ1qP+vYQ==
core-js@^3.6.5:
version "3.11.2"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.11.2.tgz#af087a43373fc6e72942917c4a4c3de43ed574d6"
integrity sha512-3tfrrO1JpJSYGKnd9LKTBPqgUES/UYiCzMKeqwR1+jF16q4kD1BY2NvqkfuzXwQ6+CIWm55V9cjD7PQd+hijdw==
core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -2984,9 +3008,9 @@ cssstyle@^1.1.1:
cssom "0.3.x"
csstype@^3.0.2:
version "3.0.7"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.7.tgz#2a5fb75e1015e84dd15692f71e89a1450290950b"
integrity sha512-KxnUB0ZMlnUWCsx2Z8MUsr6qV6ja1w9ArPErJaJaF8a5SOWoHLIszeCTKGRGRgtLgYrs1E8CHkNSP1VZTTPc9g==
version "3.0.8"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==
dashdash@^1.12.0:
version "1.14.1"
@ -3336,9 +3360,9 @@ electron-builder@^22.10.5:
yargs "^16.2.0"
electron-log@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.2.tgz#213334c69f0498fac677a7a73eae4a61fb69949e"
integrity sha512-PJPWE8JDzQ137UlxX9K917nI8GTcwgiJpE2PMPXZo+I6C4AaZU+JWQ3lW5NjQ1Lg8Qk8qbze+Ly0yAiqhbmpeA==
version "4.3.5"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.5.tgz#2aad5f93842b9b5214a1b4a10e47b5ac5c9ec104"
integrity sha512-J5Ew3axdk7W4jzzxKLSAi1sqbcAoo9CzHuBVsG0tT47j256xKulNrWFf3lZmHJ1KDXOQUcuwOngQF0jjmpEdpw==
electron-publish@22.10.5:
version "22.10.5"
@ -3355,9 +3379,9 @@ electron-publish@22.10.5:
mime "^2.5.0"
electron-store@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/electron-store/-/electron-store-7.0.2.tgz#e45a54d092ea43e2a953619ed4473893d448dfdf"
integrity sha512-tSUeHF9qdiPirph8JKJvIIcdVb3wYwgHUJCE38SJq4L08Op2z1+u8DSQ42Nvx34TKvb2lkQkByV0tHh6xBxdEQ==
version "7.0.3"
resolved "https://registry.yarnpkg.com/electron-store/-/electron-store-7.0.3.tgz#56d78284454018ed50ffc7645da49f828ae5ff19"
integrity sha512-wIbw4GHt4djs4dVrlRLCD/SpdpDUiRsQc212jagGA6zJ8xt1iwx3KZIzXY8gmwvgVCOcVxi3iyCXZoBBWwBXpQ==
dependencies:
conf "^9.0.0"
type-fest "^0.20.2"
@ -3368,9 +3392,9 @@ electron-to-chromium@^1.3.649:
integrity sha512-BqddgxNPrcWnbDdJw7SzXVzPmp+oiyjVrc7tkQVaznPGSS9SKZatw6qxoP857M+HbOyyqJQwYQtsuFIMSTNSZA==
electron@^12.0.0:
version "12.0.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.0.2.tgz#d92be205f1937627bd6718aad44ac161382b4c2d"
integrity sha512-14luh9mGzfL4e0sncyy0+kW37IU7Y0Y1tvI97FDRSW0ZBQxi5cmAwSs5dmPmNBFBIGtzkaGaEB01j9RjZuCmow==
version "12.0.6"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.0.6.tgz#2d72fa5a7db553dca3a771b22aa13a676122b4af"
integrity sha512-+fqhpdG6Fd6LzsizMdaSPC1I8tfsMT8/7fsYBgABED3hEWdus/rt6CQ54P3/EWZyQebtyHR6HXtlofUqKMV3KQ==
dependencies:
"@electron/get" "^1.0.1"
"@types/node" "^14.6.2"
@ -5157,6 +5181,11 @@ ms@2.1.2:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
nanoid@^3.1.22:
version "3.1.22"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.22.tgz#b35f8fb7d151990a8aebd5aa5015c03cf726f844"