add 'record-audio' permission

This commit is contained in:
MihailRis 2026-01-05 16:40:00 +03:00
parent 97d2623a06
commit b3ae6eb59a
6 changed files with 25 additions and 6 deletions

View file

@ -67,5 +67,8 @@ function on_open()
table.insert(devices, {value=name, text=name})
end
selectbox.options = devices
selectbox.value = audio.__get_input_info().device_specifier
local info = audio.__get_input_info()
if info then
selectbox.value = info.device_specifier
end
end

View file

@ -2,5 +2,6 @@
name = "default"
base_packs = ["base"]
permissions = [
"network"
"network",
"record-audio"
]

View file

@ -24,6 +24,7 @@ namespace {
std::vector<std::unique_ptr<Channel>> channels;
util::ObjectsKeeper objects_keeper {};
std::unique_ptr<InputDevice> input_device = nullptr;
static bool input_enabled = false;
}
Channel::Channel(std::string name) : name(std::move(name)) {
@ -152,7 +153,9 @@ public:
}
};
void audio::initialize(bool enabled, AudioSettings& settings) {
void audio::initialize(
bool enabled, bool inputEnabled, AudioSettings& settings
) {
enabled = enabled && settings.enabled.get();
if (enabled) {
logger.info() << "initializing ALAudio backend";
@ -182,7 +185,10 @@ void audio::initialize(bool enabled, AudioSettings& settings) {
}, true));
}
::input_device = backend->openInputDevice("", 44100, 1, 16);
if (inputEnabled) {
::input_device = backend->openInputDevice("", 44100, 1, 16);
::input_enabled = true;
}
if (::input_device) {
::input_device->startCapture();
}
@ -270,6 +276,10 @@ std::vector<std::string> audio::get_output_devices_names() {
void audio::set_input_device(const std::string& deviceName) {
logger.info() << "setting input device to " << deviceName;
if (!::input_enabled) {
logger.warning() << "unable to set input device due to project permissions";
return;
}
if (deviceName == audio::DEVICE_NONE) {
if (::input_device) {
::input_device->stopCapture();

View file

@ -402,7 +402,7 @@ namespace audio {
/// @brief Initialize audio system or use no audio mode
/// @param enabled try to initialize actual audio
void initialize(bool enabled, AudioSettings& settings);
void initialize(bool enabled, bool inputEnabled, AudioSettings& settings);
/// @brief Load audio file info and PCM data
/// @param file audio file

View file

@ -13,6 +13,7 @@ namespace scripting {
}
struct Permissions {
static inline std::string RECORD_AUDIO = "record-audio";
static inline std::string WRITE_TO_USER = "write-to-user";
static inline std::string NETWORK = "network";

View file

@ -160,7 +160,11 @@ void Engine::initialize(CoreParameters coreParameters) {
if (!params.headless) {
initializeClient();
}
audio::initialize(!params.headless, settings.audio);
audio::initialize(
!params.headless,
project->permissions.has(Permissions::RECORD_AUDIO),
settings.audio
);
if (settings.ui.language.get() == "auto") {
settings.ui.language.set(