diff options
author | Balaji Vijayakumar <kuttibalaji.v6@gmail.com> | 2022-10-31 16:14:30 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-31 10:44:30 +0000 |
commit | 87bc593ac72af503171f759fc6e4b1e9e0813039 (patch) | |
tree | 7128adb5cc48ae36104c4d3e6de219b9de1ac446 /src/app.tsx | |
parent | Convert web controls & screen to typescript (#722) (diff) | |
download | ferdium-app-87bc593ac72af503171f759fc6e4b1e9e0813039.tar.gz ferdium-app-87bc593ac72af503171f759fc6e4b1e9e0813039.tar.zst ferdium-app-87bc593ac72af503171f759fc6e4b1e9e0813039.zip |
refactor: convert global app to typescript (#723)
Diffstat (limited to 'src/app.tsx')
-rw-r--r-- | src/app.tsx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/app.tsx b/src/app.tsx new file mode 100644 index 000000000..4782bb778 --- /dev/null +++ b/src/app.tsx | |||
@@ -0,0 +1,66 @@ | |||
1 | import { webFrame } from 'electron'; | ||
2 | |||
3 | import { render } from 'react-dom'; | ||
4 | import { Provider } from 'mobx-react'; | ||
5 | import { RouterStore } from '@superwf/mobx-react-router'; | ||
6 | import { createHashHistory } from 'history'; | ||
7 | |||
8 | import ServerApi from './api/server/ServerApi'; | ||
9 | import LocalApi from './api/server/LocalApi'; | ||
10 | import storeFactory from './stores'; | ||
11 | import apiFactory from './api'; | ||
12 | import actions from './actions'; | ||
13 | import MenuFactory from './lib/Menu'; | ||
14 | import TouchBarFactory from './lib/TouchBar'; | ||
15 | |||
16 | import I18N from './I18n'; | ||
17 | import FerdiumRoutes from './routes'; | ||
18 | |||
19 | // Basic electron Setup | ||
20 | webFrame.setVisualZoomLevelLimits(1, 1); | ||
21 | |||
22 | window.addEventListener('load', () => { | ||
23 | const serverApi = new ServerApi(); | ||
24 | const api = apiFactory(serverApi, new LocalApi()); | ||
25 | const history = createHashHistory(); | ||
26 | const router = new RouterStore(history); | ||
27 | // @ts-ignore - Need to provide proper typings for actions | ||
28 | const stores = storeFactory(api, actions, router); | ||
29 | const menu = new MenuFactory(stores, actions); | ||
30 | const touchBar = new TouchBarFactory(stores, actions); | ||
31 | |||
32 | window['ferdium'] = { | ||
33 | stores, | ||
34 | actions, | ||
35 | api, | ||
36 | menu, | ||
37 | touchBar, | ||
38 | features: {}, | ||
39 | render() { | ||
40 | const preparedApp = ( | ||
41 | <Provider stores={stores} actions={actions}> | ||
42 | <I18N stores={{ app: stores.app, user: stores.user }}> | ||
43 | <FerdiumRoutes history={history} /> | ||
44 | </I18N> | ||
45 | </Provider> | ||
46 | ); | ||
47 | render(preparedApp, document.querySelector('#root')); | ||
48 | }, | ||
49 | }; | ||
50 | window['ferdium'].render(); | ||
51 | }); | ||
52 | |||
53 | // Prevent back and forward mouse events for the app itself (not inside the recipe) | ||
54 | // TODO: send this request to the recipe.js | ||
55 | window.addEventListener('mouseup', e => { | ||
56 | if (e.button === 3 || e.button === 4) { | ||
57 | e.preventDefault(); | ||
58 | e.stopPropagation(); | ||
59 | } | ||
60 | }); | ||
61 | |||
62 | // Prevent drag and drop into window from redirecting | ||
63 | window.addEventListener('dragover', event => event.preventDefault()); | ||
64 | window.addEventListener('drop', event => event.preventDefault()); | ||
65 | window.addEventListener('dragover', event => event.stopPropagation()); | ||
66 | window.addEventListener('drop', event => event.stopPropagation()); | ||