66 getIcons ,
77 refreshDirectoryIcons as refreshIconsCommand ,
88 clearExtensionIconCache as clearExtensionIconCacheCommand ,
9+ clearDirectoryIconCache as clearDirectoryIconCacheCommand ,
910} from './tauri-commands'
1011
1112const STORAGE_KEY = 'cmdr-icon-cache'
@@ -20,10 +21,11 @@ const memoryCache = new Map<string, string>()
2021export const iconCacheVersion = writable ( 0 )
2122
2223/**
23- * Reactive counter that increments when extension icon cache is cleared.
24+ * Reactive counter that increments when part of the icon cache is cleared
25+ * (extension icons, directory icons, etc.).
2426 * List components subscribe to this to re-fetch icons for visible files.
2527 */
26- export const extensionCacheCleared = writable ( 0 )
28+ export const iconCacheCleared = writable ( 0 )
2729
2830/** Load persisted cache from localStorage */
2931function loadFromStorage ( ) : void {
@@ -153,8 +155,27 @@ export async function clearExtensionIconCache(): Promise<void> {
153155 // Notify list components to re-fetch icons for visible files
154156 // This must happen BEFORE incrementing iconCacheVersion so components
155157 // can re-fetch before re-rendering with the cleared cache
156- extensionCacheCleared . update ( ( v ) => v + 1 )
158+ iconCacheCleared . update ( ( v ) => v + 1 )
157159
158160 // Trigger reactive update so components re-fetch icons
159161 iconCacheVersion . update ( ( v ) => v + 1 )
160162}
163+
164+ /**
165+ * Clears all cached directory icons from both memory and localStorage.
166+ * Called when the system theme or accent color changes, since macOS renders
167+ * folder icons with the current accent color baked in.
168+ */
169+ export async function clearDirectoryIconCache ( ) : Promise < void > {
170+ await clearDirectoryIconCacheCommand ( )
171+
172+ for ( const key of memoryCache . keys ( ) ) {
173+ if ( key === 'dir' || key === 'symlink-dir' || key . startsWith ( 'path:' ) ) {
174+ memoryCache . delete ( key )
175+ }
176+ }
177+
178+ saveToStorage ( )
179+ iconCacheCleared . update ( ( v ) => v + 1 )
180+ iconCacheVersion . update ( ( v ) => v + 1 )
181+ }
0 commit comments