i think this is better

This commit is contained in:
Mars 2025-02-18 13:28:51 -05:00
parent 8cbc00372d
commit ea6bf62c90
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
5 changed files with 143 additions and 72 deletions

View file

@ -1,17 +1,18 @@
#ifdef __APPLE__
#include <expected>
#include <map>
#include <sys/sysctl.h>
#include <sys/utsname.h>
#include "macos/bridge.h"
#include "os.h"
fn GetMemInfo() -> u64 {
fn GetMemInfo() -> std::expected<u64, string> {
u64 mem = 0;
usize size = sizeof(mem);
sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
if (sysctlbyname("hw.memsize", &mem, &size, nullptr, 0) == -1)
return std::unexpected(std::string("sysctlbyname failed: ") + strerror(errno));
return mem;
}
@ -27,9 +28,11 @@ fn GetOSVersion() -> string { return GetMacOSVersion(); }
fn GetDesktopEnvironment() -> string { return "Aqua"; }
fn GetWindowManager() -> string { return "Yabai"; }
fn GetKernelVersion() -> string {
std::array<char, 256> kernelVersion;
size_t kernelVersionLen = sizeof(kernelVersion);
usize kernelVersionLen = sizeof(kernelVersion);
sysctlbyname("kern.osrelease", kernelVersion.data(), &kernelVersionLen, nullptr, 0);
@ -42,7 +45,7 @@ fn GetHost() -> string {
sysctlbyname("hw.model", hwModel.data(), &hwModelLen, nullptr, 0);
// shamelessly stolen from https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/host/host_mac.c
// taken from https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/host/host_mac.c
// shortened a lot of the entries to remove unnecessary info
std::map<std::string, std::string> modelNameByHwModel = {
// MacBook Pro

View file

@ -5,20 +5,19 @@
#import "bridge.h"
#include "../../util/macros.h"
using MRMediaRemoteGetNowPlayingInfoFunction =
void (*)(dispatch_queue_t queue, void (^handler)(NSDictionary* information));
@implementation Bridge
+ (NSDictionary*)currentPlayingMetadata {
CFURLRef ref = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault,
CFSTR("/System/Library/PrivateFrameworks/MediaRemote.framework"),
kCFURLPOSIXPathStyle,
false
kCFAllocatorDefault, CFSTR("/System/Library/PrivateFrameworks/MediaRemote.framework"), kCFURLPOSIXPathStyle, false
);
if (!ref) {
NSLog(@"Failed to load MediaRemote framework");
ERROR_LOG("Failed to load MediaRemote framework");
return nil;
}
@ -26,17 +25,16 @@ using MRMediaRemoteGetNowPlayingInfoFunction =
CFRelease(ref);
if (!bundle) {
NSLog(@"Failed to load MediaRemote framework");
ERROR_LOG("Failed to load MediaRemote framework");
return nil;
}
MRMediaRemoteGetNowPlayingInfoFunction mrMediaRemoteGetNowPlayingInfo =
reinterpret_cast<MRMediaRemoteGetNowPlayingInfoFunction>(
CFBundleGetFunctionPointerForName(bundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"))
);
auto mrMediaRemoteGetNowPlayingInfo = std::bit_cast<MRMediaRemoteGetNowPlayingInfoFunction>(
CFBundleGetFunctionPointerForName(bundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"))
);
if (!mrMediaRemoteGetNowPlayingInfo) {
NSLog(@"Failed to get function pointer for MRMediaRemoteGetNowPlayingInfo");
ERROR_LOG("Failed to get function pointer for MRMediaRemoteGetNowPlayingInfo");
CFRelease(bundle);
return nil;
}
@ -55,6 +53,7 @@ using MRMediaRemoteGetNowPlayingInfoFunction =
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
CFRelease(bundle);
return nowPlayingInfo;
}
@ -63,15 +62,12 @@ using MRMediaRemoteGetNowPlayingInfoFunction =
NSOperatingSystemVersion osVersion = [processInfo operatingSystemVersion];
NSString* version;
NSString* version = nullptr;
if (osVersion.patchVersion == 0) {
version =
[NSString stringWithFormat:@"%ld.%ld", osVersion.majorVersion, osVersion.minorVersion];
version = [NSString stringWithFormat:@"%ld.%ld", osVersion.majorVersion, osVersion.minorVersion];
} else {
version = [NSString stringWithFormat:@"%ld.%ld.%ld",
osVersion.majorVersion,
osVersion.minorVersion,
osVersion.patchVersion];
version = [NSString
stringWithFormat:@"%ld.%ld.%ld", osVersion.majorVersion, osVersion.minorVersion, osVersion.patchVersion];
}
// Dictionary to map macOS versions to their respective names