fix(developers): Refactor windows detection.

This commit is contained in:
Quentin Decaunes 2019-08-17 17:40:48 +02:00
parent 029ffc2be9
commit 89f9950b59
2 changed files with 11 additions and 4 deletions

View File

@ -15,7 +15,7 @@ ready(function(){
checkForAdminRights(); checkForAdminRights();
displayVersion(); displayVersion();
reApplyPeriodically(require('electron-settings').get('settings.reapply_periodically')); reApplyPeriodically(require('electron-settings').get('settings.reapply_periodically'));
if (require('os').platform() === 'win32' && isDevMode()) { if (isWindows() && isDevMode()) {
recreateShortcut(); recreateShortcut();
} }
handlePlatformSpecificDisplay(); handlePlatformSpecificDisplay();

View File

@ -193,7 +193,7 @@ function registerRepeaterForAllInput() {
* Will display a warning if not. * Will display a warning if not.
*/ */
function checkForAdminRights() { function checkForAdminRights() {
if (require('os').platform() !== 'win32') { if (!isWindows()) {
const isRoot = process.getuid && process.getuid() === 0; const isRoot = process.getuid && process.getuid() === 0;
if (!isRoot) { if (!isRoot) {
notification('danger', notification('danger',
@ -214,6 +214,13 @@ function checkForAdminRights() {
} }
} }
/**
* Check that the app is running on Windows.
*/
function isWindows() {
return require('os').platform() === 'win32';
}
/** /**
* Will display a notification in ".notification-zone". * Will display a notification in ".notification-zone".
* @param {string} type "primary", "warning", "danger" or "success". * @param {string} type "primary", "warning", "danger" or "success".
@ -235,7 +242,7 @@ function notification(type, message) {
function getRyzenAdjExecutablePath() { function getRyzenAdjExecutablePath() {
const settings = require('electron-settings'); const settings = require('electron-settings');
var ryzen_adj_path = settings.get('settings.ryzen_adj_path'); var ryzen_adj_path = settings.get('settings.ryzen_adj_path');
if (!ryzen_adj_path && require('os').platform() === 'win32') { if (!ryzen_adj_path && isWindows()) {
ryzen_adj_path = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe"; ryzen_adj_path = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe";
} }
appendLog(`getRyzenAdjExecutablePath(): "${ryzen_adj_path}"`); appendLog(`getRyzenAdjExecutablePath(): "${ryzen_adj_path}"`);
@ -622,7 +629,7 @@ function toggleHpet(value) {
*/ */
function handlePlatformSpecificDisplay() { function handlePlatformSpecificDisplay() {
var windows_only_elements = document.getElementsByClassName('windows-only'); var windows_only_elements = document.getElementsByClassName('windows-only');
if (require('os').platform() !== 'win32') { if (!isWindows()) {
for (const item of windows_only_elements) { for (const item of windows_only_elements) {
item.setAttribute('hidden', 'true'); item.setAttribute('hidden', 'true');
} }