dbusErrors: Don't generate enums
Generating the enums from a list of names means that developers have to deduce the names of enum members themselves. That's more important than a bit more convenience when adding a new enum, so instead spell out the exported enums, and use the enums directly when registering a domain. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3160>
This commit is contained in:
parent
5d1a0cc525
commit
ad27153bee
@ -1,53 +1,45 @@
|
|||||||
import GLib from 'gi://GLib';
|
import GLib from 'gi://GLib';
|
||||||
import Gio from 'gi://Gio';
|
import Gio from 'gi://Gio';
|
||||||
|
|
||||||
function decamelcase(str, sep) {
|
function camelcase(str) {
|
||||||
return str.replace(/(.)([A-Z])/g, `$1${sep}$2`);
|
const words = str.toLowerCase().split('_');
|
||||||
|
return words.map(w => `${w.at(0).toUpperCase()}${w.substring(1)}`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerErrorDomain(domain, errorNames, prefix = 'org.gnome.Shell') {
|
function decamelcase(str) {
|
||||||
|
return str.replace(/(.)([A-Z])/g, '$1-$2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerErrorDomain(domain, errorEnum, prefix = 'org.gnome.Shell') {
|
||||||
const domainName =
|
const domainName =
|
||||||
`shell-${decamelcase(domain, '-').toLowerCase()}-error`;
|
`shell-${decamelcase(domain).toLowerCase()}-error`;
|
||||||
const quark = GLib.quark_from_string(domainName);
|
const quark = GLib.quark_from_string(domainName);
|
||||||
|
|
||||||
for (const [code, name] of errorNames.entries()) {
|
for (const [name, code] of Object.entries(errorEnum)) {
|
||||||
Gio.dbus_error_register_error(quark,
|
Gio.dbus_error_register_error(quark,
|
||||||
code, `${prefix}.${domain}.Error.${name}`);
|
code, `${prefix}.${domain}.Error.${camelcase(name)}`);
|
||||||
}
|
}
|
||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createErrorEnum(errorNames) {
|
export const ModalDialogError = {
|
||||||
const obj = {};
|
UNKNOWN_TYPE: 0,
|
||||||
|
GRAB_FAILED: 1,
|
||||||
for (const [code, name] of errorNames.entries()) {
|
};
|
||||||
const propName = decamelcase(name, '_').toUpperCase();
|
|
||||||
obj[propName] = code;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
const modalDialogErrorNames = [
|
|
||||||
'UnknownType',
|
|
||||||
'GrabFailed',
|
|
||||||
];
|
|
||||||
export const ModalDialogErrors =
|
export const ModalDialogErrors =
|
||||||
registerErrorDomain('ModalDialog', modalDialogErrorNames);
|
registerErrorDomain('ModalDialog', ModalDialogError);
|
||||||
export const ModalDialogError = createErrorEnum(modalDialogErrorNames);
|
|
||||||
|
|
||||||
const notificationErrorNames = [
|
export const NotificationError = {
|
||||||
'InvalidApp',
|
INVALID_APP: 0,
|
||||||
];
|
};
|
||||||
export const NotificationErrors =
|
export const NotificationErrors =
|
||||||
registerErrorDomain('Notifications', notificationErrorNames, 'org.gtk');
|
registerErrorDomain('Notifications', NotificationError, 'org.gtk');
|
||||||
export const NotificationError = createErrorEnum(notificationErrorNames);
|
|
||||||
|
|
||||||
const extensionErrorNames = [
|
export const ExtensionError = {
|
||||||
'InfoDownloadFailed',
|
INFO_DOWNLOAD_FAILED: 0,
|
||||||
'DownloadFailed',
|
DOWNLOAD_FAILED: 1,
|
||||||
'ExtractFailed',
|
EXTRACT_FAILED: 2,
|
||||||
'EnableFailed',
|
ENABLE_FAILED: 3,
|
||||||
];
|
};
|
||||||
export const ExtensionErrors =
|
export const ExtensionErrors =
|
||||||
registerErrorDomain('Extensions', extensionErrorNames);
|
registerErrorDomain('Extensions', ExtensionError);
|
||||||
export const ExtensionError = createErrorEnum(extensionErrorNames);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user