diff --git a/app/index.js b/app/index.js index 1d1f7df..e2dcee4 100644 --- a/app/index.js +++ b/app/index.js @@ -133,7 +133,9 @@ function startWelcome () { */ function startOrion () { // ensure the "Add to IPFS via Orion" option is enabled - ensureContextMenuEnabled() + if (!Settings.get('disableContextMenu')) { + ensureContextMenuEnabled() + } // retrieve the activity log from file if (existsSync(activityLogPath)) { const activityLog = JSON.parse(readFileSync(activityLogPath)) diff --git a/app/lib/os-context-menu/index.js b/app/lib/os-context-menu/index.js index 2d1a415..e8e81de 100644 --- a/app/lib/os-context-menu/index.js +++ b/app/lib/os-context-menu/index.js @@ -1,12 +1,11 @@ import * as WinShell from './win-shell' +const isWindows = process.platform === 'win32' /** * This adds the option "Add to IPFS via Orion" to the context menu of the OS, for files * and directories. Currently only on windows. */ export function ensureContextMenuEnabled () { - const isWindows = process.platform === 'win32' - if (isWindows) { WinShell.contextMenus.isRegistered().then(status => { // if it's not enabled, do it @@ -18,3 +17,42 @@ export function ensureContextMenuEnabled () { }) } } + +/** + * Returns true if the context menu is registered, false otherwise + * + * @returns {Promise} + */ +export function isRegistered () { + if (isWindows) { + return WinShell.contextMenus.isRegistered() + } + + return Promise.resolve(false) +} + +/** + * Registers the context menu + * + * @returns {Promise} + */ +export function register () { + if (isWindows) { + return WinShell.contextMenus.register() + } + + return Promise.resolve(false) +} + +/** + * Deregisters the context menu + * + * @returns {Promise} + */ +export function deregister () { + if (isWindows) { + return WinShell.contextMenus.deregister() + } + + return Promise.resolve(false) +} diff --git a/app/windows/Settings/Components/IntegrationsPanel.jsx b/app/windows/Settings/Components/IntegrationsPanel.jsx new file mode 100644 index 0000000..385ece4 --- /dev/null +++ b/app/windows/Settings/Components/IntegrationsPanel.jsx @@ -0,0 +1,53 @@ +import React from 'react' +import { observer } from 'mobx-react' +import { Pane, CheckBox } from 'react-photonkit' +import * as ContextMenu from '../../../lib/os-context-menu/index' +import Settings from 'electron-settings' + +const isWindows = process.platform === 'win32' + +@observer +class IntegrationsPanel extends React.Component { + state = { + contextMenu: false + } + + componentDidMount () { + ContextMenu.isRegistered().then(status => { + this.setState({ contextMenu: status }) + }) + } + + _handleContextMenuChange = () => { + // We also need to change the settings otherwise Orion will re-enable the context menu on startup + Settings.set('disableContextMenu', this.state.contextMenu) + if (this.state.contextMenu) { + ContextMenu.deregister().then(() => { + this.setState({ contextMenu: false }) + }) + } else { + ContextMenu.register().then(() => { + this.setState({ contextMenu: true }) + }) + } + } + + render () { + if (this.props.navigationStore.selected !== 3) return null + if (!this.props.informationStore) return null + if (!this.props.informationStore.loaded) return null + if (!isWindows) return null + + return ( + + + + ) + } +} + +export default IntegrationsPanel diff --git a/app/windows/Settings/Components/Sidebar.jsx b/app/windows/Settings/Components/Sidebar.jsx index 87c489d..2538ebd 100644 --- a/app/windows/Settings/Components/Sidebar.jsx +++ b/app/windows/Settings/Components/Sidebar.jsx @@ -3,10 +3,11 @@ import { observer } from 'mobx-react' import { Pane, NavGroup, NavTitle, NavGroupItem } from 'react-photonkit' +const isWindows = process.platform === 'win32' + /** * Render the Sidebar, uses NavigatorStore */ - @observer class Sidebar extends React.Component { _handleSelect = (selected) => { @@ -14,13 +15,25 @@ class Sidebar extends React.Component { } render () { + const menus = [ + Settings and Info, + , + , + + ] + + if (isWindows) { + menus.push( + + ) + } + return ( - Settings and Info - - - + { + menus + } ) diff --git a/app/windows/Settings/renderer.jsx b/app/windows/Settings/renderer.jsx index 9163c4e..44ae523 100644 --- a/app/windows/Settings/renderer.jsx +++ b/app/windows/Settings/renderer.jsx @@ -18,6 +18,7 @@ import Sidebar from './Components/Sidebar' import RepositoryPanel from './Components/RepositoryPanel' import ConnectivityPanel from './Components/ConnectivityPanel' import PeersPanel from './Components/PeersPanel' +import IntegrationsPanel from './Components/IntegrationsPanel' // Load MobX Stores import NavigationStore from './Stores/Navigation' @@ -52,6 +53,11 @@ class SettingsWindow extends React.Component { informationStore={InformationStore} navigationStore={NavigationStore} /> + +