blowfish/src/renderer/App.jsx

66 lines
1.6 KiB
React
Raw Normal View History

2019-09-24 01:13:02 +02:00
import React, { useEffect } from 'react'
2019-05-10 22:22:33 +02:00
import PropTypes from 'prop-types'
import {
Router,
createMemorySource,
createHistory,
LocationProvider,
navigate
} from '@reach/router'
2019-05-16 22:25:19 +02:00
import { webFrame, ipcRenderer } from 'electron'
2019-05-10 22:22:33 +02:00
import posed, { PoseGroup } from 'react-pose'
2019-05-05 13:34:21 +02:00
import Titlebar from './components/Titlebar'
2019-09-08 21:47:57 +02:00
import { defaultAnimation } from './components/Animations'
2019-05-08 01:02:02 +02:00
import Home from './screens/Home'
import Preferences from './screens/Preferences'
2019-09-08 21:47:57 +02:00
import styles from './App.module.css'
2019-05-05 13:34:21 +02:00
//
// Disable zooming
//
webFrame.setVisualZoomLevelLimits(1, 1)
webFrame.setLayoutZoomLevelLimits(0, 0)
2019-05-11 20:16:18 +02:00
const Animation = posed.div(defaultAnimation)
2019-05-10 22:22:33 +02:00
// Fix reach-router in packaged Electron
// https://github.com/reach/router/issues/25#issuecomment-394003652
let source = createMemorySource('/')
let history = createHistory(source)
2019-05-10 22:22:33 +02:00
const PosedRouter = ({ children }) => (
<LocationProvider history={history}>
2019-05-10 22:22:33 +02:00
{({ location }) => (
2019-05-11 20:16:18 +02:00
<PoseGroup animateOnMount>
2019-05-10 22:22:33 +02:00
<Animation key={location.key}>
<Router location={location}>{children}</Router>
</Animation>
</PoseGroup>
)}
</LocationProvider>
2019-05-10 22:22:33 +02:00
)
PosedRouter.propTypes = {
children: PropTypes.any.isRequired
}
2019-05-08 01:02:02 +02:00
2019-09-24 01:13:02 +02:00
export default function App() {
useEffect(() => {
2019-05-16 22:25:19 +02:00
ipcRenderer.on('goTo', (evt, route) => {
navigate(route)
})
2019-09-24 01:13:02 +02:00
}, [])
2019-05-16 22:25:19 +02:00
2019-09-24 01:13:02 +02:00
return (
<>
{process.platform === 'darwin' && <Titlebar />}
<div className={styles.app}>
<PosedRouter>
<Home path="/" default />
<Preferences path="/preferences" />
</PosedRouter>
</div>
</>
)
2019-05-05 13:34:21 +02:00
}