36 lines
835 B
TypeScript
36 lines
835 B
TypeScript
import { ipcMain } from "electron";
|
|
import os from "os";
|
|
import {machineId} from 'node-machine-id';
|
|
|
|
/**
|
|
* Consturct device name.
|
|
* Ex: Macbook Pro M3
|
|
*/
|
|
ipcMain.handle('device:name', () => {
|
|
const type = os.type(); // 'Darwin', 'Windows_NT', 'Linux'
|
|
|
|
let deviceName = "";
|
|
|
|
if (type === "Darwin") {
|
|
deviceName += "Mac";
|
|
} else if (type === "Windows_NT") {
|
|
deviceName += "Windows";
|
|
} else if (type === "Linux") {
|
|
deviceName += "Linux";
|
|
} else {
|
|
deviceName += type + " ";
|
|
}
|
|
|
|
const cpus = os.cpus();
|
|
if (cpus && cpus.length > 0) {
|
|
const cpuModel = cpus[0].model;
|
|
deviceName += cpuModel.replace("Apple", "").replace("Processor", "");
|
|
}
|
|
|
|
return deviceName.trim();
|
|
});
|
|
|
|
|
|
ipcMain.handle('device:id', async () => {
|
|
return await machineId();
|
|
}); |