Skip to content

Commit 624b686

Browse files
3v1n0mtwebster
authored andcommitted
overrides/Gio: Use Platform prefix for platform-only symbols
In previous versions of GLib, platform-specific symbols such as GUnixMountMonitor were mapped in the Gio namespace as Gio.UnixMountMonitor, while since commit 0565682 we create wrappers such as Gio.MountMonitor. This is not correct, and does not serve the initial purpose of providing a backward compatible wrapper. So, use the same logic that we had before: if the GType of a symbol starts with G{Unix,Win32} we use the platform specific name as prefix of the wrapper type, so that it will be Gio.{Unix,Win32}TypeName
1 parent 894b8f9 commit 624b686

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

modules/core/overrides/Gio.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,23 +496,30 @@ function _init() {
496496
} catch {}
497497
}
498498

499+
const platformName = `${GioPlatform?.__name__?.slice(3 /* 'Gio'.length */)}`;
499500
Object.entries(Object.getOwnPropertyDescriptors(GioPlatform)).forEach(([prop, desc]) => {
500-
if (Object.hasOwn(Gio, prop)) {
501-
console.debug(`Gio already contains property ${prop}`);
502-
Gio[prop] = GioPlatform[prop];
501+
let genericProp = prop;
502+
503+
const originalValue = GioPlatform[prop];
504+
const gtypeName = originalValue.$gtype?.name;
505+
if (gtypeName?.startsWith(`G${platformName}`))
506+
genericProp = `${platformName}${prop}`;
507+
508+
if (Object.hasOwn(Gio, genericProp)) {
509+
console.debug(`Gio already contains property ${genericProp}`);
510+
Gio[genericProp] = originalValue;
503511
return;
504512
}
505513

506-
const newDesc = {
514+
Object.defineProperty(Gio, genericProp, {
507515
enumerable: true,
508516
configurable: false,
509517
get() {
510518
warnDeprecatedOncePerCallsite(PLATFORM_SPECIFIC_TYPELIB,
511-
`Gio.${prop}`, `${GioPlatform.__name__}.${prop}`);
519+
`Gio.${genericProp}`, `${GioPlatform.__name__}.${prop}`);
512520
return desc.get?.() ?? desc.value;
513521
},
514-
};
515-
Object.defineProperty(Gio, prop, newDesc);
522+
});
516523
});
517524

518525
Gio.DBus = {

0 commit comments

Comments
 (0)