gnome-shell/js/misc/dbusErrors.js
Jonas Dreßler 75f86a6f60 screencastService: Propagate machine-parseable error types to gnome-shell
We'll be using hardware encoding for screencasts soon, so we'll likely see
more things go wrong in the future, including crashes of the whole
screencastService. To deal with this, we'll introduce logic to blocklist
certain recording pipelines in case of failure and also add some logic
to retry the recording automatically.

To allow for better messaging to the user in those failure cases, we want
to be aware in gnome-shell, what exactly the error in the recorder was.

So propagate the most common types of errors that can happen in the
ScreencastService to gnome-shell using the new DBusError module.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2976>
2024-02-11 11:32:19 +01:00

57 lines
1.5 KiB
JavaScript

import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
function camelcase(str) {
const words = str.toLowerCase().split('_');
return words.map(w => `${w.at(0).toUpperCase()}${w.substring(1)}`).join('');
}
function decamelcase(str) {
return str.replace(/(.)([A-Z])/g, '$1-$2');
}
function registerErrorDomain(domain, errorEnum, prefix = 'org.gnome.Shell') {
const domainName =
`shell-${decamelcase(domain).toLowerCase()}-error`;
const quark = GLib.quark_from_string(domainName);
for (const [name, code] of Object.entries(errorEnum)) {
Gio.dbus_error_register_error(quark,
code, `${prefix}.${domain}.Error.${camelcase(name)}`);
}
return quark;
}
export const ModalDialogError = {
UNKNOWN_TYPE: 0,
GRAB_FAILED: 1,
};
export const ModalDialogErrors =
registerErrorDomain('ModalDialog', ModalDialogError);
export const NotificationError = {
INVALID_APP: 0,
};
export const NotificationErrors =
registerErrorDomain('Notifications', NotificationError, 'org.gtk');
export const ExtensionError = {
INFO_DOWNLOAD_FAILED: 0,
DOWNLOAD_FAILED: 1,
EXTRACT_FAILED: 2,
ENABLE_FAILED: 3,
};
export const ExtensionErrors =
registerErrorDomain('Extensions', ExtensionError);
export const ScreencastError = {
ALL_PIPELINES_FAILED: 0,
PIPELINE_ERROR: 1,
SAVE_TO_DISK_DISABLED: 2,
ALREADY_RECORDING: 3,
RECORDER_ERROR: 4,
SERVICE_CRASH: 5,
};
export const ScreencastErrors =
registerErrorDomain('Screencast', ScreencastError);