@@ -4,11 +4,7 @@ import fsExtra from 'fs-extra';
44import combineFiles from '@/utils/combine' ;
55import logger from '@/options/logger' ;
66import { PakeAppOptions , PlatformMap } from '@/types' ;
7- import {
8- tauriConfigDirectory ,
9- npmDirectory ,
10- getUserHomeDir ,
11- } from '@/utils/dir' ;
7+ import { tauriConfigDirectory , npmDirectory } from '@/utils/dir' ;
128
139export async function mergeConfig (
1410 url : string ,
@@ -186,10 +182,8 @@ export async function mergeConfig(
186182 logger . warn ( `✼ ${ iconInfo . message } , but you give ${ customIconExt } ` ) ;
187183 tauriConf . bundle . icon = [ iconInfo . defaultIcon ] ;
188184 } else {
189- // Save icon to .pake directory instead of src-tauri
190- const iconPath = path . join ( tauriConfigDirectory , iconInfo . path ) ;
191- await fsExtra . ensureDir ( path . dirname ( iconPath ) ) ;
192- tauriConf . bundle . resources = [ `.pake/${ iconInfo . path } ` ] ;
185+ const iconPath = path . join ( npmDirectory , 'src-tauri/' , iconInfo . path ) ;
186+ tauriConf . bundle . resources = [ iconInfo . path ] ;
193187 await fsExtra . copy ( options . icon , iconPath ) ;
194188 }
195189
@@ -205,20 +199,30 @@ export async function mergeConfig(
205199 tauriConf . bundle . icon = [ iconInfo . defaultIcon ] ;
206200 }
207201
208- // Set system tray icon path
209- let trayIconPath = 'icons/icon.png' ; // default fallback
210-
211- if ( showSystemTray ) {
212- if ( systemTrayIcon . length > 0 ) {
213- // User provided custom system tray icon
214- trayIconPath = await handleCustomTrayIcon (
215- systemTrayIcon ,
216- name ,
217- tauriConfigDirectory ,
218- ) ;
219- } else {
220- // Use original downloaded PNG icon for system tray
221- trayIconPath = await handleDownloadedTrayIcon ( name , tauriConfigDirectory ) ;
202+ // Set tray icon path.
203+ let trayIconPath =
204+ platform === 'darwin' ? 'png/icon_512.png' : tauriConf . bundle . icon [ 0 ] ;
205+ if ( systemTrayIcon . length > 0 ) {
206+ try {
207+ await fsExtra . pathExists ( systemTrayIcon ) ;
208+ // 需要判断图标格式,默认只支持ico和png两种
209+ let iconExt = path . extname ( systemTrayIcon ) . toLowerCase ( ) ;
210+ if ( iconExt == '.png' || iconExt == '.ico' ) {
211+ const trayIcoPath = path . join (
212+ npmDirectory ,
213+ `src-tauri/png/${ name . toLowerCase ( ) } ${ iconExt } ` ,
214+ ) ;
215+ trayIconPath = `png/${ name . toLowerCase ( ) } ${ iconExt } ` ;
216+ await fsExtra . copy ( systemTrayIcon , trayIcoPath ) ;
217+ } else {
218+ logger . warn (
219+ `✼ System tray icon must be .ico or .png, but you provided ${ iconExt } .` ,
220+ ) ;
221+ logger . warn ( `✼ Default system tray icon will be used.` ) ;
222+ }
223+ } catch {
224+ logger . warn ( `✼ ${ systemTrayIcon } not exists!` ) ;
225+ logger . warn ( `✼ Default system tray icon will remain unchanged.` ) ;
222226 }
223227 }
224228
@@ -264,6 +268,7 @@ export async function mergeConfig(
264268 ) ;
265269
266270 const bundleConf = { bundle : tauriConf . bundle } ;
271+ console . log ( 'pakeConfig' , tauriConf . pake ) ;
267272 await fsExtra . outputJSON ( configPath , bundleConf , { spaces : 4 } ) ;
268273 const pakeConfigPath = path . join ( tauriConfigDirectory , 'pake.json' ) ;
269274 await fsExtra . outputJSON ( pakeConfigPath , tauriConf . pake , { spaces : 4 } ) ;
@@ -278,94 +283,3 @@ export async function mergeConfig(
278283 const configJsonPath = path . join ( tauriConfigDirectory , 'tauri.conf.json' ) ;
279284 await fsExtra . outputJSON ( configJsonPath , tauriConf2 , { spaces : 4 } ) ;
280285}
281-
282- /**
283- * Handle custom system tray icon provided by user
284- */
285- async function handleCustomTrayIcon (
286- systemTrayIcon : string ,
287- appName : string ,
288- configDir : string ,
289- ) : Promise < string > {
290- const defaultPath = 'icons/icon.png' ;
291-
292- if ( ! ( await fsExtra . pathExists ( systemTrayIcon ) ) ) {
293- logger . warn ( `✼ Custom tray icon ${ systemTrayIcon } not found!` ) ;
294- logger . warn ( `✼ Using default icon for system tray.` ) ;
295- return defaultPath ;
296- }
297-
298- const iconExt = path . extname ( systemTrayIcon ) . toLowerCase ( ) ;
299- if ( iconExt !== '.png' && iconExt !== '.ico' ) {
300- logger . warn (
301- `✼ System tray icon must be .png or .ico, but you provided ${ iconExt } .` ,
302- ) ;
303- logger . warn ( `✼ Using default icon for system tray.` ) ;
304- return defaultPath ;
305- }
306-
307- try {
308- const trayIconPath = path . join (
309- configDir ,
310- `png/${ appName . toLowerCase ( ) } ${ iconExt } ` ,
311- ) ;
312- await fsExtra . ensureDir ( path . dirname ( trayIconPath ) ) ;
313- await fsExtra . copy ( systemTrayIcon , trayIconPath ) ;
314-
315- const relativePath = `.pake/png/${ appName . toLowerCase ( ) } ${ iconExt } ` ;
316- logger . info ( `✓ Using custom system tray icon: ${ systemTrayIcon } ` ) ;
317- return relativePath ;
318- } catch ( error ) {
319- logger . warn ( `✼ Failed to copy custom tray icon: ${ error } ` ) ;
320- logger . warn ( `✼ Using default icon for system tray.` ) ;
321- return defaultPath ;
322- }
323- }
324-
325- /**
326- * Handle system tray icon from downloaded app icon
327- */
328- async function handleDownloadedTrayIcon (
329- appName : string ,
330- configDir : string ,
331- ) : Promise < string > {
332- const defaultPath = 'icons/icon.png' ;
333- const homeDir = getUserHomeDir ( ) ;
334- const downloadedIconPath = path . join (
335- homeDir ,
336- '.pake' ,
337- 'icons' ,
338- 'downloaded-icon.png' ,
339- ) ;
340-
341- if ( ! ( await fsExtra . pathExists ( downloadedIconPath ) ) ) {
342- logger . warn (
343- `✼ No downloaded icon found, using default icon for system tray.` ,
344- ) ;
345- return defaultPath ;
346- }
347-
348- try {
349- const trayPngPath = path . join (
350- configDir ,
351- `png/${ appName . toLowerCase ( ) } _tray.png` ,
352- ) ;
353- await fsExtra . ensureDir ( path . dirname ( trayPngPath ) ) ;
354-
355- // Resize the original PNG to appropriate tray size (32x32 for optimal display)
356- const sharp = await import ( 'sharp' ) ;
357- await sharp
358- . default ( downloadedIconPath )
359- . resize ( 32 , 32 )
360- . png ( )
361- . toFile ( trayPngPath ) ;
362-
363- const relativePath = `.pake/png/${ appName . toLowerCase ( ) } _tray.png` ;
364- logger . info ( `✓ Using downloaded app icon for system tray: ${ relativePath } ` ) ;
365- return relativePath ;
366- } catch ( error ) {
367- logger . warn ( `✼ Failed to process downloaded icon for tray: ${ error } ` ) ;
368- logger . warn ( `✼ Using default icon for system tray.` ) ;
369- return defaultPath ;
370- }
371- }
0 commit comments