mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-22 06:17:20 +00:00

Sentry error reports showcase that elevation errors on Windows are one of the most frequent Windows errors. In order to perform Windows elevation, we ship compiled EXEs of a third party CLI elevation application (http://code.kliu.org/misc/elevate/) that has several limitations: - We have the scan the output of the script to determine if a user cancelled the elevation request, which causes all sorts of issues on computers where English is not the main language - The application displays a `cmd.exe` window for some milliseconds, which is bad UX, that we have to workaround by distributing a patched version of the tool - The CLI application has to be spawned, which seems to be problematic if users have anti-virus software, leading to hard to debug issues - We don't have any control if something goes wrong For these reasons, we decided to implement our own elevation mechanism in C++ as a Node.js add-on, based on the `elevate.exe` code we where previously using. Misc changes: - Introduce a `lib/shared/bindings.js` module to easily require local native add-ons - Install `cpplint` and configure it to lint C++ files Note that for practical reasons, the C++ code lives in this repository rather than in a separate module. We will release this functionality in a more accessible way in the future as part of the Etcher SDK project. Change-Type: patch Changelog-Entry: Fix uncaught errors when cancelling elevation requests on Windows when the system's language is not English. Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
/*
|
|
* 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 = bindings.load('elevator');
|
|
*/
|
|
exports.load = (moduleName) => {
|
|
return bindings({
|
|
bindings: moduleName,
|
|
|
|
/* eslint-disable camelcase */
|
|
|
|
module_root: path.join(__dirname, '..', '..')
|
|
|
|
/* eslint-enable camelcase */
|
|
|
|
});
|
|
};
|