mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 02:24:18 +00:00
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import { constants } from 'node:os'
|
|
|
|
import { SIGNALS } from './core.js'
|
|
import { getRealtimeSignals } from './realtime.js'
|
|
|
|
// Retrieve list of know signals (including realtime) with information about
|
|
// them
|
|
export const getSignals = () => {
|
|
const realtimeSignals = getRealtimeSignals()
|
|
const signals = [...SIGNALS, ...realtimeSignals].map(normalizeSignal)
|
|
return signals
|
|
}
|
|
|
|
// Normalize signal:
|
|
// - `number`: signal numbers are OS-specific. This is taken into account by
|
|
// `os.constants.signals`. However we provide a default `number` since some
|
|
// signals are not defined for some OS.
|
|
// - `forced`: set default to `false`
|
|
// - `supported`: set value
|
|
const normalizeSignal = ({
|
|
name,
|
|
number: defaultNumber,
|
|
description,
|
|
action,
|
|
forced = false,
|
|
standard,
|
|
}) => {
|
|
const {
|
|
signals: { [name]: constantSignal },
|
|
} = constants
|
|
const supported = constantSignal !== undefined
|
|
const number = supported ? constantSignal : defaultNumber
|
|
return { name, number, description, supported, action, forced, standard }
|
|
}
|