Skip to content

Commit

Permalink
Update to GNOME Shell 46.0.2 types
Browse files Browse the repository at this point in the history
Does not build currently, as the 4.x types still suffer from
regressions, notably

- Missing promisified overloads: gjsify/ts-for-gir#171
- Missing GLib.Error.stack: gjsify/ts-for-gir#196
  • Loading branch information
swsnr committed Aug 30, 2024
1 parent 081afeb commit 0502a31
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 641 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"@girs/gjs": "^3.3.0",
"@girs/gnome-shell": "^46.0.0-beta6",
"@girs/soup-3.0": "^3.4.4-3.3.0",
"@girs/gjs": "4.0.0-beta.14",
"@girs/gnome-shell": "46.0.2",
"@girs/soup-3.0": "^3.4.4-4.0.0-beta.14",
"@tsconfig/strictest": "^2.0.5",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
1,176 changes: 598 additions & 578 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ const initializeExtension = (

// Wire up the current source
const currentSource = settings.get_string("selected-source");
if (currentSource === null) {
throw new Error("Current source 'null'?");
}
const sourceSelector = destroyer.add(SourceSelector.forKey(currentSource));
indicator.updateSelectedSource(sourceSelector.selectedSource.metadata);
const sourceSettings = SourceSettings.fromBaseSettings(extension, settings);
Expand Down
6 changes: 1 addition & 5 deletions src/lib/services/desktop-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ export class DesktopBackgroundService {
* @param image The image file to use as new background
*/
setBackgroundImageFile(image: Gio.File): void {
const uri = image.get_uri();
if (uri === null) {
throw new Error("Failed obtain URI from file");
}
this.backgroundImage = uri;
this.backgroundImage = image.get_uri();
}
}
14 changes: 4 additions & 10 deletions src/lib/services/image-metadata-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,9 @@ export class ImageMetadataStore {
* Store metadata for the given image.
*/
storedMetadataForImage(image: ImageFile) {
const uri = image.file.get_uri();
if (uri === null) {
throw new Error("Failed to get URI for current image, not storing!");
}
const stored: StoredMetadata = {
metadata: image.metadata,
uri: uri,
uri: image.file.get_uri(),
};
this.settings.set_string("current-metadata", JSON.stringify(stored));
}
Expand All @@ -87,11 +83,9 @@ export class ImageMetadataStore {
* @returns The stored image or null if no image was stored or the store was invalid
*/
loadFromMetadata(): ImageFile | null {
const storedRaw = this.settings.get_string("current-metadata");
if (storedRaw === null) {
return null;
}
const stored = parseStoredMetadata(storedRaw);
const stored = parseStoredMetadata(
this.settings.get_string("current-metadata"),
);
if (stored !== null) {
return {
metadata: stored.metadata,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/services/refresh-error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ export class RefreshErrorHandler
// If the inner error is a GLib error use its message instead of the wrapper message for better accuracy
// and locatization.
const errorMessage =
(error.cause instanceof GLib.Error
? error.cause.message
: error.message) ?? "";
error.cause instanceof GLib.Error ? error.cause.message : error.message;
notification.body = i18n.format(description, errorMessage);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/lib/source/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export class SourceSettings {
extension: Extension,
settings: Gio.Settings,
): SourceSettings {
const schemaId = settings.schemaId;
if (schemaId === null) {
throw new Error("Base settings have no schema ID!");
}
return new SourceSettings(extension, schemaId);
return new SourceSettings(extension, settings.schemaId);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sources/apod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const getImage = async (
cancellable: Gio.Cancellable,
): Promise<DownloadableImage> => {
const apiKey = settings.get_string("api-key");
if (apiKey === null || apiKey.length === 0) {
if (apiKey.length === 0) {
throw new InvalidAPIKeyError(metadata);
}

Expand Down
8 changes: 1 addition & 7 deletions src/lib/sources/bing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Soup from "gi://Soup";

import metadata from "./metadata/bing.js";
import { Source } from "../source/source.js";
import { HttpRequestError, getJSON } from "../network/http.js";
import { getJSON } from "../network/http.js";
import { DownloadableImage } from "../download.js";
import { decodeQuery, encodeQuery } from "../network/uri.js";

Expand Down Expand Up @@ -76,12 +76,6 @@ export const getTodaysImages = async (
urlbaseUHD,
GLib.UriFlags.NONE,
);
if (imageUrl === null) {
throw new HttpRequestError(
url,
`Failed to join ${urlbaseUHD} to https://www.bing.com`,
);
}
const startdate = image.startdate;
const suggestedFilename = decodeQuery(imageUrl)["id"];
return {
Expand Down
12 changes: 2 additions & 10 deletions src/lib/ui/error-detail-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ import { unfoldCauses } from "../common/error.js";
/**
* Shortcut for `GLib.markup_escape_text`.
*/
function e(s: string): string {
const escaped = GLib.markup_escape_text(s, -1);
if (escaped === null) {
// This can't happen I believe, because markup_escape_text would always return a string when given a string, but
// let's guard against it nonetheless.
throw new Error(`Failed to escape markup in ${s}`);
}
return escaped;
}
const e = (s: string): string => GLib.markup_escape_text(s, -1);

const formatStacktrace = (stack: string | undefined): string => {
return (
Expand Down Expand Up @@ -90,7 +82,7 @@ export const ErrorDetailDialog = GObject.registerClass(
class ErrorDetailDialog extends ModalDialog {
private readonly messageLabel: St.Label;

constructor(params?: ModalDialog.ConstructorProperties) {
constructor(params?: ModalDialog.ConstructorProps) {
super(params);

const contentBox = new St.BoxLayout({
Expand Down
18 changes: 2 additions & 16 deletions src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,12 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.`;

const getTemplate = (name: string): string => {
const uri = GLib.uri_resolve_relative(
const getTemplate = (name: string): string =>
GLib.uri_resolve_relative(
import.meta.url,
`ui/${name}.ui`,
GLib.UriFlags.NONE,
);
if (uri === null) {
throw new Error(`Failed to resolve URI for template ${name}!`);
}
return uri;
};

interface AllSettings {
readonly extension: Gio.Settings;
Expand Down Expand Up @@ -176,9 +171,6 @@ const SourcesPage = GObject.registerClass(
});

const selectedKey = this.settings.extension.get_string("selected-source");
if (selectedKey === null) {
throw new Error("'selected-source' is null?");
}
const selectedSource = buttons.get(selectedKey)?.source;
if (typeof selectedSource === "undefined") {
throw new Error(`${selectedKey} does not denote a known source!`);
Expand All @@ -187,9 +179,6 @@ const SourcesPage = GObject.registerClass(
buttons.get(selectedKey)?.button.set_active(true);
this.settings.extension.connect("changed::selected-source", () => {
const newKey = this.settings.extension.get_string("selected-source");
if (newKey === null) {
throw new Error("'selected-source' is null?");
}
const item = buttons.get(newKey);
if (typeof item === "undefined") {
throw new Error(`Source ${newKey} not known?`);
Expand Down Expand Up @@ -303,9 +292,6 @@ export default class PictureOfTheDayPreferences extends ExtensionPreferences {
// Load relevant settings
const extensionSettings = this.getSettings();
const schema_id = extensionSettings.schemaId;
if (schema_id === null) {
throw new Error("Schema ID of settings schema unexpectedly null?");
}
const allSettings: AllSettings = {
extension: extensionSettings,
sourceAPOD: this.getSettings(`${schema_id}.source.${apod.key}`),
Expand Down

0 comments on commit 0502a31

Please sign in to comment.