🐛 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) {
|
export async function handleIcon(options: PakeAppOptions, url?: string) {
|
||||||
if (options.icon) {
|
if (options.icon) {
|
||||||
if (options.icon.startsWith('http')) {
|
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);
|
return path.resolve(options.icon);
|
||||||
}
|
}
|
||||||
@@ -142,7 +163,14 @@ export async function handleIcon(options: PakeAppOptions, url?: string) {
|
|||||||
try {
|
try {
|
||||||
const convertedPath = await convertIconFormat(defaultPngPath, 'icon');
|
const convertedPath = await convertIconFormat(defaultPngPath, 'icon');
|
||||||
if (convertedPath && (await fsExtra.pathExists(convertedPath))) {
|
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) {
|
} catch (error) {
|
||||||
logger.warn(`Failed to convert default png to ico: ${error.message}`);
|
logger.warn(`Failed to convert default png to ico: ${error.message}`);
|
||||||
@@ -226,6 +254,19 @@ async function tryGetFavicon(
|
|||||||
|
|
||||||
const convertedPath = await convertIconFormat(faviconPath, appName);
|
const convertedPath = await convertIconFormat(faviconPath, appName);
|
||||||
if (convertedPath) {
|
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(
|
spinner.succeed(
|
||||||
chalk.green('Icon fetched and converted successfully!'),
|
chalk.green('Icon fetched and converted successfully!'),
|
||||||
);
|
);
|
||||||
|
|||||||
33
dist/cli.js
vendored
33
dist/cli.js
vendored
@@ -22,7 +22,7 @@ import sharp from 'sharp';
|
|||||||
import * as psl from 'psl';
|
import * as psl from 'psl';
|
||||||
|
|
||||||
var name = "pake-cli";
|
var name = "pake-cli";
|
||||||
var version = "3.2.9";
|
var version = "3.2.10";
|
||||||
var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。";
|
var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。";
|
||||||
var engines = {
|
var engines = {
|
||||||
node: ">=16.0.0"
|
node: ">=16.0.0"
|
||||||
@@ -935,7 +935,22 @@ async function convertIconFormat(inputPath, appName) {
|
|||||||
async function handleIcon(options, url) {
|
async function handleIcon(options, url) {
|
||||||
if (options.icon) {
|
if (options.icon) {
|
||||||
if (options.icon.startsWith('http')) {
|
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);
|
return path.resolve(options.icon);
|
||||||
}
|
}
|
||||||
@@ -960,7 +975,11 @@ async function handleIcon(options, url) {
|
|||||||
try {
|
try {
|
||||||
const convertedPath = await convertIconFormat(defaultPngPath, 'icon');
|
const convertedPath = await convertIconFormat(defaultPngPath, 'icon');
|
||||||
if (convertedPath && (await fsExtra.pathExists(convertedPath))) {
|
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) {
|
catch (error) {
|
||||||
@@ -1024,6 +1043,14 @@ async function tryGetFavicon(url, appName) {
|
|||||||
continue;
|
continue;
|
||||||
const convertedPath = await convertIconFormat(faviconPath, appName);
|
const convertedPath = await convertIconFormat(faviconPath, appName);
|
||||||
if (convertedPath) {
|
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!'));
|
spinner.succeed(chalk.green('Icon fetched and converted successfully!'));
|
||||||
return convertedPath;
|
return convertedPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pake-cli",
|
"name": "pake-cli",
|
||||||
"version": "3.2.9",
|
"version": "3.2.10",
|
||||||
"description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。",
|
"description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0"
|
"node": ">=16.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user