diff --git a/src/js/App.js b/src/js/App.js index 6d4b274..f42149e 100644 --- a/src/js/App.js +++ b/src/js/App.js @@ -13,10 +13,11 @@ import UWPNoise from '../img/uwp-noise.png'; import Search from './Search.js'; import Games from './games.js'; import Import from './Import.js'; +import Remote from './Remote.js'; // Using window.require so babel doesn't change the node require const electron = window.require('electron'); -const remote = electron.remote; +const remote = new Remote(electron.remote); // Log renderer errors const log = window.require('electron-log'); @@ -75,8 +76,8 @@ class App extends React.Component { } render() { - const accentColor = remote.systemPreferences.getAccentColor(); const navWidth = 48; + const accentColor = remote.systemPreferences.getAccentColor(); const navigationTopNodes = [ this.handleNavRedirect('/')} />, diff --git a/src/js/Remote.js b/src/js/Remote.js new file mode 100644 index 0000000..4bcb748 --- /dev/null +++ b/src/js/Remote.js @@ -0,0 +1,28 @@ +export class Remote { + constructor(remote) { + this.remote = remote; + this.platform = process.platform; + this.systemPreferences = new SystemPreferences(this.remote); + } + + getCurrentWindow() { + return this.remote.getCurrentWindow(); + } +} + +class SystemPreferences { + constructor(remote) { + this.remote = remote; + } + + getAccentColor() { + if (process.platform === 'win32') { + return this.remote.getAccentColor(); + } else { + // TODO: change this hard-coded colour + return '00FF00'; + } + } +} + +export default Remote; \ No newline at end of file diff --git a/src/js/Steam.js b/src/js/Steam.js index aaba6e3..54b3c07 100644 --- a/src/js/Steam.js +++ b/src/js/Steam.js @@ -1,6 +1,7 @@ const Registry = window.require('winreg'); const Store = window.require('electron-store'); const fs = window.require('fs'); +const os = window.require('os'); const {join} = window.require('path'); const VDF = window.require('@node-steam/vdf'); const shortcut = window.require('steam-shortcut-editor'); @@ -24,28 +25,41 @@ class Steam { return resolve(this.steamPath); } - const key = new Registry({ - hive: Registry.HKCU, - key: '\\Software\\Valve\\Steam' - }); + if (process.platform === 'win32') { + const key = new Registry({ + hive: Registry.HKCU, + key: '\\Software\\Valve\\Steam' + }); - key.values((err, items) => { - let steamPath = false; + key.values((err, items) => { + let steamPath = false; - items.forEach((item) => { - if (item.name === 'SteamPath') { - steamPath = item.value; + items.forEach((item) => { + if (item.name === 'SteamPath') { + steamPath = item.value; + } + }); + + if (steamPath) { + this.steamPath = steamPath; + log.info(`Got Steam path: ${steamPath}`); + resolve(steamPath); + } else { + reject(new Error('Could not find Steam path.')); } }); + } else if (process.platform === 'linux') { + // TODO: add support for Steam in other locations than default + const steamPath = `${os.homedir()}/.steam/steam`; - if (steamPath) { - this.steamPath = steamPath; - log.info(`Got Steam path: ${steamPath}`); + if (fs.existsSync(steamPath)) { resolve(steamPath); } else { - reject(new Error('Could not find Steam path.')); + reject(new Error(`Steam was not found in default location (${steamPath})`)); } - }); + } else { + reject(new Error(`getSteamPath() has no code path for platform "${process.platform}"`)); + } }); }