Skip to content

Commit

Permalink
Let the manager handle all states
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucki committed Jul 8, 2023
1 parent 0c11180 commit feff7b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
17 changes: 16 additions & 1 deletion src/manager/externalWallpaperManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class ExternalWallpaperManager extends WallpaperManager {
this._cancelRunning();

// Fallback to default manager, all currently supported external manager don't support setting single images
if (wallpaperPaths.length === 1) {
if (wallpaperPaths.length === 1 || (mode === Mode.BACKGROUND_AND_LOCKSCREEN_INDEPENDENT && wallpaperPaths.length === 2)) {
const promises = [];

if (mode === Mode.BACKGROUND || mode === Mode.BACKGROUND_AND_LOCKSCREEN)
Expand All @@ -61,6 +61,16 @@ abstract class ExternalWallpaperManager extends WallpaperManager {
if (mode === Mode.LOCKSCREEN || mode === Mode.BACKGROUND_AND_LOCKSCREEN)
promises.push(DefaultWallpaperManager.setSingleLockScreen(`file://${wallpaperPaths[0]}`, this._backgroundSettings, this._screensaverSettings));

if (mode === Mode.BACKGROUND_AND_LOCKSCREEN_INDEPENDENT) {
if (wallpaperPaths.length < 2)
throw new Error('Not enough wallpaper');

// Half the images for the background
promises.push(DefaultWallpaperManager.setSingleBackground(`file://${wallpaperPaths[0]}`, this._backgroundSettings));
// Half the images for the lock screen
promises.push(DefaultWallpaperManager.setSingleLockScreen(`file://${wallpaperPaths[1]}`, this._backgroundSettings, this._screensaverSettings));
}

await Promise.allSettled(promises);
return;
}
Expand All @@ -79,6 +89,11 @@ abstract class ExternalWallpaperManager extends WallpaperManager {

if (mode === Mode.BACKGROUND_AND_LOCKSCREEN)
await this._setLockScreenAfterBackground(wallpaperPaths);

if (mode === Mode.BACKGROUND_AND_LOCKSCREEN_INDEPENDENT) {
await this._setBackground(wallpaperPaths.slice(0, wallpaperPaths.length / 2));
await this._setLockScreen(wallpaperPaths.slice(wallpaperPaths.length / 2));
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/manager/wallpaperManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ abstract class WallpaperManager {
if (mode === Mode.LOCKSCREEN || mode === Mode.BACKGROUND_AND_LOCKSCREEN)
promises.push(this._setLockScreen(wallpaperPaths));

if (mode === Mode.BACKGROUND_AND_LOCKSCREEN_INDEPENDENT) {
if (wallpaperPaths.length < 2)
throw new Error('Not enough wallpaper');

// Half the images for the background
promises.push(this._setBackground(wallpaperPaths.slice(0, wallpaperPaths.length / 2)));
// Half the images for the lock screen
promises.push(this._setLockScreen(wallpaperPaths.slice(wallpaperPaths.length / 2)));
}

await Promise.allSettled(promises);
}

Expand Down
9 changes: 1 addition & 8 deletions src/wallpaperController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,7 @@ class WallpaperController {

const usedWallpaperPaths = this._fillDisplaysFromHistory(newWallpaperPaths, monitorCount);

if (changeType === Mode.BACKGROUND_AND_LOCKSCREEN_INDEPENDENT) {
// Half the images for the background
await this._wallpaperManager.setWallpaper(usedWallpaperPaths.slice(0, monitorCount / 2), Mode.BACKGROUND);
// Half the images for the lock screen
await this._wallpaperManager.setWallpaper(usedWallpaperPaths.slice(monitorCount / 2), Mode.LOCKSCREEN);
} else {
await this._wallpaperManager.setWallpaper(usedWallpaperPaths, changeType);
}
await this._wallpaperManager.setWallpaper(usedWallpaperPaths, changeType);

usedWallpaperPaths.reverse().forEach(path => {
const id = this._historyController.getEntryByPath(path)?.id;
Expand Down

0 comments on commit feff7b1

Please sign in to comment.