From 2cb73ba85cf14aba369c0e3961905d569dae525a Mon Sep 17 00:00:00 2001 From: Sudheer gupta Date: Mon, 11 Nov 2024 13:25:01 +0530 Subject: [PATCH] bind for required plateform --- lib/binding.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/binding.js b/lib/binding.js index d911034..6132d36 100644 --- a/lib/binding.js +++ b/lib/binding.js @@ -1,4 +1,31 @@ -const addon = require('./electron_printer.node'); +const path = require('path'); +const os = require('os'); +let addon = {}, binary_path; +switch (os.platform()) { + case 'win32': + if (os.arch() === 'ia32') { + binary_path = path.join(__dirname, 'electron_printer_win32_ia32.node'); + } else if (os.arch() === 'x64') { + binary_path = path.join(__dirname, 'electron_printer_win32_x64.node'); + } + addon = require(binary_path); + break; + case 'darwin': + binary_path = path.join(__dirname, 'electron_printer.node'); + addon = require(binary_path); + break; + case 'linux': + if (os.arch() === 'ia32') { + addon = path.join(__dirname, 'electron_printer.node'); + } else if (os.arch() === 'x64') { + addon = path.join(__dirname, 'electron_printer.node'); + } + break; + default: + binary_path = path.join(__dirname, 'electron_printer.node'); + addon = require(binary_path); +} + module.exports.sayMyName = addon.SayMyName module.exports.getPrinters = addon.getPrinters module.exports.printDirect = printDirect