Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
42 changes: 40 additions & 2 deletions app/lib/os-context-menu/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,3 +17,42 @@ export function ensureContextMenuEnabled () {
})
}
}

/**
* Returns true if the context menu is registered, false otherwise
*
* @returns {Promise<boolean>}
*/
export function isRegistered () {
if (isWindows) {
return WinShell.contextMenus.isRegistered()
}

return Promise.resolve(false)
}

/**
* Registers the context menu
*
* @returns {Promise<boolean>}
*/
export function register () {
if (isWindows) {
return WinShell.contextMenus.register()
}

return Promise.resolve(false)
}

/**
* Deregisters the context menu
*
* @returns {Promise<boolean>}
*/
export function deregister () {
if (isWindows) {
return WinShell.contextMenus.deregister()
}

return Promise.resolve(false)
}
53 changes: 53 additions & 0 deletions app/windows/Settings/Components/IntegrationsPanel.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<Pane className="settings">
<CheckBox
label='Enable "Add to IPFS" option to files and folders'
checked={this.state.contextMenu}
onChange={this._handleContextMenuChange}
/>
</Pane>
)
}
}

export default IntegrationsPanel
23 changes: 18 additions & 5 deletions app/windows/Settings/Components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,37 @@ 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) => {
this.props.navigationStore.selected = selected
}

render () {
const menus = [
<NavTitle key='title'>Settings and Info</NavTitle>,
<NavGroupItem key='con' glyph="rss" text="Connectivity" eventKey={0} />,
<NavGroupItem key='rep' glyph="database" text="Repository" eventKey={1} />,
<NavGroupItem key='peers' glyph="users" text="Peers" eventKey={2} />
]

if (isWindows) {
menus.push(
<NavGroupItem key='integrations' glyph="tools" text="Integrations" eventKey={3} />
)
}

return (
<Pane sidebar ptSize="sm">
<NavGroup onSelect={this._handleSelect}>
<NavTitle key='title'>Settings and Info</NavTitle>
<NavGroupItem key='con' glyph="rss" text="Connectivity" eventKey={0} />
<NavGroupItem key= 'rep' glyph="database" text="Repository" eventKey={1} />
<NavGroupItem key= 'peers' glyph="users" text="Peers" eventKey={2} />
{
menus
}
</NavGroup>
</Pane>
)
Expand Down
6 changes: 6 additions & 0 deletions app/windows/Settings/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -52,6 +53,11 @@ class SettingsWindow extends React.Component {
informationStore={InformationStore}
navigationStore={NavigationStore}
/>

<IntegrationsPanel
informationStore={InformationStore}
navigationStore={NavigationStore}
/>
</PaneGroup>
</Content>

Expand Down