Skip to content

Commit

Permalink
Use unique type names
Browse files Browse the repository at this point in the history
Fixes load errors when multiple extensions register the same type name
in their preferences, and "AboutPage" is sufficiently generic to trigger
this issue.
  • Loading branch information
swsnr committed Apr 2, 2024
1 parent bc709de commit 4325d3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface SourcesPageProperties {

const SourcesPage = GObject.registerClass(
{
GTypeName: "SourcesPage",
GTypeName: "PictureOfTheDaySourcesPage",
Template: getTemplate("SourcesPage"),
InternalChildren: [
"apodGroup",
Expand All @@ -96,22 +96,22 @@ const SourcesPage = GObject.registerClass(
"resetDownloadFolder",
],
},
class SourcesPage extends Adw.PreferencesPage {
class PictureOfTheDaySourcesPage extends Adw.PreferencesPage {
constructor(private readonly settings: AllSettings) {
super();
(this as unknown as SourcesPage & SourcesPageProperties).initialize();
(this as unknown as PictureOfTheDaySourcesPage & SourcesPageProperties).initialize();
}

private showSelectedSource(
this: SourcesPage & SourcesPageProperties,
this: PictureOfTheDaySourcesPage & SourcesPageProperties,
source: SourceMetadata,
): void {
this._sourcesRow.set_subtitle(
`<a href="${source.website}">${source.name}</a>`,
);
}

private showDownloadFolder(this: SourcesPage & SourcesPageProperties) {
private showDownloadFolder(this: PictureOfTheDaySourcesPage & SourcesPageProperties) {
const downloadDirectory = this.settings.extension
.get_value("image-download-folder")
.deepUnpack<string | null>();
Expand All @@ -121,7 +121,7 @@ const SourcesPage = GObject.registerClass(
}

private async selectDownloadDirectory(
this: SourcesPage & SourcesPageProperties,
this: PictureOfTheDaySourcesPage & SourcesPageProperties,
): Promise<void> {
// ts-for-gir doesn't recognize "select_folder" as async function, so we
// have to convince typescript explicitly that we have a promise here.
Expand All @@ -142,7 +142,7 @@ const SourcesPage = GObject.registerClass(
this.settings.extension.set_value("image-download-folder", value);
}

private initialize(this: SourcesPage & SourcesPageProperties): void {
private initialize(this: PictureOfTheDaySourcesPage & SourcesPageProperties): void {
// Fill the expander with all sources
const buttons = new Map(
SOURCES.map((source) => {
Expand Down Expand Up @@ -244,7 +244,7 @@ interface AboutPageChildren {

const AboutPage = GObject.registerClass(
{
GTypeName: "AboutPage",
GTypeName: "PictureOfTheDayAboutPage",
Template: getTemplate("AboutPage"),
InternalChildren: [
"extensionName",
Expand All @@ -254,7 +254,7 @@ const AboutPage = GObject.registerClass(
"extensionLicense",
],
},
class AboutPage extends Adw.PreferencesPage {
class PictureOfTheDayAboutPage extends Adw.PreferencesPage {
constructor(metadata: ExtensionMetadata) {
super();

Expand Down
2 changes: 1 addition & 1 deletion ui/AboutPage.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="[email protected]">
<requires lib="gtk" version="4.0"/>
<template class="AboutPage" parent="AdwPreferencesPage">
<template class="PictureOfTheDayAboutPage" parent="AdwPreferencesPage">
<property name="title" translatable="true">About</property>
<property name="icon-name">dialog-information-symbolic</property>
<child>
Expand Down
2 changes: 1 addition & 1 deletion ui/SourcesPage.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="[email protected]">
<requires lib="gtk" version="4.0"/>
<template class="SourcesPage" parent="AdwPreferencesPage">
<template class="PictureOfTheDaySourcesPage" parent="AdwPreferencesPage">
<property name="title" translatable="true">Picture Sources</property>
<property name="description" translatable="true">Configure sources for the Picture of the Day.</property>
<property name="icon-name">picture-of-the-day-symbolic</property>
Expand Down

0 comments on commit 4325d3d

Please sign in to comment.