1 Commits

Author SHA1 Message Date
aa3a3ea265 testing tray 2021-05-29 15:28:06 +02:00
24 changed files with 7798 additions and 5780 deletions

View File

@@ -1,9 +1,7 @@
name: Main name: Main
on: on:
push: workflow_dispatch:
tags:
- "v*.*.*"
jobs: jobs:
build: build:
@@ -14,12 +12,9 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: "14" node-version: "14"
- name: PNPM
run: npm i -g pnpm
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile run: yarn install --frozen-lockfile
- name: Build - name: Build
run: pnpm run dist run: yarn run dist
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EP_PRE_RELEASE: true

1
.npmrc
View File

@@ -1 +0,0 @@
engine-strict=true

View File

@@ -5,54 +5,20 @@ 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.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 ## [1.1.1] - 2021-05-28
### Added ### Added
- Restore focus to previous window when closing banner. - Restore focus to previous window when closing banner
- Responsive image. - Responsive image
### Fixed ### Fixed
- Settings page not opening. - Settings page not opening
## [1.1.0] - 2021-05-15 ## [1.1.0] - 2021-05-15
### Added ### Added
- Only pause for a limited time. - Only pause for a limited time
- Volume slider for the sound. - Volume slider for the sound

View File

@@ -25,10 +25,10 @@ Head to the [release page](https://github.com/cupcakearmy/unpixel/releases) and
## 🛠 Building / Development ## 🛠 Building / Development
1. Clone the repo 1. Clone the repo
2. `pnpm install` 2. `yarn install`
3. `pnpm dist` to build for all platforms 3. `yarn 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`. Alternatively you can run `yarn build` and the `yarn electron-builder -m` for `macOS`, `-l` fir `linux` or `-w` for `windows`.
## 📦 Release ## 📦 Release

BIN
assets/trayTemplate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
assets/trayTemplate@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
design/tray.afdesign LFS Normal file

Binary file not shown.

View File

@@ -11,25 +11,19 @@
"repository": { "repository": {
"url": "https://github.com/cupcakearmy/unpixel" "url": "https://github.com/cupcakearmy/unpixel"
}, },
"version": "1.3.2", "version": "1.1.1",
"main": "./dist/back/index.js", "main": "./dist/back/index.js",
"engines": {
"node": "14",
"npm": "please-use-pnpm",
"yarn": "please-use-pnpm"
},
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",
"watch:front": "parcel watch --target front --no-hmr ./src/front/*/index.html", "watch:front": "parcel watch --target front --no-hmr --no-cache ./src/front/*/index.html",
"watch:back": "parcel watch --target back --no-hmr ./src/back/index.ts", "watch:back": "parcel watch --target back --no-hmr --no-cache ./src/back/index.ts",
"dev": "run-p watch:*", "dev": "run-p watch:*",
"build:front": "parcel build --target front ./src/front/*/index.html", "build:front": "parcel build --target front ./src/front/*/index.html",
"build:back": "parcel build --target back ./src/back/index.ts", "build:back": "parcel build --target back ./src/back/index.ts",
"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": "run-s clean build pack", "dist": "rm -rf .parcel-cache dist && run-s build pack"
"clean": "rm -rf .parcel-cache dist out"
}, },
"browserslist": [ "browserslist": [
"last 2 Chrome versions" "last 2 Chrome versions"
@@ -47,10 +41,10 @@
}, },
"dependencies": { "dependencies": {
"auto-launch": "^5.0.5", "auto-launch": "^5.0.5",
"axios": "^0.25.0", "axios": "^0.21.1",
"dayjs": "^1.10.7", "dayjs": "^1.10.4",
"electron-log": "^4.4.5", "electron-log": "^4.3.2",
"electron-store": "^8.0.1", "electron-store": "^7.0.2",
"ms": "^2.1.3", "ms": "^2.1.3",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
@@ -59,17 +53,17 @@
"tachyons": "^4.12.0" "tachyons": "^4.12.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.16.10", "@babel/core": "^7.0.0-0",
"@types/auto-launch": "^5.0.2", "@types/auto-launch": "^5.0.1",
"@types/ms": "^0.7.31", "@types/ms": "^0.7.31",
"@types/react": "^17.0.38", "@types/react": "^17.0.3",
"@types/react-dom": "^17.0.11", "@types/react-dom": "^17.0.3",
"@types/semver": "^7.3.9", "@types/semver": "^7.3.4",
"electron": "^11.5.0", "electron": "^12.0.0",
"electron-builder": "^22.14.5", "electron-builder": "^22.10.5",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"parcel": "^2.2.1", "parcel": "next",
"postcss": "^8.4.5", "postcss": "^8.2.10",
"typescript": "^4.5.5" "typescript": "^4.2.3"
} }
} }

5589
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,13 @@
import { join } from 'path' import { join } from 'path'
import os from 'os' import os from 'os'
import { app, 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>
@@ -20,21 +22,18 @@ export default class Banner {
}) })
} }
static shouldShow(): boolean {
const [paused, interval] = Settings.getStatus()
if (paused || interval > 1000) return false
if (InputDevicesStatus.areCameraOrMicrophoneActive()) return false
return true
}
static check() { static check() {
TrayUtility.build() TrayUtility.build()
if (Banner.shouldShow()) Banner.open() const [paused, interval] = Settings.getStatus()
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: {

View File

@@ -5,15 +5,12 @@ 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
// Enforce single instance // Enforce single instance
if (!app.requestSingleInstanceLock()) { const isMain = app.requestSingleInstanceLock()
logger.warn('Another instance is already running. Exiting.') if (!isMain) app.quit()
app.quit()
}
// Disable gpu // Disable gpu
app.disableHardwareAcceleration() app.disableHardwareAcceleration()
@@ -30,7 +27,6 @@ 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,7 +19,6 @@ 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)
@@ -32,7 +31,6 @@ 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 {
@@ -68,7 +66,7 @@ export default class Settings {
if (this.win) return if (this.win) return
this.win = new BrowserWindow({ this.win = new BrowserWindow({
width: 400, width: 400,
height: 690, height: 630,
center: true, center: true,
resizable: false, resizable: false,
webPreferences: { webPreferences: {

View File

@@ -4,15 +4,13 @@ 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()
let status = paused ? `Paused for: ${ms(interval)}` : `Next break: ${ms(interval)}` const 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 },
@@ -62,11 +60,11 @@ 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/trayTemplate.png')
const resized = nativeImage.createFromPath(file).resize({ width: 24, height: 24 }) // const resized = nativeImage.createFromPath(file).resize({ width: 24, height: 24 })
resized.setTemplateImage(true) // resized.setTemplateImage(true)
resized.isMacTemplateImage = true // resized.isMacTemplateImage = true
this.tray = new Tray(resized) this.tray = new Tray(file)
this.build() this.build()
} }
} }

View File

@@ -4,7 +4,6 @@ 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'
@@ -26,9 +25,7 @@ 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.',
@@ -38,6 +35,7 @@ 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 {

View File

@@ -1,50 +0,0 @@
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
}
}

View File

@@ -1,4 +1,4 @@
@import '../../../node_modules/tachyons/css/tachyons.css'; @import 'tachyons/css/tachyons.css';
body { body {
background-color: #111; background-color: #111;
@@ -19,6 +19,11 @@ 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);
} }
@@ -53,16 +58,3 @@ 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

@@ -8,6 +8,6 @@
</head> </head>
<body> <body>
<main></main> <main></main>
<script type="module" src="./index.tsx"></script> <script src="./index.tsx"></script>
</body> </body>
</html> </html>

View File

@@ -30,8 +30,6 @@ 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(
@@ -59,26 +57,16 @@ 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 mb3">Look Away</h1> <h1 className="ma0 mb4">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

@@ -1,5 +1,5 @@
@import '../../node_modules/spectre.css/dist/spectre.css'; @import 'spectre.css/dist/spectre.min.css';
@import '../../node_modules/tachyons/css/tachyons.css'; @import 'tachyons/css/tachyons.min.css';
body { body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',

View File

@@ -7,7 +7,6 @@ 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 is active'],
} }
const ranges: Partial<Record<keyof typeof labels, [number, number]>> = { const ranges: Partial<Record<keyof typeof labels, [number, number]>> = {

View File

@@ -1,5 +1,7 @@
import React from 'react' import React from 'react'
import '../base.css'
import Field from './Field' import Field from './Field'
const Settings = () => { const Settings = () => {
@@ -13,10 +15,6 @@ 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' }}>
experimental & only on <i>macOS</i>
</small>
</fieldset> </fieldset>
</form> </form>
</div> </div>

View File

@@ -4,10 +4,9 @@
<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>
<script type="module" src="./index.tsx"></script> <script src="./index.tsx"></script>
</body> </body>
</html> </html>

View File

@@ -1,6 +1,8 @@
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'

7733
yarn.lock Normal file

File diff suppressed because it is too large Load Diff