diff --git a/.resinci.json b/.resinci.json index d1011423..c2932918 100644 --- a/.resinci.json +++ b/.resinci.json @@ -19,6 +19,7 @@ "nodeGypRebuild": true, "afterPack": "./afterPack.js", "files": [ + "build/Release/elevator.node", "generated", "lib/shared/catalina-sudo/sudo-askpass.osascript.js", "lib/gui/app/index.html", diff --git a/electron-builder.yml b/electron-builder.yml index dd42396b..7fbeff85 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -6,6 +6,7 @@ nodeGypRebuild: true publish: null afterPack: "./afterPack.js" files: + - build/Release/elevator.node - generated - lib/shared/catalina-sudo/sudo-askpass.osascript.js - lib/gui/app/index.html diff --git a/lib/shared/native-module.js b/lib/shared/native-module.js deleted file mode 100644 index bbb0c35b..00000000 --- a/lib/shared/native-module.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 resin.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict' - -const path = require('path') -const bindings = require('bindings') - -/** - * @summary Load a native module - * @function - * @public - * - * @param {String} moduleName - native module name - * @returns {Object} native module - * - * @example - * const elevator = nativeModule.load('elevator'); - */ -exports.load = (moduleName) => { - return bindings({ - bindings: moduleName, - - // eslint-disable-next-line camelcase - module_root: path.join(__dirname, '..', '..') - - }) -} diff --git a/lib/shared/permissions.js b/lib/shared/permissions.js index b403007d..c0bbd052 100755 --- a/lib/shared/permissions.js +++ b/lib/shared/permissions.js @@ -18,6 +18,7 @@ 'use strict' +const bindings = require('bindings') const Bluebird = require('bluebird') const childProcess = Bluebird.promisifyAll(require('child_process')) const fs = require('fs') @@ -136,10 +137,9 @@ exports.createLaunchScript = (command, argv, environment) => { } const elevateScriptWindows = async (path) => { - // './nativeModule' imported here as it only exists on windows + // 'elevator' imported here as it only exists on windows // TODO: replace this with sudo-prompt once https://github.com/jorangreef/sudo-prompt/issues/96 is fixed - const nativeModule = require('./native-module') - const elevateAsync = promisify(nativeModule.load('elevator').elevate) + const elevateAsync = promisify(bindings({ bindings: 'elevator' }).elevate) // '&' needs to be escaped here (but not when written to a .cmd file) const cmd = [ 'cmd', '/c', escapeParamCmd(path).replace(/&/g, '^&') ]