-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-taskbar-icon.mjs
More file actions
122 lines (107 loc) · 4 KB
/
fix-taskbar-icon.mjs
File metadata and controls
122 lines (107 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
/**
* Fix Windows taskbar icon by removing the blue background
* Creates a transparent version of Square44x44Logo.png
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function fixTaskbarIcon() {
// Check if sharp is available
let sharp;
try {
sharp = (await import('sharp')).default;
} catch (e) {
console.error('sharp not found. Installing sharp...');
const { execSync } = await import('child_process');
try {
execSync('npm install sharp', { stdio: 'inherit' });
sharp = (await import('sharp')).default;
} catch (err) {
console.error('Failed to install sharp');
process.exit(1);
}
}
const workspaceRoot = 'c:\\Users\\seans\\Documents\\GitHub\\TimeLens';
const sourceIcon = path.join(workspaceRoot, 'src-tauri', 'icons', 'icon.png');
const outputDir = path.join(workspaceRoot, 'src-tauri', 'windows', 'msix-staging', 'Assets');
const outputIcon = path.join(outputDir, 'Square44x44Logo.png');
// Check if source exists
if (!fs.existsSync(sourceIcon)) {
console.error(`✗ Source icon not found: ${sourceIcon}`);
process.exit(1);
}
if (!fs.existsSync(outputDir)) {
console.error(`✗ Output directory not found: ${outputDir}`);
process.exit(1);
}
console.log('Fixing Windows taskbar icon (Square44x44Logo.png)...');
console.log(`Source: ${sourceIcon}`);
console.log(`Output: ${outputIcon}`);
try {
// Read image
const image = sharp(sourceIcon);
const metadata = await image.metadata();
// Get raw pixel data
const { data } = await image.raw().toBuffer({ resolveWithObject: true });
// Process pixels to remove blue background
const newData = Buffer.alloc(data.length);
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
const a = data[i + 3] || 255;
// Check if pixel is part of blue background
// Blue background is darker: b > r+20 and b > g+20 and overall dark
if (b > r + 20 && b > g + 20 && (r + g + b) < 300) {
// Make background transparent
newData[i] = r;
newData[i + 1] = g;
newData[i + 2] = b;
newData[i + 3] = 0; // Transparent
} else {
// Keep the pixel
newData[i] = r;
newData[i + 1] = g;
newData[i + 2] = b;
newData[i + 3] = 255; // Opaque
}
}
// Resize to 44x44 with the processed pixels, then save
await sharp({
create: {
width: metadata.width,
height: metadata.height,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 }
}
})
.composite([{
input: newData,
raw: {
width: metadata.width,
height: metadata.height,
channels: 4
}
}])
.resize(44, 44, {
fit: 'contain',
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
.png()
.toFile(outputIcon);
console.log(`✓ Created ${outputIcon}`);
console.log('\n✓ Taskbar icon fixed successfully!');
console.log(' The blue background has been removed and replaced with transparency.');
console.log(' This will display correctly in the Windows taskbar.');
} catch (error) {
console.error('✗ Error:', error.message);
process.exit(1);
}
}
fixTaskbarIcon().catch(err => {
console.error(err);
process.exit(1);
});