Compare commits
43 Commits
Author | SHA1 | Date |
---|---|---|
cupcakearmy | d1485e18ee | |
cupcakearmy | caa7a35aef | |
Nicco | 22f704e41d | |
cupcakearmy | e9cd600fd7 | |
cupcakearmy | 6f365fb9f6 | |
cupcakearmy | 791cc57177 | |
cupcakearmy | d7b5b6b73e | |
cupcakearmy | 7eddb6a592 | |
cupcakearmy | 9333af5369 | |
cupcakearmy | 62a8999f47 | |
cupcakearmy | 69da7b2364 | |
cupcakearmy | 9e5eaf1b3d | |
cupcakearmy | aa56ad6ce7 | |
cupcakearmy | dc03c1b1ce | |
cupcakearmy | 893c0fcc5c | |
cupcakearmy | 1b691949a3 | |
cupcakearmy | 14ac96366e | |
cupcakearmy | 622bfc914e | |
cupcakearmy | 1b48709a1d | |
cupcakearmy | 8398dccac3 | |
cupcakearmy | 82142ccb14 | |
cupcakearmy | 8854566336 | |
cupcakearmy | 447726e6cc | |
cupcakearmy | beb5572fb7 | |
cupcakearmy | 99a70c662f | |
cupcakearmy | 49afc7fccd | |
cupcakearmy | f1c0ab6dbb | |
cupcakearmy | 53c16e7063 | |
cupcakearmy | 2606214e53 | |
cupcakearmy | f5ecebb61a | |
cupcakearmy | 3129030d00 | |
cupcakearmy | e237eefc94 | |
cupcakearmy | 48cd3f1905 | |
Nicco | 27ec42fecd | |
cupcakearmy | 604f021ce2 | |
cupcakearmy | 6e5cb4ef4f | |
cupcakearmy | 0434d3dc55 | |
cupcakearmy | 1856024419 | |
cupcakearmy | 6fba47a4f8 | |
dependabot[bot] | 41f1cd691a | |
cupcakearmy | 928b69b4fb | |
cupcakearmy | b17f5db58e | |
Nicco | 064287c34f |
|
@ -2,8 +2,8 @@ name: Main
|
|||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
@ -13,10 +13,13 @@ jobs:
|
|||
uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
node-version: "14"
|
||||
- name: PNPM
|
||||
run: npm i -g pnpm
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Build
|
||||
run: yarn run dist
|
||||
run: pnpm run dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
EP_PRE_RELEASE: true
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.3.2] - 2022-01-21
|
||||
|
||||
### Changed
|
||||
|
||||
- Moved to pnpm
|
||||
|
||||
### Security
|
||||
|
||||
- Updated all dependencies.
|
||||
|
||||
## [1.3.1] - 2021-06-17
|
||||
|
||||
### Fixed
|
||||
|
||||
- Pause on Mic/Camera was not working correctly.
|
||||
|
||||
## [1.3.0] - 2021-06-10
|
||||
|
||||
### Added
|
||||
|
||||
- [macOS] Pause on Mic/Camera.
|
||||
|
||||
## [1.2.0] - 2021-06-01
|
||||
|
||||
### Added
|
||||
|
||||
- Progress bar.
|
||||
|
||||
## [1.1.2] - 2021-05-31
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bug with update window when banner is currently open.
|
||||
|
||||
## [1.1.1] - 2021-05-28
|
||||
|
||||
### Added
|
||||
|
||||
- Restore focus to previous window when closing banner.
|
||||
- Responsive image.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Settings page not opening.
|
||||
|
||||
## [1.1.0] - 2021-05-15
|
||||
|
||||
### Added
|
||||
|
||||
- Only pause for a limited time.
|
||||
- Volume slider for the sound.
|
21
README.md
21
README.md
|
@ -14,6 +14,25 @@ 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).
|
||||
|
||||
## 📦 Install
|
||||
## 💻 Installation
|
||||
|
||||
Head to the [release page](https://github.com/cupcakearmy/unpixel/releases) and grab the latest for your platform.
|
||||
|
||||
- For `macOS` you can downlaod the `.dmg` image.
|
||||
- For `Windows` download the `.exe`.
|
||||
- For `Linux` either the `.AppImage` or `.deb`, you will know what fits you 😉.
|
||||
|
||||
## 🛠 Building / Development
|
||||
|
||||
1. Clone the repo
|
||||
2. `pnpm install`
|
||||
3. `pnpm dist` to build for all platforms
|
||||
|
||||
Alternatively you can run `pnpm build` and the `pnpm electron-builder -m` for `macOS`, `-l` fir `linux` or `-w` for `windows`.
|
||||
|
||||
## 📦 Release
|
||||
|
||||
1. Bump version in `package.json`
|
||||
2. Update `CHANGELOG.md`
|
||||
3. Create a draft release with the new version. (e.g. tag with `v1.2.3`).
|
||||
4. Start the publish action and the ci will build and upload assets to the draft matching the version of `package.json` and draft.
|
||||
|
|
BIN
assets/tray.png
BIN
assets/tray.png
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 16 KiB |
48
package.json
48
package.json
|
@ -11,19 +11,25 @@
|
|||
"repository": {
|
||||
"url": "https://github.com/cupcakearmy/unpixel"
|
||||
},
|
||||
"version": "1.0.3",
|
||||
"version": "1.3.2",
|
||||
"main": "./dist/back/index.js",
|
||||
"engines": {
|
||||
"node": "14",
|
||||
"npm": "please-use-pnpm",
|
||||
"yarn": "please-use-pnpm"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"watch:front": "parcel watch --target front --no-hmr --no-cache ./src/front/banner/index.html ./src/front/settings/index.html",
|
||||
"watch:back": "parcel watch --target back --no-hmr --no-cache ./src/back/index.ts",
|
||||
"watch:front": "parcel watch --target front --no-hmr ./src/front/*/index.html",
|
||||
"watch:back": "parcel watch --target back --no-hmr ./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",
|
||||
"pack:dev": "electron-builder -m",
|
||||
"dist": "rm -rf .parcel-cache dist && run-s build pack"
|
||||
"pack:dev": "electron-builder -m dir && open ./out/mac/UnPixel.app",
|
||||
"dist": "run-s clean build pack",
|
||||
"clean": "rm -rf .parcel-cache dist out"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 2 Chrome versions"
|
||||
|
@ -41,10 +47,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"auto-launch": "^5.0.5",
|
||||
"axios": "^0.21.1",
|
||||
"dayjs": "^1.10.4",
|
||||
"electron-log": "^4.3.2",
|
||||
"electron-store": "^7.0.2",
|
||||
"axios": "^0.25.0",
|
||||
"dayjs": "^1.10.7",
|
||||
"electron-log": "^4.4.5",
|
||||
"electron-store": "^8.0.1",
|
||||
"ms": "^2.1.3",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"semver": "^7.3.5",
|
||||
|
@ -52,16 +59,17 @@
|
|||
"tachyons": "^4.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.0.0-0",
|
||||
"@types/auto-launch": "^5.0.1",
|
||||
"@types/react": "^17.0.3",
|
||||
"@types/react-dom": "^17.0.3",
|
||||
"@types/semver": "^7.3.4",
|
||||
"electron": "^12.0.0",
|
||||
"electron-builder": "^22.10.5",
|
||||
"@babel/core": "^7.16.10",
|
||||
"@types/auto-launch": "^5.0.2",
|
||||
"@types/ms": "^0.7.31",
|
||||
"@types/react": "^17.0.38",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/semver": "^7.3.9",
|
||||
"electron": "^11.5.0",
|
||||
"electron-builder": "^22.14.5",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"parcel": "next",
|
||||
"postcss": "^8.2.9",
|
||||
"typescript": "^4.2.3"
|
||||
"parcel": "^2.2.1",
|
||||
"postcss": "^8.4.5",
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,11 @@
|
|||
import { join } from 'path'
|
||||
import os from 'os'
|
||||
import { BrowserWindow, BrowserWindowConstructorOptions, ipcMain } from 'electron'
|
||||
import dayjs from 'dayjs'
|
||||
import logger from 'electron-log'
|
||||
import { app, BrowserWindow, BrowserWindowConstructorOptions, ipcMain } from 'electron'
|
||||
|
||||
import { DEV } from '.'
|
||||
import Settings from './settings'
|
||||
import TrayUtility from './tray'
|
||||
import { InputDevicesStatus } from './utils'
|
||||
|
||||
export default class Banner {
|
||||
static interval: ReturnType<typeof setInterval>
|
||||
|
@ -15,32 +14,27 @@ 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
|
||||
}
|
||||
static shouldShow(): boolean {
|
||||
const [paused, interval] = Settings.getStatus()
|
||||
if (paused || interval > 1000) return false
|
||||
if (InputDevicesStatus.areCameraOrMicrophoneActive()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
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) {
|
||||
Banner.open()
|
||||
}
|
||||
static check() {
|
||||
TrayUtility.build()
|
||||
if (Banner.shouldShow()) Banner.open()
|
||||
}
|
||||
|
||||
static open() {
|
||||
if (this.window) return
|
||||
|
||||
logger.debug('Showing banner')
|
||||
const options: BrowserWindowConstructorOptions = {
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
|
@ -49,7 +43,8 @@ export default class Banner {
|
|||
},
|
||||
width: 1200,
|
||||
height: 600,
|
||||
fullscreen: !DEV,
|
||||
fullscreen: true,
|
||||
simpleFullscreen: os.platform() === 'darwin',
|
||||
}
|
||||
this.window = new BrowserWindow(options)
|
||||
|
||||
|
@ -59,17 +54,6 @@ export default class Banner {
|
|||
if (DEV) {
|
||||
this.window.webContents.toggleDevTools()
|
||||
} else {
|
||||
switch (os.platform()) {
|
||||
case 'win32':
|
||||
break
|
||||
case 'linux':
|
||||
break
|
||||
case 'darwin':
|
||||
this.window.setSimpleFullScreen(true)
|
||||
this.window.setFullScreenable(false)
|
||||
break
|
||||
}
|
||||
// this.window.maximize()
|
||||
this.window.setAlwaysOnTop(true, 'floating', 99)
|
||||
this.window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
||||
this.window.setMovable(false)
|
||||
|
@ -81,6 +65,9 @@ export default class Banner {
|
|||
static close() {
|
||||
if (this.window) {
|
||||
Settings.save('lastRun', Date.now())
|
||||
this.window.minimize()
|
||||
this.window.hide()
|
||||
if (process.platform === 'darwin') app.hide()
|
||||
this.window.close()
|
||||
this.window = null
|
||||
}
|
||||
|
|
|
@ -5,12 +5,15 @@ import TrayUtility from './tray'
|
|||
import Settings from './settings'
|
||||
import Banner from './banner'
|
||||
import Updater from './updater'
|
||||
import { InputDevicesStatus } from './utils'
|
||||
|
||||
export const DEV = !app.isPackaged
|
||||
|
||||
// Enforce single instance
|
||||
const isMain = app.requestSingleInstanceLock()
|
||||
if (!isMain) app.quit()
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
logger.warn('Another instance is already running. Exiting.')
|
||||
app.quit()
|
||||
}
|
||||
|
||||
// Disable gpu
|
||||
app.disableHardwareAcceleration()
|
||||
|
@ -27,6 +30,7 @@ app
|
|||
Settings.init()
|
||||
Banner.init()
|
||||
Updater.init()
|
||||
InputDevicesStatus.init()
|
||||
logger.log('Done')
|
||||
})
|
||||
.catch((e) => {
|
||||
|
|
|
@ -8,15 +8,18 @@ import { productName } from '../../package.json'
|
|||
const autoLaunch = new AutoLaunch({ name: productName, mac: { useLaunchAgent: true } })
|
||||
|
||||
import { DEV } from '.'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const store = new Store()
|
||||
const defaults = {
|
||||
every: 20,
|
||||
duration: 20,
|
||||
boot: true,
|
||||
paused: false,
|
||||
paused: 0,
|
||||
lastRun: 0,
|
||||
autoClose: false,
|
||||
volume: 100,
|
||||
skipOnCameraOrMic: true,
|
||||
}
|
||||
export type SettingKeys = keyof typeof defaults
|
||||
const IntNormalizer = (x: any) => parseInt(x)
|
||||
|
@ -26,8 +29,10 @@ const normalizers: Record<SettingKeys, (x: any) => any> = {
|
|||
duration: IntNormalizer,
|
||||
boot: BoolNormalizer,
|
||||
autoClose: BoolNormalizer,
|
||||
paused: BoolNormalizer,
|
||||
paused: IntNormalizer,
|
||||
lastRun: IntNormalizer,
|
||||
volume: IntNormalizer,
|
||||
skipOnCameraOrMic: BoolNormalizer,
|
||||
}
|
||||
|
||||
export default class Settings {
|
||||
|
@ -61,9 +66,9 @@ export default class Settings {
|
|||
|
||||
static open() {
|
||||
if (this.win) return
|
||||
Settings.win = new BrowserWindow({
|
||||
this.win = new BrowserWindow({
|
||||
width: 400,
|
||||
height: 575,
|
||||
height: 690,
|
||||
center: true,
|
||||
resizable: false,
|
||||
webPreferences: {
|
||||
|
@ -71,15 +76,29 @@ export default class Settings {
|
|||
contextIsolation: false,
|
||||
},
|
||||
})
|
||||
this.win.on('closed', () => (this.win = null))
|
||||
|
||||
const entry = join(__dirname, '../front/settings/index.html')
|
||||
Settings.win.loadFile(entry)
|
||||
Settings.win.setMenu(null)
|
||||
this.win.loadFile(entry)
|
||||
this.win.setMenu(null)
|
||||
|
||||
if (DEV) {
|
||||
Settings.win.setSize(800, 485)
|
||||
Settings.win.setResizable(true)
|
||||
Settings.win.webContents.openDevTools()
|
||||
this.win.setSize(800, 485)
|
||||
this.win.setResizable(true)
|
||||
this.win.webContents.openDevTools()
|
||||
}
|
||||
}
|
||||
|
||||
static getStatus(): [boolean, number] {
|
||||
const paused: number = this.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]
|
||||
}
|
||||
}
|
||||
|
|
101
src/back/tray.ts
101
src/back/tray.ts
|
@ -1,64 +1,73 @@
|
|||
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',
|
||||
}
|
||||
import { InputDevicesStatus } from './utils'
|
||||
|
||||
export default class TrayUtility {
|
||||
static menu: Parameters<typeof Menu['buildFromTemplate']>[0] = [
|
||||
{ label: 'Status', type: 'normal', enabled: false, id: Items.Status },
|
||||
{ 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
|
||||
|
||||
static setStatus(status: string) {
|
||||
this.menu[0].label = status
|
||||
this.tray?.setContextMenu(this.build())
|
||||
}
|
||||
static build() {
|
||||
const [paused, interval] = Settings.getStatus()
|
||||
let status = paused ? `Paused for: ${ms(interval)}` : `Next break: ${ms(interval)}`
|
||||
if (InputDevicesStatus.areCameraOrMicrophoneActive()) status = `Paused: Mic/Camera Active`
|
||||
|
||||
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 template: Parameters<typeof Menu['buildFromTemplate']>[0] = [
|
||||
{ label: status, type: 'normal', enabled: false },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Take a break now',
|
||||
type: 'normal',
|
||||
click: () => Banner.open(),
|
||||
},
|
||||
]
|
||||
|
||||
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()
|
||||
},
|
||||
}))
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
template.push(
|
||||
{ label: 'Settings', click: () => Settings.open() },
|
||||
{ type: 'separator' },
|
||||
{ label: 'Quit', role: 'quit' }
|
||||
)
|
||||
|
||||
const menu = Menu.buildFromTemplate(template)
|
||||
this.tray?.setContextMenu(menu)
|
||||
}
|
||||
|
||||
static init() {
|
||||
if (!this.tray) {
|
||||
const file = path.join(__dirname, '../../assets/tray.png')
|
||||
const icon = nativeImage.createFromPath(file).resize({
|
||||
width: 24,
|
||||
height: 24,
|
||||
})
|
||||
this.tray = new Tray(icon)
|
||||
this.tray.setContextMenu(this.build())
|
||||
const resized = nativeImage.createFromPath(file).resize({ width: 24, height: 24 })
|
||||
resized.setTemplateImage(true)
|
||||
resized.isMacTemplateImage = true
|
||||
this.tray = new Tray(resized)
|
||||
this.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import logger from 'electron-log'
|
|||
import { dialog, shell } from 'electron'
|
||||
|
||||
import pkg from '../../package.json'
|
||||
import Banner from './banner'
|
||||
|
||||
const current = semver.coerce(pkg.version)
|
||||
const url = 'https://api.github.com/repos/cupcakearmy/unpixel/tags'
|
||||
|
@ -25,7 +26,9 @@ export default class Updater {
|
|||
if (!current) throw new Error('Could not determine current version')
|
||||
if (semver.lt(current, latest)) {
|
||||
logger.info('New version available')
|
||||
Banner.close()
|
||||
dialog
|
||||
// @ts-ignore
|
||||
.showMessageBox(null, {
|
||||
title: 'Update available',
|
||||
message: 'A newer version is available, please download.',
|
||||
|
@ -35,7 +38,6 @@ export default class Updater {
|
|||
.then(({ response }) => {
|
||||
if (response === 0) {
|
||||
shell.openExternal('https://github.com/cupcakearmy/unpixel/releases')
|
||||
process.exit(0)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import cp from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
|
||||
import Settings from './settings'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export async function isCameraActive(): Promise<boolean> {
|
||||
// Not reliable
|
||||
if (process.platform === 'darwin') {
|
||||
// Check number of processes using the camera
|
||||
const out = await exec(`lsof -n | grep "AppleCamera"`)
|
||||
const processesUsingCamera = out.stdout.trim().split('\n').length
|
||||
return processesUsingCamera > 1 // One is the apple daemon that is always active
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function isMicrophoneActive(): Promise<boolean> {
|
||||
if (process.platform === 'darwin') {
|
||||
const out = await exec(`ioreg -c AppleHDAEngineInput | grep "IOAudioEngineState"`)
|
||||
const parsed = parseInt(out.stdout.trim().replace(/[^\d]/gim, ''))
|
||||
return parsed > 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export class InputDevicesStatus {
|
||||
static status = {
|
||||
mic: false,
|
||||
camera: false,
|
||||
}
|
||||
|
||||
static update() {
|
||||
// TODO: Update electron version as soon as issue is resolved https://github.com/electron/electron/issues/26143
|
||||
isMicrophoneActive().then((result) => (InputDevicesStatus.status.mic = result))
|
||||
isCameraActive().then((result) => (InputDevicesStatus.status.camera = result))
|
||||
}
|
||||
|
||||
static init() {
|
||||
setInterval(InputDevicesStatus.update, 2000)
|
||||
}
|
||||
|
||||
static areCameraOrMicrophoneActive(): boolean {
|
||||
if (Settings.load('skipOnCameraOrMic')) {
|
||||
return InputDevicesStatus.status.mic
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
@import 'tachyons/css/tachyons.css';
|
||||
@import '../../../node_modules/tachyons/css/tachyons.css';
|
||||
|
||||
body {
|
||||
background-color: #111;
|
||||
|
@ -19,11 +19,6 @@ main {
|
|||
align-items: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
border-bottom: 0.5em solid currentColor;
|
||||
padding-bottom: 0.15em;
|
||||
}
|
||||
|
||||
.countdown {
|
||||
font-size: min(8rem, 25vh);
|
||||
}
|
||||
|
@ -58,3 +53,16 @@ button {
|
|||
button:hover {
|
||||
background-color: #2c2cce;
|
||||
}
|
||||
|
||||
.progress {
|
||||
width: 100%;
|
||||
height: 3rem;
|
||||
border: 0.125rem solid currentColor;
|
||||
}
|
||||
|
||||
.progress > div {
|
||||
background-color: currentColor;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
transition: width ease-out 250ms;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<main></main>
|
||||
<script src="./index.tsx"></script>
|
||||
<script type="module" src="./index.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
console.log('test')
|
||||
|
||||
import { ipcRenderer } from 'electron'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { render } from 'react-dom'
|
||||
|
@ -32,6 +30,8 @@ const Banner: React.FC = () => {
|
|||
|
||||
const [done, setDone] = useState(false)
|
||||
const [auto, setAuto] = useState(false)
|
||||
const [progress, setProgress] = useState(100)
|
||||
const [max, setMax] = useState(0)
|
||||
const [countdown, setCountdown] = useState<null | number>(null)
|
||||
|
||||
const handler = useCallback(
|
||||
|
@ -52,21 +52,33 @@ const Banner: React.FC = () => {
|
|||
setTimeout(() => setCountdown(countdown - 1), 1000)
|
||||
} else {
|
||||
const audio = new Audio(chime)
|
||||
const volume = ipcRenderer.sendSync('load', { key: 'volume' })
|
||||
audio.volume = volume / 100
|
||||
audio.play()
|
||||
setDone(true)
|
||||
}
|
||||
}, [countdown])
|
||||
|
||||
useEffect(() => {
|
||||
if (countdown !== null) {
|
||||
setProgress((countdown / max) * 100)
|
||||
}
|
||||
}, [countdown, max])
|
||||
|
||||
useEffect(() => {
|
||||
const autoClose = ipcRenderer.sendSync('load', { key: 'autoClose' })
|
||||
setAuto(autoClose)
|
||||
const time = ipcRenderer.sendSync('load', { key: 'duration' })
|
||||
setCountdown(time)
|
||||
setMax(time)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="ma0 mb4">Look Away</h1>
|
||||
<h1 className="ma0 mb3">Look Away</h1>
|
||||
<div className="progress mb4">
|
||||
<div style={{ width: progress.toFixed(2) + '%' }} />
|
||||
</div>
|
||||
<div className="code countdown">{countdown}</div>
|
||||
<div className="tile message">
|
||||
Look at least <b>6 meters</b> away. <br />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
@import 'spectre.css/dist/spectre.min.css';
|
||||
@import 'tachyons/css/tachyons.min.css';
|
||||
@import '../../node_modules/spectre.css/dist/spectre.css';
|
||||
@import '../../node_modules/tachyons/css/tachyons.css';
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
|
||||
|
|
|
@ -6,6 +6,19 @@ const labels = {
|
|||
duration: ['For', 'seconds'],
|
||||
boot: ['Start on boot'],
|
||||
autoClose: ['Close window after countdown'],
|
||||
volume: ['Chime Volume'],
|
||||
skipOnCameraOrMic: ['Pause when Mic is active'],
|
||||
}
|
||||
|
||||
const ranges: Partial<Record<keyof typeof labels, [number, number]>> = {
|
||||
every: [1, 60],
|
||||
duration: [1, 60],
|
||||
volume: [0, 100],
|
||||
}
|
||||
|
||||
function getRange(key: keyof typeof labels): [number, number] {
|
||||
const range = ranges[key]
|
||||
return range || [0, 0]
|
||||
}
|
||||
|
||||
const Field: React.FC<{ setting: keyof typeof labels }> = ({ setting: key }) => {
|
||||
|
@ -39,8 +52,8 @@ const Field: React.FC<{ setting: keyof typeof labels }> = ({ setting: key }) =>
|
|||
className="mt0 mb3"
|
||||
type="range"
|
||||
id={key}
|
||||
min="1"
|
||||
max="60"
|
||||
min={getRange(key)[0]}
|
||||
max={getRange(key)[1]}
|
||||
step="1"
|
||||
value={value}
|
||||
onChange={(e) => setValue(parseInt(e.target.value))}
|
||||
|
|
|
@ -9,7 +9,7 @@ const Footer: React.FC = () => {
|
|||
<div className="flex justify-center items-center">
|
||||
<Link link="https://github.com/cupcakearmy" text="Github" />
|
||||
<div className="ph1"> - </div>
|
||||
<Link link="https://nicco.io/support" text="Support" />
|
||||
<Link link="https://nicco.io/support" text="Support / Donate" />
|
||||
</div>
|
||||
<div className="code o-20 mt1">
|
||||
<small>version: {version}</small>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import React from 'react'
|
||||
|
||||
import '../base.css'
|
||||
|
||||
import Field from './Field'
|
||||
|
||||
const Settings = () => {
|
||||
|
@ -12,8 +10,13 @@ const Settings = () => {
|
|||
<fieldset className="ma0 pa0">
|
||||
<Field setting="every" />
|
||||
<Field setting="duration" />
|
||||
<Field setting="volume" />
|
||||
<Field setting="autoClose" />
|
||||
<Field setting="boot" />
|
||||
<Field setting="skipOnCameraOrMic" />
|
||||
<small className="ml4" style={{ position: 'relative', top: '-0.5em' }}>
|
||||
experimental & only on <i>macOS</i>
|
||||
</small>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
<meta charset="UTF-8" />
|
||||
<title>Settings</title>
|
||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
|
||||
<link href="../base.css" rel="stylesheet" charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<main></main>
|
||||
<script src="./index.tsx"></script>
|
||||
<script type="module" src="./index.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import React from 'react'
|
||||
import { render } from 'react-dom'
|
||||
|
||||
import '../base.css'
|
||||
|
||||
import About from './About'
|
||||
import Settings from './Settings'
|
||||
import Footer from './Footer'
|
||||
|
|
Loading…
Reference in New Issue