1+ import GLib from 'gi://GLib' ;
2+ import Gio from 'gi://Gio' ;
13import { ConfigWriter } from '../../utils/ConfigWriter.js' ;
24import { BlueprintService } from '../../services/BlueprintService.js' ;
35import { ColorMapper } from '../utils/color-mapper.js' ;
6+ import { ensureDirectoryExists } from '../../utils/file-utils.js' ;
47
58/**
69 * Command handler for applying a blueprint theme
@@ -11,9 +14,9 @@ export class ApplyBlueprintCommand {
1114 * Executes the apply-blueprint command
1215 *
1316 * @param {string } name - Name of the blueprint to apply
14- * @returns {boolean } True if successful, false otherwise
17+ * @returns {Promise< boolean> } True if successful, false otherwise
1518 */
16- static execute ( name ) {
19+ static async execute ( name ) {
1720 if ( ! name ) {
1821 print ( 'Error: Blueprint name is required' ) ;
1922 print ( 'Usage: aether --apply-blueprint <name>' ) ;
@@ -47,6 +50,16 @@ export class ApplyBlueprintCommand {
4750 }
4851
4952 const palette = foundBlueprint . palette ;
53+
54+ // Download wallpaper if wallpaperUrl is present and wallpaper is missing
55+ let wallpaperPath = palette . wallpaper ;
56+ if ( palette . wallpaperUrl && ! wallpaperPath ) {
57+ wallpaperPath = await this . _downloadWallpaper ( palette . wallpaperUrl ) ;
58+ if ( ! wallpaperPath ) {
59+ print ( 'Warning: Failed to download wallpaper, continuing without it' ) ;
60+ }
61+ }
62+
5063 const colorRoles = ColorMapper . mapColorsToRoles ( palette . colors ) ;
5164
5265 const settings = foundBlueprint . settings || { } ;
@@ -56,7 +69,7 @@ export class ApplyBlueprintCommand {
5669 const configWriter = new ConfigWriter ( ) ;
5770 configWriter . applyTheme (
5871 colorRoles ,
59- palette . wallpaper ,
72+ wallpaperPath ,
6073 settings ,
6174 lightMode ,
6275 appOverrides ,
@@ -71,4 +84,48 @@ export class ApplyBlueprintCommand {
7184 return false ;
7285 }
7386 }
87+
88+ /**
89+ * Downloads a wallpaper from a URL
90+ * @param {string } url - URL to download from
91+ * @returns {Promise<string|null> } Path to downloaded wallpaper or null on failure
92+ * @private
93+ */
94+ static async _downloadWallpaper ( url ) {
95+ try {
96+ print ( `Downloading wallpaper from: ${ url } ` ) ;
97+
98+ const wallpapersDir = GLib . build_filenamev ( [
99+ GLib . get_user_data_dir ( ) ,
100+ 'aether' ,
101+ 'wallpapers' ,
102+ ] ) ;
103+ ensureDirectoryExists ( wallpapersDir ) ;
104+
105+ // Extract filename from URL
106+ const urlParts = url . split ( '/' ) ;
107+ const filename = urlParts [ urlParts . length - 1 ] || 'imported-wallpaper.jpg' ;
108+ const wallpaperPath = GLib . build_filenamev ( [
109+ wallpapersDir ,
110+ filename ,
111+ ] ) ;
112+
113+ // Check if already downloaded
114+ const file = Gio . File . new_for_path ( wallpaperPath ) ;
115+ if ( file . query_exists ( null ) ) {
116+ print ( `Wallpaper already downloaded: ${ wallpaperPath } ` ) ;
117+ return wallpaperPath ;
118+ }
119+
120+ // Download wallpaper
121+ const { wallhavenService} = await import ( '../../services/wallhaven-service.js' ) ;
122+ await wallhavenService . downloadWallpaper ( url , wallpaperPath ) ;
123+
124+ print ( `✓ Wallpaper downloaded: ${ wallpaperPath } ` ) ;
125+ return wallpaperPath ;
126+ } catch ( error ) {
127+ print ( `Error downloading wallpaper: ${ error . message } ` ) ;
128+ return null ;
129+ }
130+ }
74131}
0 commit comments