3 Commits

Author SHA1 Message Date
Scott Idem
2c7b609295 Updated dist files 2026-05-13 19:09:09 -04:00
Scott Idem
1008a55ec3 Adjust Linux wallpaper test mode 2026-05-13 18:57:27 -04:00
Scott Idem
c8fdb8b1e7 Harden wallpaper downloads 2026-05-13 18:43:58 -04:00
3 changed files with 129 additions and 45 deletions

View File

@@ -132,12 +132,25 @@ function registerSystemHandlers() {
headers['x-account-id'] = account_id;
try {
const response = await (0, axios_1.default)({ method: 'get', url: image_url, responseType: 'stream', headers });
const content_type = (response.headers['content-type'] ?? '');
if (!content_type.startsWith('image/')) {
response.data.destroy();
return { success: false, error: `URL did not return an image (Content-Type: ${content_type})` };
}
const writer = fs.createWriteStream(dest_path);
response.data.pipe(writer);
await new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
const file_size = fs.statSync(dest_path).size;
if (file_size === 0) {
try {
fs.unlinkSync(dest_path);
}
catch { }
return { success: false, error: 'Wallpaper download incomplete (0 bytes)' };
}
return { success: true, path: dest_path };
}
catch (e) {
@@ -185,6 +198,12 @@ function registerSystemHandlers() {
return { success: false, error: result.error };
primary_path = result.path;
}
if (!primary_path && url_external && display === 'external') {
const ext_result = await download_wallpaper_image(url_external, 'wallpaper_external');
if (!ext_result.success || !ext_result.path)
return { success: false, error: ext_result.error };
return await apply_mac_wallpaper(ext_result.path, 'external');
}
if (!primary_path)
return { success: false, error: 'No image source provided' };
if (url_external) {
@@ -193,26 +212,50 @@ function registerSystemHandlers() {
if (!primary_result.success)
return primary_result;
const ext_result = await download_wallpaper_image(url_external, 'wallpaper_external');
const ext_path = ext_result.success && ext_result.path ? ext_result.path : primary_path;
return await apply_mac_wallpaper(ext_path, 'external');
if (!ext_result.success || !ext_result.path)
return { success: false, error: ext_result.error };
return await apply_mac_wallpaper(ext_result.path, 'external');
}
else {
return await apply_mac_wallpaper(primary_path, display);
}
}
if (os.platform() === 'linux') {
let img_path = imagePath ? (0, file_utils_1.expandPath)(imagePath) : null;
if (!img_path && url) {
const result = await download_wallpaper_image(url, 'wallpaper_primary');
if (!result.success || !result.path)
return { success: false, error: result.error };
img_path = result.path;
}
if (!img_path)
// Dev test mode: never touch the desktop on Linux. Running gsettings during
// development would reset the dev workstation monitors on every test cycle.
// Return what would have run so the Svelte side can show a debug popup.
const would_run = [];
const cache_dir = wallpaper_cache_dir;
if (!imagePath && !url && !url_external) {
return { success: false, error: 'No image source provided' };
if (!fs.existsSync(img_path))
return { success: false, error: 'Image file not found' };
return await runExec(`gsettings set org.gnome.desktop.background picture-uri "file://${img_path}"`);
}
if (imagePath) {
const clean = (0, file_utils_1.expandPath)(imagePath);
if (!fs.existsSync(clean))
return { success: false, error: 'Image file not found' };
}
if (url)
would_run.push(`download: ${url}\n${path.join(cache_dir, 'wallpaper_primary.jpg')}`);
if (url_external)
would_run.push(`download: ${url_external}\n${path.join(cache_dir, 'wallpaper_external.jpg')}`);
if (imagePath) {
would_run.push(`gsettings set org.gnome.desktop.background picture-uri "file://${(0, file_utils_1.expandPath)(imagePath)}"`);
}
else if (url) {
would_run.push(`gsettings set org.gnome.desktop.background picture-uri "file://${path.join(cache_dir, 'wallpaper_primary.jpg')}"`);
}
if (url_external) {
would_run.push(`(external display: gsettings has no per-display wallpaper support)`);
}
return {
success: true,
linux_test_mode: true,
platform: 'linux',
display,
url: url ?? null,
url_external: url_external ?? null,
would_run
};
}
return { success: false, error: 'Platform not supported' };
});

File diff suppressed because one or more lines are too long

View File

@@ -96,12 +96,23 @@ export function registerSystemHandlers() {
try {
const response = await axios({ method: 'get', url: image_url, responseType: 'stream', headers });
const content_type = (response.headers['content-type'] ?? '') as string;
if (!content_type.startsWith('image/')) {
response.data.destroy();
return { success: false, error: `URL did not return an image (Content-Type: ${content_type})` };
}
const writer = fs.createWriteStream(dest_path);
response.data.pipe(writer);
await new Promise<void>((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
const file_size = fs.statSync(dest_path).size;
if (file_size === 0) {
try { fs.unlinkSync(dest_path); } catch {}
return { success: false, error: 'Wallpaper download incomplete (0 bytes)' };
}
return { success: true, path: dest_path };
} catch (e: any) {
return { success: false, error: `Wallpaper download failed: ${e.message}` };
@@ -144,6 +155,12 @@ export function registerSystemHandlers() {
primary_path = result.path;
}
if (!primary_path && url_external && display === 'external') {
const ext_result = await download_wallpaper_image(url_external, 'wallpaper_external');
if (!ext_result.success || !ext_result.path) return { success: false, error: ext_result.error };
return await apply_mac_wallpaper(ext_result.path, 'external');
}
if (!primary_path) return { success: false, error: 'No image source provided' };
if (url_external) {
@@ -152,26 +169,50 @@ export function registerSystemHandlers() {
if (!primary_result.success) return primary_result;
const ext_result = await download_wallpaper_image(url_external, 'wallpaper_external');
const ext_path = ext_result.success && ext_result.path ? ext_result.path : primary_path;
return await apply_mac_wallpaper(ext_path, 'external');
if (!ext_result.success || !ext_result.path) return { success: false, error: ext_result.error };
return await apply_mac_wallpaper(ext_result.path, 'external');
} else {
return await apply_mac_wallpaper(primary_path, display);
}
}
if (os.platform() === 'linux') {
let img_path: string | null = imagePath ? expandPath(imagePath) : null;
// Dev test mode: never touch the desktop on Linux. Running gsettings during
// development would reset the dev workstation monitors on every test cycle.
// Return what would have run so the Svelte side can show a debug popup.
const would_run: string[] = [];
const cache_dir = wallpaper_cache_dir;
if (!img_path && url) {
const result = await download_wallpaper_image(url, 'wallpaper_primary');
if (!result.success || !result.path) return { success: false, error: result.error };
img_path = result.path;
if (!imagePath && !url && !url_external) {
return { success: false, error: 'No image source provided' };
}
if (!img_path) return { success: false, error: 'No image source provided' };
if (!fs.existsSync(img_path)) return { success: false, error: 'Image file not found' };
if (imagePath) {
const clean = expandPath(imagePath);
if (!fs.existsSync(clean)) return { success: false, error: 'Image file not found' };
}
return await runExec(`gsettings set org.gnome.desktop.background picture-uri "file://${img_path}"`);
if (url) would_run.push(`download: ${url}\n → ${path.join(cache_dir, 'wallpaper_primary.jpg')}`);
if (url_external) would_run.push(`download: ${url_external}\n → ${path.join(cache_dir, 'wallpaper_external.jpg')}`);
if (imagePath) {
would_run.push(`gsettings set org.gnome.desktop.background picture-uri "file://${expandPath(imagePath)}"`);
} else if (url) {
would_run.push(`gsettings set org.gnome.desktop.background picture-uri "file://${path.join(cache_dir, 'wallpaper_primary.jpg')}"`);
}
if (url_external) {
would_run.push(`(external display: gsettings has no per-display wallpaper support)`);
}
return {
success: true,
linux_test_mode: true,
platform: 'linux',
display,
url: url ?? null,
url_external: url_external ?? null,
would_run
};
}
return { success: false, error: 'Platform not supported' };