mirror of
https://github.com/cupcakearmy/unpixel.git
synced 2024-12-22 08:06:33 +00:00
util class to check active mic
This commit is contained in:
parent
622bfc914e
commit
14ac96366e
@ -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) => {
|
||||||
|
@ -1,28 +1,25 @@
|
|||||||
import cp from 'child_process'
|
import cp from 'child_process'
|
||||||
|
import { promisify } from 'util'
|
||||||
|
|
||||||
import Settings from './settings'
|
import Settings from './settings'
|
||||||
|
|
||||||
|
const exec = promisify(cp.exec)
|
||||||
|
|
||||||
export async function isCameraActive(): Promise<boolean> {
|
export async function isCameraActive(): Promise<boolean> {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
return new Promise((resolve) => {
|
// Check number of processes using the camera
|
||||||
// Check number of processes using the camera
|
const out = await exec(`lsof -n | grep "AppleCamera"`)
|
||||||
cp.exec(`lsof -n | grep "AppleCamera"`, (_, out) => {
|
const processesUsingCamera = out.stdout.trim().split('\n').length
|
||||||
const processesUsingCamera = out.trim().split('\n').length
|
return processesUsingCamera > 1 // One is the apple daemon that is always active
|
||||||
resolve(processesUsingCamera > 1) // One is the apple daemon that is always active
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isMicrophoneActive(): Promise<boolean> {
|
export async function isMicrophoneActive(): Promise<boolean> {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
return new Promise((resolve) => {
|
const out = await exec(`ioreg -c AppleHDAEngineInput | grep "IOAudioEngineState"`)
|
||||||
cp.exec(`ioreg -c AppleHDAEngineInput | grep IOAudioEngineState`, (_, out) => {
|
const parsed = parseInt(out.stdout.trim().replace(/[^\d]/gim, ''))
|
||||||
const parsed = parseInt(out.trim().replace(/[^\d]/gim, ''))
|
return parsed > 0
|
||||||
resolve(parsed > 0)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -33,11 +30,14 @@ export class InputDevicesStatus {
|
|||||||
camera: 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) => (this.status.mic = result))
|
||||||
|
isCameraActive().then((result) => (this.status.camera = result))
|
||||||
|
}
|
||||||
|
|
||||||
static init() {
|
static init() {
|
||||||
setInterval(() => {
|
setInterval(this.update, 3000)
|
||||||
isMicrophoneActive().then((result) => (this.status.mic = result))
|
|
||||||
isCameraActive().then((result) => (this.status.camera = result))
|
|
||||||
}, 2000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static areCameraOrMicrophoneActive(): boolean {
|
static areCameraOrMicrophoneActive(): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user