Fix the issue of Linux in chart PNG conversion.

This commit is contained in:
Tw93
2025-11-11 15:50:38 +08:00
parent eb829ca85c
commit d597d66722

View File

@@ -6,6 +6,7 @@ import linuxJson from "../src-tauri/tauri.linux.conf.json" with { type: "json" }
import { writeFileSync, existsSync, copyFileSync } from "fs"; import { writeFileSync, existsSync, copyFileSync } from "fs";
import os from "os"; import os from "os";
import sharp from "sharp";
/** /**
* Configuration script for Tauri app generation * Configuration script for Tauri app generation
@@ -121,20 +122,40 @@ function updateBaseConfigs() {
} }
} }
function ensureIconExists(iconPath, defaultPath, description = "icon") { async function ensureRgbaPng(iconPath) {
try {
const buffer = await sharp(iconPath)
.ensureAlpha()
.png({ force: true })
.toBuffer();
writeFileSync(iconPath, buffer);
} catch (error) {
console.warn(`Failed to normalize ${iconPath} to RGBA: ${error.message}`);
}
}
async function ensureIconExists(
iconPath,
defaultPath,
description = "icon",
ensureRgba = false,
) {
if (!existsSync(iconPath)) { if (!existsSync(iconPath)) {
// For official release apps, icons should already exist
if (process.env.PAKE_CREATE_APP === "1") { if (process.env.PAKE_CREATE_APP === "1") {
console.warn( console.warn(
`${description} for ${process.env.NAME} not found at ${iconPath}`, `${description} for ${process.env.NAME} not found at ${iconPath}`,
); );
return; // Don't auto-generate for release builds return;
} }
console.warn( console.warn(
`${description} for ${process.env.NAME} not found, using default`, `${description} for ${process.env.NAME} not found, using default`,
); );
copyFileSync(defaultPath, iconPath); copyFileSync(defaultPath, iconPath);
} }
if (ensureRgba && existsSync(iconPath)) {
await ensureRgbaPng(iconPath);
}
} }
function updatePlatformConfig(platformConfig, platformVars) { function updatePlatformConfig(platformConfig, platformVars) {
@@ -150,8 +171,13 @@ function updatePlatformConfig(platformConfig, platformVars) {
// Platform-specific handlers // Platform-specific handlers
const platformHandlers = { const platformHandlers = {
linux: (config) => { linux: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "Linux icon"); await ensureIconExists(
config.iconPath,
config.defaultIcon,
"Linux icon",
true,
);
// Update desktop entry // Update desktop entry
linuxJson.bundle.linux.deb.files = { linuxJson.bundle.linux.deb.files = {
@@ -162,14 +188,14 @@ const platformHandlers = {
updatePlatformConfig(linuxJson, config); updatePlatformConfig(linuxJson, config);
}, },
darwin: (config) => { darwin: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon"); await ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon");
updatePlatformConfig(macosJson, config); updatePlatformConfig(macosJson, config);
}, },
win32: (config) => { win32: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon"); await ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon");
ensureIconExists( await ensureIconExists(
config.hdIconPath, config.hdIconPath,
config.hdDefaultIcon, config.hdDefaultIcon,
"Windows HD icon", "Windows HD icon",
@@ -196,7 +222,7 @@ function saveConfigurations() {
} }
// Main execution // Main execution
function main() { async function main() {
try { try {
validateEnvironment(); validateEnvironment();
updateBaseConfigs(); updateBaseConfigs();
@@ -210,7 +236,7 @@ function main() {
const handler = platformHandlers[platform]; const handler = platformHandlers[platform];
if (handler) { if (handler) {
handler(platformConfig); await handler(platformConfig);
} }
saveConfigurations(); saveConfigurations();