'init'
This commit is contained in:
36
lib/main/ipcs/ipcDevice.ts
Normal file
36
lib/main/ipcs/ipcDevice.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user