From 978e5d0415a760ce3dc26c560bb041c2bd8112ca Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 7 Apr 2019 02:56:37 -0500 Subject: [PATCH] Solus Linux detection --- CHANGELOG.md | 3 ++- electron.js | 28 +++++++++++++++++++++++++--- helpers.js | 31 +++++++++++++++++++++++++++++++ public/detect_linux.sh | 17 +++++++++++++++++ src/constants.js | 7 ++++++- 5 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 public/detect_linux.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a85c7e..aa34878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,10 @@ * Linux distribution support * Debian 9 * Solus + * Ubuntu 18.04 * Ubuntu 18.10 * Ubuntu 19.04 - * + ## 1.0.2 ## * Option to launch application hidden (notification icon only) * Close window to notification area diff --git a/electron.js b/electron.js index ed58920..be4bd04 100644 --- a/electron.js +++ b/electron.js @@ -11,6 +11,10 @@ const helpers = require('./helpers'); const fs = require('fs'); const unzip = require('unzipper'); const AutoLaunch = require('auto-launch'); +require.extensions['.sh'] = function (module, filename) { + module.exports = fs.readFileSync(filename, 'utf8'); +}; +const detectScript = require('./public/detect_linux.sh'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -577,9 +581,27 @@ ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => { }); ipcMain.on(Constants.IPC_Get_Platform, (event) => { - event.sender.send(Constants.IPC_Get_Platform_Reply, { - data: os.platform() - }); + let platform = os.platform(); + if (platform === 'linux') { + fs.writeFileSync('/tmp/repertory_detect_linux.sh', detectScript); + helpers + .executeScript('/tmp/repertory_detect_linux.sh') + .then(data => { + platform = data.replace(/(\r\n|\n|\r)/gm,""); + event.sender.send(Constants.IPC_Get_Platform_Reply, { + data: platform, + }); + }) + .catch(() => { + event.sender.send(Constants.IPC_Get_Platform_Reply, { + data: platform, + }); + }); + } else { + event.sender.send(Constants.IPC_Get_Platform_Reply, { + data: platform, + }); + } }); ipcMain.on(Constants.IPC_Get_State, (event, data) => { diff --git a/helpers.js b/helpers.js index e494960..945f2fa 100644 --- a/helpers.js +++ b/helpers.js @@ -156,6 +156,37 @@ module.exports.executeAsync = (command, args=[]) => { }); }; +module.exports.executeScript = script => { + return new Promise((resolve, reject) => { + const processOptions = { + detached: false, + shell: true, + windowsHide: true, + }; + + const command = '/bin/sh'; + const args = [ + script + ]; + + const process = new spawn(command, args, processOptions); + let result = ''; + + process.on('error', (err) => { + reject(err); + }); + + process.stdout.on('data', (d)=> { + result += d; + }); + + process.on('exit', () => { + resolve(result); + }); + process.unref(); + }); +}; + module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => { return new Promise((resolve) => { const processOptions = { diff --git a/public/detect_linux.sh b/public/detect_linux.sh new file mode 100644 index 0000000..65009d0 --- /dev/null +++ b/public/detect_linux.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +DISTNAME=unknown +DISTVER= + +if [ -f /etc/solus-release ]; then + DISTNAME=solus +elif [ -f /etc/lsb-release ]; then + . /etc/lsb-release + DISTNAME=$(echo ${DISTRIB_ID} | awk '{print tolower($0)}') + DISTVER=${DISTRIB_RELEASE} +elif [ -f /etc/debian_version ]; then + DISTNAME=debian + DISTVER=$(head -1 /etc/debian_version) +fi + +echo ${DISTNAME}${DISTVER} diff --git a/src/constants.js b/src/constants.js index 672b660..86683ff 100644 --- a/src/constants.js +++ b/src/constants.js @@ -3,11 +3,16 @@ Object.defineProperty(exports, "__esModule", { }); exports.RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory/raw/1.0.0-beta_branch/releases.json'; exports.DATA_LOCATIONS = { + debian: '~/.local/repertory/ui', linux: '~/.local/repertory/ui', + solus: '~/.local/repertory/ui', + 'ubuntu18.04': '~/.local/repertory/ui', + 'ubuntu18.10': '~/.local/repertory/ui', + 'ubuntu19.04': '~/.local/repertory/ui', darwin: '~/Library/Application Support/repertory/ui', win32: '%LOCALAPPDATA%\\repertory\\ui' }; -exports.UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/1.0.0-beta_branch/releases.json'; +exports.UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/1.0.3_branch/releases.json'; exports.PROVIDER_LIST = [ 'Hyperspace',