Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

feat: enhance app and icon naming with platform-specific logic and streamline icon generation error handling

Tw93f540e5b3bfd4
diff --git a/bin/options/icon.ts b/bin/options/icon.ts
index da85716c..3f33c19b 100644
--- a/bin/options/icon.ts
+++ b/bin/options/icon.ts
@@ -42,12 +42,10 @@ const API_KEYS = {
/**
* Generates platform-specific icon paths and handles copying for Windows
*/
-import { generateSafeFilename } from '@/utils/name';
+import { generateLinuxPackageName, generateSafeFilename } from '@/utils/name';
function generateIconPath(appName: string, isDefault = false): string {
- const safeName = isDefault
- ? 'icon'
- : generateSafeFilename(appName).toLowerCase();
+ const safeName = isDefault ? 'icon' : getIconBaseName(appName);
const baseName = safeName;
if (IS_WIN) {
@@ -59,6 +57,13 @@ function generateIconPath(appName: string, isDefault = false): string {
return path.join(npmDirectory, 'src-tauri', 'icons', `${baseName}.icns`);
}
+function getIconBaseName(appName: string): string {
+ const baseName = IS_LINUX
+ ? generateLinuxPackageName(appName)
+ : generateSafeFilename(appName).toLowerCase();
+ return baseName || 'pake-app';
+}
+
async function copyWindowsIconIfNeeded(
convertedPath: string,
appName: string,
@@ -181,7 +186,7 @@ async function convertIconFormat(
await fsExtra.ensureDir(platformOutputDir);
const processedInputPath = await preprocessIcon(inputPath);
- const iconName = generateSafeFilename(appName).toLowerCase();
+ const iconName = getIconBaseName(appName);
// Generate platform-specific format
if (IS_WIN) {
@@ -418,21 +423,6 @@ async function tryGetFavicon(
if (error instanceof Error) {
logger.debug(`Icon service ${serviceUrl} failed: ${error.message}`);
}
-
- // Network error handling
- if ((IS_LINUX || IS_WIN) && (error as any).code === 'ENOTFOUND') {
- return null;
- }
-
- // Icon generation error on Windows
- if (
- IS_WIN &&
- error instanceof Error &&
- error.message.includes('icongen')
- ) {
- return null;
- }
-
continue;
}
}
diff --git a/bin/options/index.ts b/bin/options/index.ts
index cb90c772..e7dea120 100644
--- a/bin/options/index.ts
+++ b/bin/options/index.ts
@@ -1,3 +1,4 @@
+import path from 'path';
import fsExtra from 'fs-extra';
import logger from '@/options/logger';
@@ -12,6 +13,22 @@ function resolveAppName(name: string, platform: NodeJS.Platform): string {
return platform !== 'linux' ? capitalizeFirstLetter(domain) : domain;
}
+function resolveLocalAppName(
+ filePath: string,
+ platform: NodeJS.Platform,
+): string {
+ const baseName = path.parse(filePath).name || 'pake-app';
+ if (platform === 'linux') {
+ return generateLinuxPackageName(baseName) || 'pake-app';
+ }
+ const normalized = baseName
+ .replace(/[^a-zA-Z0-9\u4e00-\u9fff -]/g, '')
+ .replace(/^[ -]+/, '')
+ .replace(/\s+/g, ' ')
+ .trim();
+ return normalized || 'pake-app';
+}
+
function isValidName(name: string, platform: NodeJS.Platform): boolean {
const platformRegexMapping: PlatformMap = {
linux: /^[a-z0-9\u4e00-\u9fff][a-z0-9\u4e00-\u9fff-]*$/,
@@ -31,10 +48,12 @@ export default async function handleOptions(
const pathExists = await fsExtra.pathExists(url);
if (!options.name) {
- const defaultName = pathExists ? '' : resolveAppName(url, platform);
+ const defaultName = pathExists
+ ? resolveLocalAppName(url, platform)
+ : resolveAppName(url, platform);
const promptMessage = 'Enter your application name';
const namePrompt = await promptText(promptMessage, defaultName);
- name = namePrompt || defaultName;
+ name = namePrompt?.trim() || defaultName;
}
if (name && platform === 'linux') {