aboutsummaryrefslogtreecommitdiffstats
path: root/src/app.tsx
diff options
context:
space:
mode:
authorLibravatar Balaji Vijayakumar <kuttibalaji.v6@gmail.com>2022-10-31 16:14:30 +0530
committerLibravatar GitHub <noreply@github.com>2022-10-31 10:44:30 +0000
commit87bc593ac72af503171f759fc6e4b1e9e0813039 (patch)
tree7128adb5cc48ae36104c4d3e6de219b9de1ac446 /src/app.tsx
parentConvert web controls & screen to typescript (#722) (diff)
downloadferdium-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.tsx66
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 @@
1import { webFrame } from 'electron';
2
3import { render } from 'react-dom';
4import { Provider } from 'mobx-react';
5import { RouterStore } from '@superwf/mobx-react-router';
6import { createHashHistory } from 'history';
7
8import ServerApi from './api/server/ServerApi';
9import LocalApi from './api/server/LocalApi';
10import storeFactory from './stores';
11import apiFactory from './api';
12import actions from './actions';
13import MenuFactory from './lib/Menu';
14import TouchBarFactory from './lib/TouchBar';
15
16import I18N from './I18n';
17import FerdiumRoutes from './routes';
18
19// Basic electron Setup
20webFrame.setVisualZoomLevelLimits(1, 1);
21
22window.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
55window.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
63window.addEventListener('dragover', event => event.preventDefault());
64window.addEventListener('drop', event => event.preventDefault());
65window.addEventListener('dragover', event => event.stopPropagation());
66window.addEventListener('drop', event => event.stopPropagation());