:3
This commit is contained in:
parent
a743cdabe5
commit
bd402f57f5
276 changed files with 37936 additions and 22932 deletions
|
@ -45,8 +45,35 @@ u64 MeminfoParse(std::ifstream input) {
|
|||
return num;
|
||||
}
|
||||
|
||||
u64 GetMemInfo() {
|
||||
return MeminfoParse(std::ifstream("/proc/meminfo")) * 1024;
|
||||
u64 GetMemInfo() { return MeminfoParse(std::ifstream("/proc/meminfo")) * 1024; }
|
||||
|
||||
const char* GetOSVersion() {
|
||||
static std::string prettyName;
|
||||
|
||||
std::ifstream file("/etc/os-release");
|
||||
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Failed to open /etc/os-release" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
if (line.find("PRETTY_NAME=") == 0) {
|
||||
// Remove the "PRETTY_NAME=" part and any surrounding quotes
|
||||
prettyName = line.substr(12);
|
||||
|
||||
if (!prettyName.empty() && prettyName.front() == '"' &&
|
||||
prettyName.back() == '"')
|
||||
prettyName = prettyName.substr(1, prettyName.size() - 2);
|
||||
|
||||
file.close();
|
||||
return prettyName.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetMprisPlayers(sdbus::IConnection& connection) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include "macos/now_playing_bridge.h"
|
||||
#include "macos/bridge.h"
|
||||
#include "os.h"
|
||||
|
||||
u64 GetMemInfo() {
|
||||
|
@ -22,4 +22,6 @@ std::string GetNowPlaying() {
|
|||
return "No song playing";
|
||||
}
|
||||
|
||||
const char* GetOSVersion() { return GetMacOSVersion(); };
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NowPlayingBridge : NSObject
|
||||
@interface Bridge : NSObject
|
||||
+ (NSDictionary*)currentPlayingMetadata;
|
||||
+ (NSString*)macOSVersion;
|
||||
@end
|
||||
#else
|
||||
extern "C" {
|
||||
const char* GetCurrentPlayingTitle();
|
||||
const char* GetCurrentPlayingArtist();
|
||||
const char* GetMacOSVersion();
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,14 +1,13 @@
|
|||
#ifdef __APPLE__
|
||||
|
||||
#import "now_playing_bridge.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "bridge.h"
|
||||
#import <dispatch/dispatch.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
using MRMediaRemoteGetNowPlayingInfoFunction = void (*)(
|
||||
dispatch_queue_t queue, void (^handler)(NSDictionary *information));
|
||||
|
||||
@implementation NowPlayingBridge
|
||||
@implementation Bridge
|
||||
|
||||
+ (NSDictionary *)currentPlayingMetadata {
|
||||
#pragma clang diagnostic push
|
||||
|
@ -58,11 +57,21 @@ using MRMediaRemoteGetNowPlayingInfoFunction = void (*)(
|
|||
return nowPlayingInfo;
|
||||
}
|
||||
|
||||
+ (NSString *)macOSVersion {
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
NSOperatingSystemVersion osVersion = [processInfo operatingSystemVersion];
|
||||
NSString *version =
|
||||
[NSString stringWithFormat:@"%ld.%ld.%ld", (long)osVersion.majorVersion,
|
||||
(long)osVersion.minorVersion,
|
||||
(long)osVersion.patchVersion];
|
||||
return version;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
extern "C" {
|
||||
const char *GetCurrentPlayingTitle() {
|
||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||
NSDictionary *metadata = [Bridge currentPlayingMetadata];
|
||||
|
||||
if (metadata == nil)
|
||||
return nullptr;
|
||||
|
@ -77,7 +86,7 @@ const char *GetCurrentPlayingTitle() {
|
|||
}
|
||||
|
||||
const char *GetCurrentPlayingArtist() {
|
||||
NSDictionary *metadata = [NowPlayingBridge currentPlayingMetadata];
|
||||
NSDictionary *metadata = [Bridge currentPlayingMetadata];
|
||||
|
||||
if (metadata == nil)
|
||||
return nullptr;
|
||||
|
@ -90,6 +99,15 @@ const char *GetCurrentPlayingArtist() {
|
|||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char *GetMacOSVersion() {
|
||||
NSString *version = [Bridge macOSVersion];
|
||||
if (version) {
|
||||
return strdup([version UTF8String]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -6,3 +6,4 @@
|
|||
|
||||
u64 GetMemInfo();
|
||||
std::string GetNowPlaying();
|
||||
const char* GetOSVersion();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue