Skip to content

Commit

Permalink
Gui/Bootstrap: cleaned-up process (#363)
Browse files Browse the repository at this point in the history
Also removed hardcoded call to outdated test scripts ;)
  • Loading branch information
warpdesign authored Jan 25, 2023
1 parent bcdcc2f commit e66703f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 56 deletions.
7 changes: 4 additions & 3 deletions src/components/Main.tsx → src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface InjectedProps extends WithTranslation {
appState: AppState
}

const App = inject('appState')(
const AppClass = inject('appState')(
observer(
class App extends React.Component<WithTranslation> {
private appState: AppState
Expand Down Expand Up @@ -189,6 +189,7 @@ const App = inject('appState')(

componentDidMount(): void {
// listen for events from main electron process as well as webview
document.body.classList.add('loaded')
this.addListeners()
this.setDarkThemeClass()
this.setPlatformClass()
Expand Down Expand Up @@ -328,6 +329,6 @@ const App = inject('appState')(
),
)

const Main = withTranslation()(App)
const App = withTranslation()(AppClass)

export { Main }
export { App }
72 changes: 19 additions & 53 deletions src/gui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { Provider } from 'mobx-react'
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'
import process from 'process'
import child_process from 'child_process'

import { Main } from '$src/components/Main'
import { App } from '$src/components/App'
import { i18n } from '$src/locale/i18n'
import { AppState } from '$src/state/appState'
import initFS from '$src/utils/initFS'
Expand All @@ -22,60 +21,27 @@ configure({
safeDescriptors: window.ENV.CY ? false : true,
})

class App {
appState: AppState
const bootstrap = async () => {
const appState = new AppState()

constructor() {
this.appState = new AppState()
}
initFS()

// debug stuff
createTestFolder(): Promise<void> {
return new Promise((resolve) => {
// Development stuff: create fake directory for testing
// const exec = require('child_process').exec;
const exec = child_process.exec
exec('/Users/leo/tmp_ftp.sh', (err: Error) => {
if (err) {
console.log('error preparing fake folders', err)
}
await appState.loadSettingsAndPrepareViews()

resolve()
})
})
}
await i18n.promise

init = async (): Promise<void> => {
if (window.ENV.NODE_ENV !== 'production') {
await this.createTestFolder()
}

initFS()

await this.appState.loadSettingsAndPrepareViews()
// we need for translations to be ready too
await i18n.promise

this.renderApp()
}

renderApp = async (): Promise<void> => {
document.body.classList.add('loaded')

ReactDOM.render(
<DndProvider backend={HTML5Backend}>
<I18nextProvider i18n={i18n.i18next}>
<Provider appState={this.appState}>
<HotkeysProvider>
<Main />
</HotkeysProvider>
</Provider>
</I18nextProvider>
</DndProvider>,
document.getElementById('root'),
)
}
ReactDOM.render(
<DndProvider backend={HTML5Backend}>
<I18nextProvider i18n={i18n.i18next}>
<Provider appState={appState}>
<HotkeysProvider>
<App />
</HotkeysProvider>
</Provider>
</I18nextProvider>
</DndProvider>,
document.getElementById('root'),
)
}

const app = new App()
app.init()
bootstrap()

0 comments on commit e66703f

Please sign in to comment.