Fix issue with macstats on mac
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import si from 'systeminformation';
|
||||
import { createRequire } from 'module';
|
||||
import os from 'os';
|
||||
import { CpuInfo } from '@/types';
|
||||
import { cached } from '@/server/apiCache';
|
||||
import { loadMacstats } from '@/server/macstats';
|
||||
|
||||
const isMac = os.platform() === 'darwin';
|
||||
|
||||
@@ -13,8 +13,8 @@ async function getCpuInfo(): Promise<CpuInfo> {
|
||||
|
||||
if (isMac) {
|
||||
try {
|
||||
const nativeRequire = createRequire(import.meta.url);
|
||||
const ms = nativeRequire('macstats') as any;
|
||||
const ms = loadMacstats();
|
||||
if (!ms) throw new Error('macstats unavailable');
|
||||
const ramData = ms.getRAMUsageSync();
|
||||
const cpuData = ms.getCpuDataSync();
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import { createRequire } from 'module';
|
||||
import os from 'os';
|
||||
import { cached } from '@/server/apiCache';
|
||||
import { loadMacstats } from '@/server/macstats';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
@@ -47,11 +47,8 @@ async function getMacGpuInfo(): Promise<MacGpuResult | null> {
|
||||
let memUsed = 0;
|
||||
let memTotal = memoryTotal;
|
||||
|
||||
try {
|
||||
// Use createRequire to hide from webpack static analysis so it doesn't fail on non-mac platforms
|
||||
const nativeRequire = createRequire(import.meta.url);
|
||||
const ms = nativeRequire('macstats') as any;
|
||||
|
||||
const ms = loadMacstats();
|
||||
if (ms) {
|
||||
try {
|
||||
const gpuData = ms.getGpuDataSync();
|
||||
temperature = gpuData.temperature || 0;
|
||||
@@ -84,8 +81,6 @@ async function getMacGpuInfo(): Promise<MacGpuResult | null> {
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('macstats not available:', error);
|
||||
}
|
||||
|
||||
return { name: gpuName, memUsed, memTotal, gpuLoad, temperature, fanSpeed, powerDraw };
|
||||
|
||||
Reference in New Issue
Block a user