-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-msix-icons.mjs
More file actions
126 lines (104 loc) · 4.27 KB
/
Copy pathgenerate-msix-icons.mjs
File metadata and controls
126 lines (104 loc) · 4.27 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
123
124
125
126
#!/usr/bin/env node
/**
* Generate proper MSIX icons with transparent backgrounds
* This should be run after updating the source icon
*/
import sharp from 'sharp';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const workspaceRoot = __dirname;
const ICON_SPECS = [
{ name: 'Square44x44Logo.png', size: 44 },
{ name: 'Square71x71Logo.png', size: 71 },
{ name: 'Square150x150Logo.png', size: 150 },
{ name: 'Square310x310Logo.png', size: 310 },
{ name: 'Wide310x150Logo.png', width: 310, height: 150 },
{ name: 'StoreLogo.png', size: 50 }
];
const TASKBAR_TARGET_SIZES = [16, 20, 24, 30, 32, 36, 40, 44, 48, 60, 64, 72, 80, 96, 256];
async function processIcon(sourceIconPath, spec) {
// Preserve original icon style; only resize on a transparent background.
let image = sharp(sourceIconPath);
// Resize based on spec
if (spec.width && spec.height) {
// For wide tiles like Wide310x150Logo
image = image.resize(spec.width, spec.height, {
fit: 'inside',
background: { r: 0, g: 0, b: 0, alpha: 0 }
});
} else {
// For square tiles
image = image.resize(spec.size, spec.size, {
fit: 'inside',
background: { r: 0, g: 0, b: 0, alpha: 0 }
});
}
return image.png();
}
async function main() {
const sourceIcon = path.join(workspaceRoot, 'src-tauri', 'icons', 'icon.png');
const outputDir = path.join(workspaceRoot, 'src-tauri', 'windows', 'msix-staging', 'Assets');
if (!fs.existsSync(sourceIcon)) {
console.error(`✗ Source icon not found: ${sourceIcon}`);
process.exit(1);
}
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
console.log('Generating MSIX icons with transparent backgrounds...\n');
try {
// Read source icon
const image = sharp(sourceIcon);
const metadata = await image.metadata();
console.log(`Source image: ${metadata.width}x${metadata.height}`);
// Process each icon spec
let successCount = 0;
for (const spec of ICON_SPECS) {
const outputPath = path.join(outputDir, spec.name);
try {
const processedImage = await processIcon(sourceIcon, spec);
await processedImage.toFile(outputPath);
const displayName = spec.width ?
`${spec.name} (${spec.width}x${spec.height})` :
`${spec.name} (${spec.size}x${spec.size})`;
console.log(`✓ ${displayName}`);
successCount++;
} catch (err) {
console.error(`✗ ${spec.name}: ${err.message}`);
}
}
for (const size of TASKBAR_TARGET_SIZES) {
const names = [
`Square44x44Logo.targetsize-${size}.png`,
`Square44x44Logo.altform-unplated_targetsize-${size}.png`
];
for (const name of names) {
const outputPath = path.join(outputDir, name);
try {
await sharp(sourceIcon)
.resize(size, size, {
fit: 'inside',
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
.png()
.toFile(outputPath);
console.log(`✓ ${name} (${size}x${size})`);
successCount++;
} catch (err) {
console.error(`✗ ${name}: ${err.message}`);
}
}
}
const expectedCount = ICON_SPECS.length + (TASKBAR_TARGET_SIZES.length * 2);
console.log(`\n✓ Successfully generated ${successCount}/${expectedCount} MSIX icons`);
console.log('✓ Generated base and unplated targetsize icons with transparent backgrounds');
console.log('\nThe taskbar and Start menu will display correctly without blue backgrounds.');
} catch (error) {
console.error(`✗ Error: ${error.message}`);
process.exit(1);
}
}
main();