Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

Commit

Permalink
Merge pull request #179 from Siderus/feature/add-context-menu-automat…
Browse files Browse the repository at this point in the history
…ically

Add the context menu after the welcome window
  • Loading branch information
kernelwhisperer authored Aug 21, 2018
2 parents cfd056c + 127b9e3 commit e6e053f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
4 changes: 4 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import StorageWindow from './windows/Storage/window'
import WelcomeWindow from './windows/Welcome/window'
import ActivitiesWindow from './windows/Activities/window'

import { ensureContextMenuEnabled } from './lib/os-context-menu'

// we support adding files if you start the app with the `--add` param
checkForAddRequests()

Expand Down Expand Up @@ -130,6 +132,8 @@ function startWelcome () {
* 8. show storage window
*/
function startOrion () {
// ensure the "Add to IPFS via Orion" option is enabled
ensureContextMenuEnabled()
// retrieve the activity log from file
if (existsSync(activityLogPath)) {
const activityLog = JSON.parse(readFileSync(activityLogPath))
Expand Down
20 changes: 20 additions & 0 deletions app/lib/os-context-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as WinShell from './win-shell'

/**
* 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
if (!status) {
WinShell.contextMenus.register().then(() => {
console.log('Successfully added Orion to the windows context menu!')
})
}
})
}
}
File renamed without changes.
39 changes: 1 addition & 38 deletions app/windows/Settings/Components/ConnectivityPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { trackEvent } from '../../../stats'

import { Pane, Button, CheckBox } from 'react-photonkit'
import Input from '../../../components/Input'
import * as WinShell from '../../../util/win-shell'

const GatewayEnum = {
SIDERUS: 'https://siderus.io',
LOCAL: 'http://localhost:8080'
}

const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'

/**
* Connectivity Panel
Expand All @@ -25,8 +23,7 @@ class ConnectivityPanel extends React.Component {
skipGatewayQuery: true,
runInBackground: true,
disablePubSubIPNS: false,
allowUserTracking: false,
contextMenu: false
allowUserTracking: false
}

componentDidMount () {
Expand All @@ -49,14 +46,6 @@ class ConnectivityPanel extends React.Component {
disablePubSubIPNS: values[3] || false,
allowUserTracking: values[4] || false
}))
/**
* Retrieve settings from Windows Registry
*/
if (isWindows) {
WinShell.contextMenus.isRegistered().then(status => {
this.setState({ contextMenu: status })
})
}
}

_handleSkipGatewayQueryChange = (event) => {
Expand Down Expand Up @@ -139,24 +128,6 @@ class ConnectivityPanel extends React.Component {
document.execCommand('copy')
}

/**
* If the user wants to have "Add to IPFS via Orion" option in the context menu
* we need to register this change in the windows registry. For removal we need to deregister.
*/
_handleContextMenuChange = () => {
if (isWindows) {
if (this.state.contextMenu) {
WinShell.contextMenus.deregister().then(() => {
this.setState({ contextMenu: false })
})
} else {
WinShell.contextMenus.register().then(() => {
this.setState({ contextMenu: true })
})
}
}
}

render () {
if (this.props.navigationStore.selected !== 0) return null
if (!this.props.informationStore) return null
Expand Down Expand Up @@ -227,14 +198,6 @@ class ConnectivityPanel extends React.Component {
onChange={this._handleUserTrackingChange}
/>

{
isWindows &&
<CheckBox
label='Enable "Add to IPFS" option to files and folders'
checked={this.state.contextMenu}
onChange={this._handleContextMenuChange}
/>
}
</Pane>
)
}
Expand Down

0 comments on commit e6e053f

Please sign in to comment.