:3
This commit is contained in:
parent
a743cdabe5
commit
bd402f57f5
276 changed files with 37936 additions and 22932 deletions
|
@ -1,9 +1,7 @@
|
|||
#include "config.h"
|
||||
|
||||
#define DEFINE_GETTER(class_name, type, name) \
|
||||
type class_name::get##name() const { \
|
||||
return m_##name; \
|
||||
}
|
||||
type class_name::get##name() const { return m_##name; }
|
||||
|
||||
DEFINE_GETTER(Config, const General, General)
|
||||
DEFINE_GETTER(Config, const NowPlaying, NowPlaying)
|
||||
|
@ -42,26 +40,20 @@ WeatherImpl WeatherImpl::from_class(const Weather& weather) noexcept {
|
|||
};
|
||||
}
|
||||
|
||||
Weather WeatherImpl::to_class() const {
|
||||
return {location, api_key, units};
|
||||
}
|
||||
Weather WeatherImpl::to_class() const { return {location, api_key, units}; }
|
||||
|
||||
GeneralImpl GeneralImpl::from_class(const General& general) noexcept {
|
||||
return {general.getName()};
|
||||
}
|
||||
|
||||
General GeneralImpl::to_class() const {
|
||||
return {name};
|
||||
}
|
||||
General GeneralImpl::to_class() const { return {name}; }
|
||||
|
||||
NowPlayingImpl NowPlayingImpl::from_class(
|
||||
const NowPlaying& now_playing) noexcept {
|
||||
return {.enabled = now_playing.getEnabled()};
|
||||
}
|
||||
|
||||
NowPlaying NowPlayingImpl::to_class() const {
|
||||
return {enabled};
|
||||
}
|
||||
NowPlaying NowPlayingImpl::to_class() const { return {enabled}; }
|
||||
|
||||
ConfigImpl ConfigImpl::from_class(const Config& config) noexcept {
|
||||
return {
|
||||
|
@ -71,6 +63,4 @@ ConfigImpl ConfigImpl::from_class(const Config& config) noexcept {
|
|||
};
|
||||
}
|
||||
|
||||
Config ConfigImpl::to_class() const {
|
||||
return {general, now_playing, weather};
|
||||
}
|
||||
Config ConfigImpl::to_class() const { return {general, now_playing, weather}; }
|
||||
|
|
|
@ -80,5 +80,7 @@ int main() {
|
|||
|
||||
fmt::println("It is {}°F in {}", temp, townName);
|
||||
|
||||
fmt::println("{}", GetOSVersion());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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