From b9e35c8f2ff7d77ecb0ccd3f6e5242d7c1469b1e Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Wed, 20 Jan 2021 22:24:36 -0800 Subject: [PATCH] Updated platform check --- modules/win-securitycenter.js | 45 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/modules/win-securitycenter.js b/modules/win-securitycenter.js index 8afb91c..f7c4d73 100644 --- a/modules/win-securitycenter.js +++ b/modules/win-securitycenter.js @@ -71,26 +71,31 @@ function getStatus() return (ret); } -var j = { status: getStatus }; -require('events').EventEmitter.call(j, true) - .createEvent('changed'); -j._H = require('_GenericMarshal').CreatePointer(); -j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1); -j._EV.parent = j; -j._EV.on('GlobalCallback', function (p) +if (process.platform == 'win32' && seccenter != null) { - if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us - this.parent.emit('changed'); -}); -j.on('~', function () -{ - if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { } -}); + var j = { status: getStatus }; + require('events').EventEmitter.call(j, true) + .createEvent('changed'); + j._H = require('_GenericMarshal').CreatePointer(); + j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1); + j._EV.parent = j; + j._EV.on('GlobalCallback', function (p) + { + if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us + this.parent.emit('changed'); + }); + j.on('~', function () + { + if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { } + }); -if(seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0) -{ - j._H = j._H.Deref(); + if (seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0) + { + j._H = j._H.Deref(); + } + module.exports = j; } - - -module.exports = j; \ No newline at end of file +else +{ + throw ('win-securitycenter not supported on this platform'); +} \ No newline at end of file