mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 20:24:19 +01:00
Battery: add dirty support for macOS
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "cfdict_helpers.h"
|
||||
|
||||
const void* ffCfDictGetValue(CFMutableDictionaryRef dict, const char* key)
|
||||
{
|
||||
CFStringRef cfKey = CFStringCreateWithCStringNoCopy(NULL, key, kCFStringEncodingASCII, kCFAllocatorNull);
|
||||
return CFDictionaryGetValue(dict, cfKey);
|
||||
}
|
||||
|
||||
bool ffCfDictGetString(CFMutableDictionaryRef dict, const char* key, FFstrbuf* result)
|
||||
{
|
||||
CFStringRef cf = (CFStringRef)ffCfDictGetValue(dict, key);
|
||||
if(cf == NULL || CFGetTypeID(cf) != CFStringGetTypeID())
|
||||
return false;
|
||||
|
||||
uint32_t length = (uint32_t)CFStringGetLength(cf);
|
||||
ffStrbufEnsureFree(result, length + 1);
|
||||
if(CFStringGetCString(cf, result->chars, length + 1, kCFStringEncodingASCII))
|
||||
{
|
||||
result->length = length;
|
||||
// CFStringGetCString ensures the buffer is NUL terminated
|
||||
// https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffCfDictGetBool(CFMutableDictionaryRef dict, const char* key, bool* result)
|
||||
{
|
||||
CFBooleanRef cf = (CFBooleanRef)ffCfDictGetValue(dict, key);
|
||||
if(cf == NULL || CFGetTypeID(cf) != CFNumberGetTypeID())
|
||||
return false;
|
||||
|
||||
*result = CFBooleanGetValue(cf);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffCfDictGetInt(CFMutableDictionaryRef dict, const char* key, int* result)
|
||||
{
|
||||
CFNumberRef cf = (CFNumberRef)ffCfDictGetValue(dict, key);
|
||||
if (cf == NULL || CFGetTypeID(cf) != CFStringGetTypeID())
|
||||
return false;
|
||||
|
||||
if(!CFNumberGetValue(cf, kCFNumberSInt32Type, result))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FASTFETCH_INCLUDED_cfdict_helpers
|
||||
#define FASTFETCH_INCLUDED_cfdict_helpers
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
const void* ffCfDictGetValue(CFMutableDictionaryRef dict, const char* str);
|
||||
bool ffCfDictGetString(CFMutableDictionaryRef dict, const char* key, FFstrbuf* result);
|
||||
bool ffCfDictGetBool(CFMutableDictionaryRef dict, const char* key, bool* result);
|
||||
bool ffCfDictGetInt(CFMutableDictionaryRef dict, const char* key, int* result);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user