🐛 Fix ico icon problem under Windows
This commit is contained in:
45
bin/options/icon.ts
vendored
45
bin/options/icon.ts
vendored
@@ -107,7 +107,28 @@ async function convertIconFormat(
|
||||
export async function handleIcon(options: PakeAppOptions, url?: string) {
|
||||
if (options.icon) {
|
||||
if (options.icon.startsWith('http')) {
|
||||
return downloadIcon(options.icon);
|
||||
const downloadedPath = await downloadIcon(options.icon);
|
||||
if (downloadedPath && options.name) {
|
||||
// Convert downloaded icon to platform-specific format
|
||||
const convertedPath = await convertIconFormat(
|
||||
downloadedPath,
|
||||
options.name,
|
||||
);
|
||||
if (convertedPath) {
|
||||
// For Windows, copy the converted ico to the expected location
|
||||
if (IS_WIN && convertedPath.endsWith('.ico')) {
|
||||
const finalIconPath = path.join(
|
||||
npmDirectory,
|
||||
`src-tauri/png/${options.name.toLowerCase()}_256.ico`,
|
||||
);
|
||||
await fsExtra.ensureDir(path.dirname(finalIconPath));
|
||||
await fsExtra.copy(convertedPath, finalIconPath);
|
||||
return finalIconPath;
|
||||
}
|
||||
return convertedPath;
|
||||
}
|
||||
}
|
||||
return downloadedPath;
|
||||
}
|
||||
return path.resolve(options.icon);
|
||||
}
|
||||
@@ -142,7 +163,14 @@ export async function handleIcon(options: PakeAppOptions, url?: string) {
|
||||
try {
|
||||
const convertedPath = await convertIconFormat(defaultPngPath, 'icon');
|
||||
if (convertedPath && (await fsExtra.pathExists(convertedPath))) {
|
||||
return convertedPath;
|
||||
// Copy converted icon to the expected location for Windows
|
||||
const finalIconPath = path.join(
|
||||
npmDirectory,
|
||||
'src-tauri/png/icon_256.ico',
|
||||
);
|
||||
await fsExtra.ensureDir(path.dirname(finalIconPath));
|
||||
await fsExtra.copy(convertedPath, finalIconPath);
|
||||
return finalIconPath;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to convert default png to ico: ${error.message}`);
|
||||
@@ -226,6 +254,19 @@ async function tryGetFavicon(
|
||||
|
||||
const convertedPath = await convertIconFormat(faviconPath, appName);
|
||||
if (convertedPath) {
|
||||
// For Windows, copy the converted ico to the expected location
|
||||
if (IS_WIN && convertedPath.endsWith('.ico')) {
|
||||
const finalIconPath = path.join(
|
||||
npmDirectory,
|
||||
`src-tauri/png/${appName.toLowerCase()}_256.ico`,
|
||||
);
|
||||
await fsExtra.ensureDir(path.dirname(finalIconPath));
|
||||
await fsExtra.copy(convertedPath, finalIconPath);
|
||||
spinner.succeed(
|
||||
chalk.green('Icon fetched and converted successfully!'),
|
||||
);
|
||||
return finalIconPath;
|
||||
}
|
||||
spinner.succeed(
|
||||
chalk.green('Icon fetched and converted successfully!'),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user