import { ipcMain } from "electron";
import os from "os";
import {machineId} from 'node-machine-id';


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;
        /**
         * Fix device name
         */
        deviceName += cpuModel.replace("Apple", "").replace("Processor", "").replace("Silicon", "ARM");
    }

    return deviceName.trim();
});


ipcMain.handle('device:id', async () => {
    return await machineId();
});