17 Commits

Author SHA1 Message Date
893c0fcc5c fixes 2021-06-10 22:53:33 +02:00
1b691949a3 banner logic 2021-06-10 22:23:27 +02:00
14ac96366e util class to check active mic 2021-06-10 22:23:19 +02:00
622bfc914e settings height 2021-06-10 22:23:02 +02:00
1b48709a1d downgrade electorn version for big sure performance 2021-06-10 22:22:39 +02:00
8398dccac3 show paused on mic/camera 2021-06-09 12:13:11 +02:00
82142ccb14 utils class for input device monitoring 2021-06-09 12:12:58 +02:00
8854566336 add pause on mic/camera toggle 2021-06-09 12:12:36 +02:00
447726e6cc move css to html 2021-06-09 12:12:23 +02:00
beb5572fb7 update electron and version bump 2021-06-09 12:12:03 +02:00
99a70c662f progress bar 2021-06-01 10:38:41 +02:00
49afc7fccd bug with updater 2021-05-31 18:58:23 +02:00
f1c0ab6dbb restore focus to orignal window 2021-05-28 21:05:12 +02:00
53c16e7063 version bump 2021-05-28 20:56:43 +02:00
2606214e53 tray icon 2021-05-28 20:56:35 +02:00
f5ecebb61a fix settings open 2021-05-28 20:54:56 +02:00
3129030d00 releasing docs 2021-05-15 17:17:44 +02:00
18 changed files with 1350 additions and 2228 deletions

View File

@@ -2,9 +2,6 @@ name: Main
on: on:
workflow_dispatch: workflow_dispatch:
push:
tags:
- "v*.*.*"
jobs: jobs:
build: build:

View File

@@ -5,6 +5,35 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [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 ## [1.1.0] - 2021-05-15
### Added ### Added

View File

@@ -35,4 +35,4 @@ Alternatively you can run `yarn build` and the `yarn electron-builder -m` for `m
1. Bump version in `package.json` 1. Bump version in `package.json`
2. Update `CHANGELOG.md` 2. Update `CHANGELOG.md`
3. Create a draft release with the new version. (e.g. tag with `v1.2.3`). 3. Create a draft release with the new version. (e.g. tag with `v1.2.3`).
4. Push to `main` and github workflow will build and upload assets to the draft matching the version of `package.json` and draft. 4. Start the publish action and the ci will build and upload assets to the draft matching the version of `package.json` and draft.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -11,7 +11,7 @@
"repository": { "repository": {
"url": "https://github.com/cupcakearmy/unpixel" "url": "https://github.com/cupcakearmy/unpixel"
}, },
"version": "1.1.0", "version": "1.3.0",
"main": "./dist/back/index.js", "main": "./dist/back/index.js",
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",
@@ -23,7 +23,8 @@
"build": "run-s build:*", "build": "run-s build:*",
"pack": "electron-builder -mwl", "pack": "electron-builder -mwl",
"pack:dev": "electron-builder -m dir && open ./out/mac/UnPixel.app", "pack:dev": "electron-builder -m dir && open ./out/mac/UnPixel.app",
"dist": "rm -rf .parcel-cache dist && run-s build pack" "dist": "run-s clean build pack",
"clean": "rm -rf .parcel-cache dist out"
}, },
"browserslist": [ "browserslist": [
"last 2 Chrome versions" "last 2 Chrome versions"
@@ -59,10 +60,10 @@
"@types/react": "^17.0.3", "@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3", "@types/react-dom": "^17.0.3",
"@types/semver": "^7.3.4", "@types/semver": "^7.3.4",
"electron": "^12.0.0", "electron": "^11",
"electron-builder": "^22.10.5", "electron-builder": "^22.10.5",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"parcel": "next", "parcel": "^2.0.0-beta.3.1",
"postcss": "^8.2.10", "postcss": "^8.2.10",
"typescript": "^4.2.3" "typescript": "^4.2.3"
} }

View File

@@ -1,13 +1,11 @@
import { join } from 'path' import { join } from 'path'
import os from 'os' import os from 'os'
import { BrowserWindow, BrowserWindowConstructorOptions, ipcMain } from 'electron' import { app, BrowserWindow, BrowserWindowConstructorOptions, ipcMain } from 'electron'
import dayjs from 'dayjs'
import logger from 'electron-log'
import ms from 'ms'
import { DEV } from '.' import { DEV } from '.'
import Settings from './settings' import Settings from './settings'
import TrayUtility from './tray' import TrayUtility from './tray'
import { InputDevicesStatus } from './utils'
export default class Banner { export default class Banner {
static interval: ReturnType<typeof setInterval> static interval: ReturnType<typeof setInterval>
@@ -22,18 +20,21 @@ export default class Banner {
}) })
} }
static shouldShow(): boolean {
const [paused, interval] = Settings.getStatus()
if (paused || interval > 1000) return false
if (InputDevicesStatus.areCameraOrMicrophoneActive()) return true
return true
}
static check() { static check() {
TrayUtility.build() TrayUtility.build()
const [paused, interval] = Settings.getStatus() if (Banner.shouldShow()) Banner.open()
if (!paused && interval < 1000) {
Banner.open()
}
} }
static open() { static open() {
if (this.window) return if (this.window) return
logger.debug('Showing banner')
const options: BrowserWindowConstructorOptions = { const options: BrowserWindowConstructorOptions = {
frame: false, frame: false,
webPreferences: { webPreferences: {
@@ -64,6 +65,9 @@ export default class Banner {
static close() { static close() {
if (this.window) { if (this.window) {
Settings.save('lastRun', Date.now()) Settings.save('lastRun', Date.now())
this.window.minimize()
this.window.hide()
if (process.platform === 'darwin') app.hide()
this.window.close() this.window.close()
this.window = null this.window = null
} }

View File

@@ -5,6 +5,7 @@ import TrayUtility from './tray'
import Settings from './settings' import Settings from './settings'
import Banner from './banner' import Banner from './banner'
import Updater from './updater' import Updater from './updater'
import { InputDevicesStatus } from './utils'
export const DEV = !app.isPackaged export const DEV = !app.isPackaged
@@ -27,6 +28,7 @@ app
Settings.init() Settings.init()
Banner.init() Banner.init()
Updater.init() Updater.init()
InputDevicesStatus.init()
logger.log('Done') logger.log('Done')
}) })
.catch((e) => { .catch((e) => {

View File

@@ -19,6 +19,7 @@ const defaults = {
lastRun: 0, lastRun: 0,
autoClose: false, autoClose: false,
volume: 100, volume: 100,
skipOnCameraOrMic: true,
} }
export type SettingKeys = keyof typeof defaults export type SettingKeys = keyof typeof defaults
const IntNormalizer = (x: any) => parseInt(x) const IntNormalizer = (x: any) => parseInt(x)
@@ -31,6 +32,7 @@ const normalizers: Record<SettingKeys, (x: any) => any> = {
paused: IntNormalizer, paused: IntNormalizer,
lastRun: IntNormalizer, lastRun: IntNormalizer,
volume: IntNormalizer, volume: IntNormalizer,
skipOnCameraOrMic: BoolNormalizer,
} }
export default class Settings { export default class Settings {
@@ -64,9 +66,9 @@ export default class Settings {
static open() { static open() {
if (this.win) return if (this.win) return
Settings.win = new BrowserWindow({ this.win = new BrowserWindow({
width: 400, width: 400,
height: 630, height: 690,
center: true, center: true,
resizable: false, resizable: false,
webPreferences: { webPreferences: {
@@ -74,20 +76,21 @@ export default class Settings {
contextIsolation: false, contextIsolation: false,
}, },
}) })
this.win.on('closed', () => (this.win = null))
const entry = join(__dirname, '../front/settings/index.html') const entry = join(__dirname, '../front/settings/index.html')
Settings.win.loadFile(entry) this.win.loadFile(entry)
Settings.win.setMenu(null) this.win.setMenu(null)
if (DEV) { if (DEV) {
Settings.win.setSize(800, 485) this.win.setSize(800, 485)
Settings.win.setResizable(true) this.win.setResizable(true)
Settings.win.webContents.openDevTools() this.win.webContents.openDevTools()
} }
} }
static getStatus(): [boolean, number] { static getStatus(): [boolean, number] {
const paused: number = Settings.load('paused') const paused: number = this.load('paused')
const now = Date.now() const now = Date.now()
if (paused > now) { if (paused > now) {
return [true, paused - now] return [true, paused - now]

View File

@@ -4,13 +4,15 @@ import ms from 'ms'
import Banner from './banner' import Banner from './banner'
import Settings from './settings' import Settings from './settings'
import { InputDevicesStatus } from './utils'
export default class TrayUtility { export default class TrayUtility {
static tray: Tray | null = null static tray: Tray | null = null
static build() { static build() {
const [paused, interval] = Settings.getStatus() const [paused, interval] = Settings.getStatus()
const status = paused ? `Paused for: ${ms(interval)}` : `Next break: ${ms(interval)}` let status = paused ? `Paused for: ${ms(interval)}` : `Next break: ${ms(interval)}`
if (InputDevicesStatus.areCameraOrMicrophoneActive()) status = `Paused: Mic/Camera Active`
const template: Parameters<typeof Menu['buildFromTemplate']>[0] = [ const template: Parameters<typeof Menu['buildFromTemplate']>[0] = [
{ label: status, type: 'normal', enabled: false }, { label: status, type: 'normal', enabled: false },
@@ -61,11 +63,10 @@ export default class TrayUtility {
static init() { static init() {
if (!this.tray) { if (!this.tray) {
const file = path.join(__dirname, '../../assets/tray.png') const file = path.join(__dirname, '../../assets/tray.png')
const icon = nativeImage.createFromPath(file).resize({ const resized = nativeImage.createFromPath(file).resize({ width: 24, height: 24 })
width: 24, resized.setTemplateImage(true)
height: 24, resized.isMacTemplateImage = true
}) this.tray = new Tray(resized)
this.tray = new Tray(icon)
this.build() this.build()
} }
} }

View File

@@ -4,6 +4,7 @@ import logger from 'electron-log'
import { dialog, shell } from 'electron' import { dialog, shell } from 'electron'
import pkg from '../../package.json' import pkg from '../../package.json'
import Banner from './banner'
const current = semver.coerce(pkg.version) const current = semver.coerce(pkg.version)
const url = 'https://api.github.com/repos/cupcakearmy/unpixel/tags' 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 (!current) throw new Error('Could not determine current version')
if (semver.lt(current, latest)) { if (semver.lt(current, latest)) {
logger.info('New version available') logger.info('New version available')
Banner.close()
dialog dialog
// @ts-ignore
.showMessageBox(null, { .showMessageBox(null, {
title: 'Update available', title: 'Update available',
message: 'A newer version is available, please download.', message: 'A newer version is available, please download.',
@@ -35,7 +38,6 @@ export default class Updater {
.then(({ response }) => { .then(({ response }) => {
if (response === 0) { if (response === 0) {
shell.openExternal('https://github.com/cupcakearmy/unpixel/releases') shell.openExternal('https://github.com/cupcakearmy/unpixel/releases')
process.exit(0)
} }
}) })
} else { } else {

49
src/back/utils.ts Normal file
View File

@@ -0,0 +1,49 @@
import cp from 'child_process'
import { promisify } from 'util'
import Settings from './settings'
const exec = promisify(cp.exec)
export async function isCameraActive(): Promise<boolean> {
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 || InputDevicesStatus.status.camera
}
return false
}
}

View File

@@ -19,11 +19,6 @@ main {
align-items: center; align-items: center;
} }
h1 {
border-bottom: 0.5em solid currentColor;
padding-bottom: 0.15em;
}
.countdown { .countdown {
font-size: min(8rem, 25vh); font-size: min(8rem, 25vh);
} }
@@ -58,3 +53,16 @@ button {
button:hover { button:hover {
background-color: #2c2cce; 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;
}

View File

@@ -30,6 +30,8 @@ const Banner: React.FC = () => {
const [done, setDone] = useState(false) const [done, setDone] = useState(false)
const [auto, setAuto] = 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 [countdown, setCountdown] = useState<null | number>(null)
const handler = useCallback( const handler = useCallback(
@@ -57,16 +59,26 @@ const Banner: React.FC = () => {
} }
}, [countdown]) }, [countdown])
useEffect(() => {
if (countdown !== null) {
setProgress((countdown / max) * 100)
}
}, [countdown, max])
useEffect(() => { useEffect(() => {
const autoClose = ipcRenderer.sendSync('load', { key: 'autoClose' }) const autoClose = ipcRenderer.sendSync('load', { key: 'autoClose' })
setAuto(autoClose) setAuto(autoClose)
const time = ipcRenderer.sendSync('load', { key: 'duration' }) const time = ipcRenderer.sendSync('load', { key: 'duration' })
setCountdown(time) setCountdown(time)
setMax(time)
}, []) }, [])
return ( return (
<div> <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="code countdown">{countdown}</div>
<div className="tile message"> <div className="tile message">
Look at least <b>6 meters</b> away. <br /> Look at least <b>6 meters</b> away. <br />

View File

@@ -7,6 +7,7 @@ const labels = {
boot: ['Start on boot'], boot: ['Start on boot'],
autoClose: ['Close window after countdown'], autoClose: ['Close window after countdown'],
volume: ['Chime Volume'], volume: ['Chime Volume'],
skipOnCameraOrMic: ['Pause when Mic or Camera are active'],
} }
const ranges: Partial<Record<keyof typeof labels, [number, number]>> = { const ranges: Partial<Record<keyof typeof labels, [number, number]>> = {

View File

@@ -1,7 +1,5 @@
import React from 'react' import React from 'react'
import '../base.css'
import Field from './Field' import Field from './Field'
const Settings = () => { const Settings = () => {
@@ -15,6 +13,10 @@ const Settings = () => {
<Field setting="volume" /> <Field setting="volume" />
<Field setting="autoClose" /> <Field setting="autoClose" />
<Field setting="boot" /> <Field setting="boot" />
<Field setting="skipOnCameraOrMic" />
<small className="ml4" style={{ position: 'relative', top: '-0.5em' }}>
only on <i>macOS</i>
</small>
</fieldset> </fieldset>
</form> </form>
</div> </div>

View File

@@ -4,6 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Settings</title> <title>Settings</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" /> <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<link href="../base.css" rel="stylesheet" charset="utf-8" />
</head> </head>
<body> <body>
<main></main> <main></main>

View File

@@ -1,8 +1,6 @@
import React from 'react' import React from 'react'
import { render } from 'react-dom' import { render } from 'react-dom'
import '../base.css'
import About from './About' import About from './About'
import Settings from './Settings' import Settings from './Settings'
import Footer from './Footer' import Footer from './Footer'

3384
yarn.lock

File diff suppressed because it is too large Load Diff