start updating macos stuff
This commit is contained in:
parent
a02ffbed47
commit
46074a94a2
10
src/main.cpp
10
src/main.cpp
|
@ -123,13 +123,11 @@ namespace {
|
|||
using namespace ftxui;
|
||||
|
||||
fn CreateColorCircles() -> Element {
|
||||
Elements circles;
|
||||
Elements circles(16);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
circles.push_back(hbox({
|
||||
text("◯") | bold | color(Color::Palette256(i)),
|
||||
text(" "),
|
||||
}));
|
||||
std::generate_n(circles.begin(), 16, [colorIndex = 0]() mutable {
|
||||
return hbox({ text("◯") | bold | color(Color::Palette256(colorIndex++)), text(" ") });
|
||||
});
|
||||
|
||||
return hbox(circles);
|
||||
}
|
||||
|
|
|
@ -7,26 +7,26 @@
|
|||
#include "macos/bridge.h"
|
||||
#include "os.h"
|
||||
|
||||
fn GetMemInfo() -> std::expected<u64, string> {
|
||||
fn GetMemInfo() -> expected<u64, string> {
|
||||
u64 mem = 0;
|
||||
usize size = sizeof(mem);
|
||||
|
||||
if (sysctlbyname("hw.memsize", &mem, &size, nullptr, 0) == -1)
|
||||
return std::unexpected(std::string("sysctlbyname failed: ") + strerror(errno));
|
||||
return std::unexpected(string("sysctlbyname failed: ") + strerror(errno));
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
fn GetNowPlaying() -> string {
|
||||
fn GetNowPlaying() -> expected<string, NowPlayingError> {
|
||||
if (const char* title = GetCurrentPlayingTitle(); const char* artist = GetCurrentPlayingArtist())
|
||||
return "Now Playing: " + string(artist) + " - " + string(title);
|
||||
|
||||
return "No song playing";
|
||||
}
|
||||
|
||||
fn GetOSVersion() -> string { return GetMacOSVersion(); }
|
||||
fn GetOSVersion() -> expected<string, string> { return GetMacOSVersion(); }
|
||||
|
||||
fn GetDesktopEnvironment() -> string { return "Aqua"; }
|
||||
fn GetDesktopEnvironment() -> optional<string> { return std::nullopt; }
|
||||
|
||||
fn GetWindowManager() -> string { return "Yabai"; }
|
||||
|
||||
|
|
|
@ -7,18 +7,19 @@
|
|||
#ifdef __OBJC__
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <expected>
|
||||
|
||||
@interface Bridge : NSObject
|
||||
+ (NSDictionary*)currentPlayingMetadata;
|
||||
+ (NSString*)macOSVersion;
|
||||
+ (std::expected<const char*, const char*>)macOSVersion;
|
||||
@end
|
||||
|
||||
#else
|
||||
|
||||
extern "C" {
|
||||
extern "C++" {
|
||||
fn GetCurrentPlayingTitle() -> const char*;
|
||||
fn GetCurrentPlayingArtist() -> const char*;
|
||||
fn GetMacOSVersion() -> const char*;
|
||||
fn GetMacOSVersion() -> std::expected<const char*, const char*>;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifdef __APPLE__
|
||||
|
||||
#import <dispatch/dispatch.h>
|
||||
#include <expected>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#import "bridge.h"
|
||||
|
@ -57,36 +58,34 @@ using MRMediaRemoteGetNowPlayingInfoFunction =
|
|||
return nowPlayingInfo;
|
||||
}
|
||||
|
||||
+ (NSString*)macOSVersion {
|
||||
+ (std::expected<const char*, const char*>)macOSVersion {
|
||||
NSProcessInfo* processInfo = [NSProcessInfo processInfo];
|
||||
|
||||
NSOperatingSystemVersion osVersion = [processInfo operatingSystemVersion];
|
||||
|
||||
NSString* version = nullptr;
|
||||
if (osVersion.patchVersion == 0) {
|
||||
version = [NSString stringWithFormat:@"%ld.%ld", osVersion.majorVersion, osVersion.minorVersion];
|
||||
} else {
|
||||
version = [NSString
|
||||
// Build version number string
|
||||
NSString* versionNumber = nullptr;
|
||||
if (osVersion.patchVersion == 0)
|
||||
versionNumber = [NSString stringWithFormat:@"%ld.%ld", osVersion.majorVersion, osVersion.minorVersion];
|
||||
else
|
||||
versionNumber = [NSString
|
||||
stringWithFormat:@"%ld.%ld.%ld", osVersion.majorVersion, osVersion.minorVersion, osVersion.patchVersion];
|
||||
}
|
||||
|
||||
// Dictionary to map macOS versions to their respective names
|
||||
NSDictionary<NSNumber*, NSString*>* versionNames =
|
||||
// Map major version to name
|
||||
NSDictionary* versionNames =
|
||||
@{ @11 : @"Big Sur", @12 : @"Monterey", @13 : @"Ventura", @14 : @"Sonoma", @15 : @"Sequoia" };
|
||||
NSNumber* majorVersion = @(osVersion.majorVersion);
|
||||
NSString* versionName = versionNames[majorVersion];
|
||||
|
||||
NSNumber* majorVersionNumber = @(osVersion.majorVersion);
|
||||
NSString* versionName = versionNames[majorVersionNumber];
|
||||
if (!versionName)
|
||||
return std::unexpected("Unsupported macOS version");
|
||||
|
||||
if (versionName == nil)
|
||||
versionName = @"Unknown";
|
||||
|
||||
NSString* fullVersion = [NSString stringWithFormat:@"macOS %@ %@", version, versionName];
|
||||
|
||||
return fullVersion;
|
||||
NSString* fullVersion = [NSString stringWithFormat:@"macOS %@ %@", versionNumber, versionName];
|
||||
return strdup([fullVersion UTF8String]);
|
||||
}
|
||||
@end
|
||||
|
||||
extern "C" {
|
||||
extern "C++" {
|
||||
// NOLINTBEGIN(misc-use-internal-linkage)
|
||||
fn GetCurrentPlayingTitle() -> const char* {
|
||||
NSDictionary* metadata = [Bridge currentPlayingMetadata];
|
||||
|
||||
|
@ -115,14 +114,8 @@ extern "C" {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
fn GetMacOSVersion() -> const char* {
|
||||
NSString* version = [Bridge macOSVersion];
|
||||
|
||||
if (version)
|
||||
return strdup([version UTF8String]);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
fn GetMacOSVersion() -> std::expected<const char*, const char*> { return [Bridge macOSVersion]; }
|
||||
// NOLINTEND(misc-use-internal-linkage)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue