|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Fix Windows taskbar icon by removing the blue background |
| 4 | + * Creates a transparent version of Square44x44Logo.png |
| 5 | + */ |
| 6 | + |
| 7 | +import fs from 'fs'; |
| 8 | +import path from 'path'; |
| 9 | +import { fileURLToPath } from 'url'; |
| 10 | + |
| 11 | +const __filename = fileURLToPath(import.meta.url); |
| 12 | +const __dirname = path.dirname(__filename); |
| 13 | + |
| 14 | +// Try to use sharp for image processing, fall back to Canvas if needed |
| 15 | +let processImage; |
| 16 | + |
| 17 | +try { |
| 18 | + const sharp = (await import('sharp')).default; |
| 19 | + processImage = async (inputPath, outputPath) => { |
| 20 | + console.log(`Processing ${path.basename(inputPath)}...`); |
| 21 | + |
| 22 | + const image = sharp(inputPath); |
| 23 | + const metadata = await image.metadata(); |
| 24 | + |
| 25 | + // Read the image as raw pixel data |
| 26 | + const { data, info } = await image.raw().toBuffer({ resolveWithObject: true }); |
| 27 | + |
| 28 | + // Process pixels to remove blue background |
| 29 | + const newData = Buffer.alloc(data.length); |
| 30 | + |
| 31 | + for (let i = 0; i < data.length; i += 4) { |
| 32 | + const r = data[i]; |
| 33 | + const g = data[i + 1]; |
| 34 | + const b = data[i + 2]; |
| 35 | + const a = data[i + 3]; |
| 36 | + |
| 37 | + // Check if pixel is part of blue background |
| 38 | + // Blue background is darker: b > r+20 and b > g+20 and overall dark |
| 39 | + if (b > r + 20 && b > g + 20 && (r + g + b) < 300) { |
| 40 | + // Make background transparent |
| 41 | + newData[i] = r; |
| 42 | + newData[i + 1] = g; |
| 43 | + newData[i + 2] = b; |
| 44 | + newData[i + 3] = 0; // Transparent |
| 45 | + } else { |
| 46 | + // Keep the pixel |
| 47 | + newData[i] = r; |
| 48 | + newData[i + 1] = g; |
| 49 | + newData[i + 2] = b; |
| 50 | + newData[i + 3] = 255; // Opaque |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + // Resize to 44x44 and save |
| 55 | + await sharp({ |
| 56 | + create: { |
| 57 | + width: info.width, |
| 58 | + height: info.height, |
| 59 | + channels: 4, |
| 60 | + background: { r: 0, g: 0, b: 0, alpha: 0 } |
| 61 | + } |
| 62 | + }) |
| 63 | + .composite([{ input: Buffer.concat([ |
| 64 | + Buffer.from([...data]), |
| 65 | + ]), raw: { width: info.width, height: info.height, channels: 4 } }]) |
| 66 | + .png() |
| 67 | + .toFile(outputPath); |
| 68 | + }; |
| 69 | +} catch (e) { |
| 70 | + // If sharp is not available, use a different approach |
| 71 | + console.warn('sharp not found, will attempt alternative method'); |
| 72 | + processImage = null; |
| 73 | +} |
| 74 | + |
| 75 | +async function fixTaskbarIcon() { |
| 76 | + const workspaceRoot = 'c:\\Users\\seans\\Documents\\GitHub\\TimeLens'; |
| 77 | + const sourceIcon = path.join(workspaceRoot, 'src-tauri', 'icons', 'icon.png'); |
| 78 | + const outputDir = path.join(workspaceRoot, 'src-tauri', 'windows', 'msix-staging', 'Assets'); |
| 79 | + const outputIcon = path.join(outputDir, 'Square44x44Logo.png'); |
| 80 | + |
| 81 | + // Check if source exists |
| 82 | + if (!fs.existsSync(sourceIcon)) { |
| 83 | + console.error(`✗ Source icon not found: ${sourceIcon}`); |
| 84 | + process.exit(1); |
| 85 | + } |
| 86 | + |
| 87 | + if (!fs.existsSync(outputDir)) { |
| 88 | + console.error(`✗ Output directory not found: ${outputDir}`); |
| 89 | + process.exit(1); |
| 90 | + } |
| 91 | + |
| 92 | + console.log('Fixing Windows taskbar icon (Square44x44Logo.png)...'); |
| 93 | + console.log(`Source: ${sourceIcon}`); |
| 94 | + console.log(`Output: ${outputIcon}`); |
| 95 | + |
| 96 | + try { |
| 97 | + if (processImage) { |
| 98 | + await processImage(sourceIcon, outputIcon); |
| 99 | + } else { |
| 100 | + // Fallback: try using jimp |
| 101 | + try { |
| 102 | + const Jimp = require('jimp'); |
| 103 | + const image = await Jimp.read(sourceIcon); |
| 104 | + |
| 105 | + // Resize to 44x44 |
| 106 | + image.resize(44, 44); |
| 107 | + |
| 108 | + // Process each pixel to remove blue background |
| 109 | + image.forEachPixel((pixel, x, y) => { |
| 110 | + const { r, g, b, a } = pixel; |
| 111 | + |
| 112 | + // If blue background, make transparent |
| 113 | + if (b > r + 20 && b > g + 20 && (r + g + b) < 300) { |
| 114 | + pixel.a = 0; // Transparent |
| 115 | + } else { |
| 116 | + pixel.a = 255; // Opaque |
| 117 | + } |
| 118 | + }); |
| 119 | + |
| 120 | + await image.write(outputIcon); |
| 121 | + console.log(`✓ Created ${outputIcon}`); |
| 122 | + } catch (jimpError) { |
| 123 | + console.error('Neither sharp nor jimp available. Installing sharp...'); |
| 124 | + |
| 125 | + const { execSync } = require('child_process'); |
| 126 | + try { |
| 127 | + execSync('npm install sharp', { stdio: 'inherit', cwd: workspaceRoot }); |
| 128 | + console.log('sharp installed, please run the script again'); |
| 129 | + process.exit(0); |
| 130 | + } catch (installError) { |
| 131 | + console.error('Failed to install sharp:', installError.message); |
| 132 | + process.exit(1); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + console.log('\n✓ Taskbar icon fixed successfully!'); |
| 138 | + console.log(' The blue background has been removed and replaced with transparency.'); |
| 139 | + console.log(' This will display correctly in the Windows taskbar.'); |
| 140 | + } catch (error) { |
| 141 | + console.error('✗ Error:', error.message); |
| 142 | + process.exit(1); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +fixTaskbarIcon().catch(err => { |
| 147 | + console.error(err); |
| 148 | + process.exit(1); |
| 149 | +}); |
0 commit comments