1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-15 18:32:33 +01:00
upscayl/electron/utils/get-device-specs.ts

66 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-04 21:29:17 +05:30
"use strict";
2024-12-16 16:18:57 +05:30
import { ipcRenderer } from "electron";
import os from "os";
2023-09-04 21:29:17 +05:30
export const getPlatform = () => {
2024-12-16 16:18:57 +05:30
switch (os.platform()) {
2023-09-04 21:29:17 +05:30
case "aix":
case "freebsd":
case "linux":
case "openbsd":
case "android":
return "linux";
case "darwin":
case "sunos":
return "mac";
case "win32":
return "win";
}
};
export const getArch = () => {
2024-12-16 16:18:57 +05:30
switch (os.arch()) {
2023-09-04 21:29:17 +05:30
case "x64":
return "x64";
case "x32":
return "x86";
case "arm":
return "arm";
case "arm64":
return "arm64";
}
};
2024-12-16 16:18:57 +05:30
export const getAppVersion = async () => {
let appVersion = process.env.npm_package_version;
try {
appVersion = await ipcRenderer.invoke("get-app-version");
} catch (error) {
console.error("Failed to get app version:", error);
}
return appVersion;
};
export const getDeviceSpecs = async () => {
let gpuInfo;
try {
gpuInfo = await ipcRenderer.invoke("get-gpu-info");
} catch (error) {
console.error("Failed to get GPU info:", error);
gpuInfo = null;
}
const deviceSpecs = {
2024-12-16 16:18:57 +05:30
platform: getPlatform(),
release: os.release(),
arch: getArch(),
model: os.cpus()[0].model.trim(),
cpuCount: os.cpus().length,
...(gpuInfo && { gpu: gpuInfo.gpuDevice[0] }),
};
return deviceSpecs;
2024-12-16 16:18:57 +05:30
};