mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 14:10:11 +01:00
Logo: adds automatic cleanup of temporary media cover files
This commit is contained in:
@@ -17,6 +17,7 @@ const FFMediaResult* ffDetectMedia(bool saveCover)
|
||||
ffStrbufInit(&result.url);
|
||||
ffStrbufInit(&result.status);
|
||||
ffStrbufInit(&result.cover);
|
||||
result.removeCoverAfterUse = false;
|
||||
ffDetectMediaImpl(&result, saveCover);
|
||||
|
||||
if(result.song.length == 0 && result.error.length == 0)
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct FFMediaResult
|
||||
FFstrbuf url;
|
||||
FFstrbuf status;
|
||||
FFstrbuf cover;
|
||||
bool removeCoverAfterUse;
|
||||
} FFMediaResult;
|
||||
|
||||
const FFMediaResult* ffDetectMedia(bool saveCover);
|
||||
|
||||
@@ -44,7 +44,7 @@ static const char* getMediaByMediaRemote(FFMediaResult* result, bool saveCover)
|
||||
FF_CFTYPE_AUTO_RELEASE CFStringRef ext = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
|
||||
#pragma clang diagnostic pop
|
||||
NSString *tmpDir = NSTemporaryDirectory();
|
||||
NSString *uuid = [[NSUUID UUID] UUIDString];
|
||||
NSString *uuid = NSUUID.UUID.UUIDString;
|
||||
NSString *path = [tmpDir stringByAppendingPathComponent:[NSString stringWithFormat:@"ff_%@.%@", uuid, ext ? (__bridge NSString *) ext : @"img"]];
|
||||
if ([artworkData writeToFile:path atomically:NO])
|
||||
ffStrbufSetS(&result->cover, path.UTF8String);
|
||||
@@ -160,5 +160,7 @@ void ffDetectMediaImpl(FFMediaResult* media, bool saveCover)
|
||||
if (ffStrbufStartsWithIgnCaseS(&media->player, "com."))
|
||||
ffStrbufSubstrAfter(&media->player, strlen("com.") - 1);
|
||||
ffStrbufReplaceAllC(&media->player, '.', ' ');
|
||||
if (media->cover.length > 0)
|
||||
media->removeCoverAfterUse = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ static const char* getMedia(FFMediaResult* media, bool saveCover)
|
||||
ffStrbufSetWS(&media->album, result.album);
|
||||
ffStrbufSetWS(&media->cover, result.cover);
|
||||
ffStrbufSetStatic(&media->status, result.status);
|
||||
if (media->cover.length > 0)
|
||||
media->removeCoverAfterUse = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user