volume setting for chime

This commit is contained in:
cupcakearmy 2021-05-15 16:53:27 +02:00
parent 6e5cb4ef4f
commit 604f021ce2
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
4 changed files with 20 additions and 6 deletions

View File

@ -8,7 +8,6 @@ import { productName } from '../../package.json'
const autoLaunch = new AutoLaunch({ name: productName, mac: { useLaunchAgent: true } }) const autoLaunch = new AutoLaunch({ name: productName, mac: { useLaunchAgent: true } })
import { DEV } from '.' import { DEV } from '.'
import ms from 'ms'
import dayjs from 'dayjs' import dayjs from 'dayjs'
const store = new Store() const store = new Store()
@ -19,6 +18,7 @@ const defaults = {
paused: 0, paused: 0,
lastRun: 0, lastRun: 0,
autoClose: false, autoClose: false,
volume: 100,
} }
export type SettingKeys = keyof typeof defaults export type SettingKeys = keyof typeof defaults
const IntNormalizer = (x: any) => parseInt(x) const IntNormalizer = (x: any) => parseInt(x)
@ -30,6 +30,7 @@ const normalizers: Record<SettingKeys, (x: any) => any> = {
autoClose: BoolNormalizer, autoClose: BoolNormalizer,
paused: IntNormalizer, paused: IntNormalizer,
lastRun: IntNormalizer, lastRun: IntNormalizer,
volume: IntNormalizer,
} }
export default class Settings { export default class Settings {
@ -65,7 +66,7 @@ export default class Settings {
if (this.win) return if (this.win) return
Settings.win = new BrowserWindow({ Settings.win = new BrowserWindow({
width: 400, width: 400,
height: 575, height: 630,
center: true, center: true,
resizable: false, resizable: false,
webPreferences: { webPreferences: {

View File

@ -1,5 +1,3 @@
console.log('test')
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import React, { useCallback, useEffect, useRef, useState } from 'react' import React, { useCallback, useEffect, useRef, useState } from 'react'
import { render } from 'react-dom' import { render } from 'react-dom'
@ -52,6 +50,8 @@ const Banner: React.FC = () => {
setTimeout(() => setCountdown(countdown - 1), 1000) setTimeout(() => setCountdown(countdown - 1), 1000)
} else { } else {
const audio = new Audio(chime) const audio = new Audio(chime)
const volume = ipcRenderer.sendSync('load', { key: 'volume' })
audio.volume = volume / 100
audio.play() audio.play()
setDone(true) setDone(true)
} }

View File

@ -6,6 +6,18 @@ const labels = {
duration: ['For', 'seconds'], duration: ['For', 'seconds'],
boot: ['Start on boot'], boot: ['Start on boot'],
autoClose: ['Close window after countdown'], autoClose: ['Close window after countdown'],
volume: ['Chime Volume'],
}
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 }) => { const Field: React.FC<{ setting: keyof typeof labels }> = ({ setting: key }) => {
@ -39,8 +51,8 @@ const Field: React.FC<{ setting: keyof typeof labels }> = ({ setting: key }) =>
className="mt0 mb3" className="mt0 mb3"
type="range" type="range"
id={key} id={key}
min="1" min={getRange(key)[0]}
max="60" max={getRange(key)[1]}
step="1" step="1"
value={value} value={value}
onChange={(e) => setValue(parseInt(e.target.value))} onChange={(e) => setValue(parseInt(e.target.value))}

View File

@ -12,6 +12,7 @@ const Settings = () => {
<fieldset className="ma0 pa0"> <fieldset className="ma0 pa0">
<Field setting="every" /> <Field setting="every" />
<Field setting="duration" /> <Field setting="duration" />
<Field setting="volume" />
<Field setting="autoClose" /> <Field setting="autoClose" />
<Field setting="boot" /> <Field setting="boot" />
</fieldset> </fieldset>