mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-01 18:42:56 +01:00
Uptime: support Windows
This commit is contained in:
@@ -316,6 +316,7 @@ if(LINUX OR ANDROID OR BSD)
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
src/detection/processes/processes_linux.c
|
||||
src/detection/uptime/uptime_linux.c
|
||||
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
)
|
||||
@@ -370,6 +371,7 @@ if(MSYS)
|
||||
src/detection/packages/packages_windows.c
|
||||
src/detection/kernel/kernel_windows.cpp
|
||||
src/detection/localip/localip_windows.c
|
||||
src/detection/uptime/uptime_windows.c
|
||||
src/util/windows/wmi.cpp
|
||||
|
||||
src/detection/poweradapter/poweradapter_nosupport.c
|
||||
@@ -398,6 +400,7 @@ if(APPLE)
|
||||
src/detection/font/font_apple.m
|
||||
src/detection/opengl/opengl_apple.c
|
||||
src/detection/processes/processes_apple.c
|
||||
src/detection/uptime/uptime_apple.c
|
||||
|
||||
src/detection/bios/bios_nosupport.c
|
||||
src/detection/board/board_nosupport.c
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_uptime_uptime
|
||||
#define FF_INCLUDED_detection_uptime_uptime
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
uint64_t ffDetectUptime(const FFinstance* instance);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "uptime.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
uint64_t ffDetectUptime(const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance)
|
||||
struct timeval bootTime;
|
||||
size_t bootTimeSize = sizeof(bootTime);
|
||||
if(sysctl(
|
||||
(int[]) {CTL_KERN, KERN_BOOTTIME}, 2,
|
||||
&bootTime, &bootTimeSize,
|
||||
NULL, 0
|
||||
) == 0)
|
||||
return (uint64_t) difftime(time(NULL), bootTime.tv_sec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "uptime.h"
|
||||
|
||||
uint64_t ffDetectUptime(const FFinstance* instance)
|
||||
{
|
||||
#if FF_HAVE_SYSINFO_H
|
||||
return (uint64_t) instance->state.sysinfo.uptime;
|
||||
#else
|
||||
FF_UNUSED(instance)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "uptime.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <sysinfoapi.h>
|
||||
|
||||
uint64_t ffDetectUptime(const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance)
|
||||
return GetTickCount64() / 1000;
|
||||
}
|
||||
+2
-23
@@ -1,34 +1,13 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
|
||||
#if __APPLE__
|
||||
#include "time.h"
|
||||
#include "sys/sysctl.h"
|
||||
#endif
|
||||
#include "detection/uptime/uptime.h"
|
||||
|
||||
#define FF_UPTIME_MODULE_NAME "Uptime"
|
||||
#define FF_UPTIME_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintUptime(FFinstance* instance)
|
||||
{
|
||||
uint64_t uptime;
|
||||
|
||||
#if FF_HAVE_SYSINFO_H
|
||||
uptime = (uint64_t) instance->state.sysinfo.uptime;
|
||||
#elif __APPLE__
|
||||
struct timeval bootTime;
|
||||
size_t bootTimeSize = sizeof(bootTime);
|
||||
if(sysctl(
|
||||
(int[]) {CTL_KERN, KERN_BOOTTIME}, 2,
|
||||
&bootTime, &bootTimeSize,
|
||||
NULL, 0
|
||||
) == 0)
|
||||
uptime = (uint64_t) difftime(time(NULL), bootTime.tv_sec);
|
||||
else
|
||||
uptime = 0;
|
||||
#else
|
||||
uptime = 0;
|
||||
#endif
|
||||
uint64_t uptime = ffDetectUptime(instance);
|
||||
|
||||
if(uptime == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user