From 37b1d0126d352cac4f44dfffffeeeca83c9317f1 Mon Sep 17 00:00:00 2001 From: SySyAli Date: Sat, 6 Jan 2024 00:28:33 -0500 Subject: [PATCH] Linting and Fixing CMakeLists.txt. --- CMakeLists.txt | 23 +++++++++++------------ IWindowInterface.cpp | 13 ++++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7562826..c56796f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,23 +50,22 @@ add_executable(desktop_screentime main.cpp IWindowInterface.cpp ) -# Link SQLite3 to the executable -target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES}) - - -# Link pthread and X11 for Linux -if(UNIX AND NOT APPLE) +# Link libraries to the executable +if(MSVC) + # Using Microsoft Visual C++ + target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES}) +elseif(APPLE) + # For macOS, link Application Services framework + target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} "-framework ApplicationServices") +elseif(UNIX AND NOT APPLE) + # For Linux, link pthread and possibly X11 if(X11_FOUND) - target_link_libraries(desktop_screentime PRIVATE ${X11_LIBRARIES} pthread) + target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} ${X11_LIBRARIES} pthread) else() - target_link_libraries(desktop_screentime PRIVATE pthread) + target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} pthread) endif() endif() -# Link Application Services for macOS -if(APPLE) - target_link_libraries(desktop_screentime "-framework ApplicationServices") -endif() # Testing Executable # Define the source files and dependencies for the executable diff --git a/IWindowInterface.cpp b/IWindowInterface.cpp index 7d35696..f2b39cc 100644 --- a/IWindowInterface.cpp +++ b/IWindowInterface.cpp @@ -172,8 +172,10 @@ void LinuxTracker::startTracking() #ifdef __APPLE__ -std::string getActiveWindowTitleMac() { - CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); +std::string getActiveWindowTitleMac() +{ + CFArrayRef windowList + = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); if (windowList) { for (CFIndex i = 0; i < CFArrayGetCount(windowList); i++) { CFDictionaryRef windowInfo = (CFDictionaryRef)CFArrayGetValueAtIndex(windowList, i); @@ -181,7 +183,8 @@ std::string getActiveWindowTitleMac() { int layer; CFNumberGetValue(windowLayer, kCFNumberIntType, &layer); if (layer == 0) { // Check if it's the active window layer - CFStringRef windowTitle = (CFStringRef)CFDictionaryGetValue(windowInfo, kCGWindowName); + CFStringRef windowTitle + = (CFStringRef)CFDictionaryGetValue(windowInfo, kCGWindowName); if (windowTitle) { char title[256]; CFStringGetCString(windowTitle, title, 256, kCFStringEncodingUTF8); @@ -195,7 +198,8 @@ std::string getActiveWindowTitleMac() { return ""; } -void MacOSTracker::startTracking() { +void MacOSTracker::startTracking() +{ AppEntry prevEntry; while (tracking) { std::string title = getActiveWindowTitleMac(); @@ -236,6 +240,5 @@ void MacOSTracker::startTracking() { std::this_thread::sleep_for(std::chrono::seconds(1)); } - } #endif