-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.tsx
115 lines (105 loc) · 4.7 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import "regenerator-runtime/runtime";
import FrontendInsights, { LogLevel, reduxMiddleware } from "@aics/frontend-insights";
import AmplitudeNodePlugin from "@aics/frontend-insights-plugin-amplitude-node";
import { ipcRenderer } from "electron";
import { memoize } from "lodash";
import * as React from "react";
import { render } from "react-dom";
import { Provider } from "react-redux";
import FmsFileExplorer from "../../../core/App";
import { PersistedConfigKeys } from "../../../core/services";
import { createReduxStore, interaction, selection } from "../../../core/state";
import ApplicationInfoServiceElectron from "../services/ApplicationInfoServiceElectron";
import ExecutionEnvServiceElectron from "../services/ExecutionEnvServiceElectron";
import FileDownloadServiceElectron from "../services/FileDownloadServiceElectron";
import FileViewerServiceElectron from "../services/FileViewerServiceElectron";
import PersistentConfigServiceElectron from "../services/PersistentConfigServiceElectron";
import NotificationServiceElectron from "../services/NotificationServiceElectron";
import { GlobalVariableChannels, FileDownloadServiceBaseUrl } from "../util/constants";
const APP_ID = "fms-file-explorer";
const notificationService = new NotificationServiceElectron();
const persistentConfigService = new PersistentConfigServiceElectron();
const applicationInfoService = new ApplicationInfoServiceElectron();
const executionEnvService = new ExecutionEnvServiceElectron(notificationService);
// application analytics/metrics
const frontendInsights = new FrontendInsights(
{
application: {
name: APP_ID,
version: applicationInfoService.getApplicationVersion(),
},
userInfo: {
userId: applicationInfoService.getUserName(),
},
session: {
platform: "Electron",
deviceId: `${applicationInfoService.getUserName()}-${executionEnvService.getOS()}`,
},
loglevel: process.env.NODE_ENV === "production" ? LogLevel.Error : LogLevel.Debug,
},
[new AmplitudeNodePlugin({ apiKey: process.env.AMPLITUDE_API_KEY })]
);
frontendInsights.dispatchUserEvent({ type: "SESSION_START" });
// Memoized to make sure the object that collects these services doesn't
// unnecessarily change with regard to referential equality between re-renders of the application
const collectPlatformDependentServices = memoize(
(downloadServiceBaseUrl: FileDownloadServiceBaseUrl) => ({
applicationInfoService,
executionEnvService,
fileDownloadService: new FileDownloadServiceElectron(
notificationService,
downloadServiceBaseUrl
),
fileViewerService: new FileViewerServiceElectron(notificationService),
frontendInsights,
persistentConfigService,
})
);
const frontendInsightsMiddleware = reduxMiddleware(frontendInsights, {
useActionAsProperties: true,
});
const store = createReduxStore({
middleware: [frontendInsightsMiddleware],
persistedConfig: persistentConfigService.getAll(),
});
// https://redux.js.org/api/store#subscribelistener
store.subscribe(() => {
const state = store.getState();
const csvColumns = interaction.selectors.getCsvColumns(state);
const displayAnnotations = selection.selectors.getAnnotationsToDisplay(state);
const userSelectedApplications = interaction.selectors.getUserSelectedApplications(state);
const appState = {
[PersistedConfigKeys.CsvColumns]: csvColumns,
[PersistedConfigKeys.DisplayAnnotations]: displayAnnotations.map((annotation) => ({
annotationDisplayName: annotation.displayName,
annotationName: annotation.name,
description: annotation.description,
type: annotation.type,
})),
[PersistedConfigKeys.UserSelectedApplications]: userSelectedApplications,
[PersistedConfigKeys.HasUsedApplicationBefore]: true,
};
persistentConfigService.persist(appState);
});
function renderFmsFileExplorer() {
render(
<Provider store={store}>
<FmsFileExplorer
fileExplorerServiceBaseUrl={global.fileExplorerServiceBaseUrl}
platformDependentServices={collectPlatformDependentServices(
global.fileDownloadServiceBaseUrl as FileDownloadServiceBaseUrl
)}
/>
</Provider>,
document.getElementById(APP_ID)
);
}
ipcRenderer.addListener(
GlobalVariableChannels.BaseUrl,
(_, { fileExplorerServiceBaseUrl, fileDownloadServiceBaseUrl }) => {
global.fileDownloadServiceBaseUrl = fileDownloadServiceBaseUrl;
global.fileExplorerServiceBaseUrl = fileExplorerServiceBaseUrl;
renderFmsFileExplorer();
}
);
renderFmsFileExplorer();