@el3um4s/ipc-for-electron-system-info
Version:
Allow the renderer to get information about the version of Electron, Chrome and NodeJS used
65 lines (64 loc) • 2.89 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const nameAPI = "systemInfo";
const defaultApiKey = "ipc";
const getSystemInfo = (options) => __awaiter(void 0, void 0, void 0, function* () {
const { callback } = options;
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || defaultApiKey;
const api = globalThis[apiKey][nameAPI];
return new Promise((resolve) => {
api.receive("getSystemInfo", (data) => {
const { chrome, node, electron, app } = data;
if (callback) {
callback({ chrome, node, electron, app });
}
resolve({ chrome, node, electron, app });
});
});
});
const requestSystemInfo = (options) => __awaiter(void 0, void 0, void 0, function* () {
const { callback } = options;
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || defaultApiKey;
const api = globalThis[apiKey][nameAPI];
api.send("requestSystemInfo", null);
return getSystemInfo({ callback, apiKey });
});
const getIsWindows = (options) => __awaiter(void 0, void 0, void 0, function* () {
const { callback } = options;
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || defaultApiKey;
const api = globalThis[apiKey][nameAPI];
return new Promise((resolve) => {
api.receive("getIsWindows", (data) => {
const { isWindows } = data;
if (callback) {
callback({ isWindows });
}
resolve({ isWindows });
});
});
});
const requestIsWindows = (options) => __awaiter(void 0, void 0, void 0, function* () {
const { callback } = options;
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || defaultApiKey;
const api = globalThis[apiKey][nameAPI];
api.send("requestIsWindows", null);
return getIsWindows({ callback, apiKey });
});
const renderer = {
requestSystemInfo,
requestIsWindows,
on: {
getSystemInfo,
getIsWindows,
},
};
exports.default = renderer;