Skip to content

Commit

Permalink
Expect historyEntry.adapter as null
Browse files Browse the repository at this point in the history
Older history entries from gsettings might not yet have a adapter
associated.
This properly types this and fixes related null checks missing.
  • Loading branch information
Lucki authored and ifl0w committed Feb 11, 2024
1 parent 59c159f commit 975b97c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class HistoryEntry {
/** Unique identifier, concat of timestamp and name */
id: string;
/** Basename of URI */
name: string;
name: string | null; // This can be null when an entry from an older version is mapped from settings
path: string | null = null;
source: SourceInfo;
adapter: AdapterInfo = {
adapter: AdapterInfo | null = { // This can be null when an entry from an older version is mapped from settings
id: null,
type: null,
};
Expand Down
4 changes: 2 additions & 2 deletions src/historyMenuElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const HistoryElement = GObject.registerClass({
this.menu.addMenuItem(copyToFavorites);

// Static URLs can't block images (yet?)
if (this.historyEntry.adapter.type !== 5) {
if (this.historyEntry.adapter?.type !== 5) {
const blockImage = new PopupMenu.PopupMenuItem('Add To Blocklist');
blockImage.connect('activate', () => {
this._addToBlocklist(this.historyEntry);
Expand Down Expand Up @@ -185,7 +185,7 @@ const HistoryElement = GObject.registerClass({
}

private _addToBlocklist(entry: HistoryModule.HistoryEntry) {
if (!entry.adapter.id || entry.adapter.id === '-1' || !entry.name) {
if (!entry.adapter?.id || entry.adapter.id === '-1' || !entry.name) {
this._logger.error('Image entry is missing information');
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/wallpaperController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ class WallpaperController {
const fetchPromiseArray: Promise<HistoryModule.HistoryEntry>[] = [];

for (const element of array) {
element.adapter.id = imageAdapters[index].id;
element.adapter.type = imageAdapters[index].type;
element.adapter = {
id: imageAdapters[index].id,
type: imageAdapters[index].type,
};

this._logger.info(`Requesting image: ${element.source.imageDownloadUrl}`);
fetchPromiseArray.push(imageAdapters[index].adapter.fetchFile(element));
Expand Down

0 comments on commit 975b97c

Please sign in to comment.