diff --git a/src/main/main.ts b/src/main/main.ts index a6de479..7c004cb 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -2,7 +2,7 @@ import 'regenerator-runtime/runtime'; import {app, BrowserWindow, nativeTheme, shell} from 'electron'; import isDev from 'electron-is-dev'; -import {reaction, set} from 'mobx'; +import {reaction, set, when} from 'mobx'; import {bringOnline, NetworkState, ProlinkNetwork} from 'prolink-connect'; import * as path from 'path'; @@ -14,7 +14,12 @@ import {registerDebuggingEventsService} from 'src/main/debugEvents'; import {setupMenu} from 'src/main/menu'; import {userInfo} from 'src/shared/sentry/main'; import {AppStore, createStore} from 'src/shared/store'; -import {loadMainConfig, observeStore, registerMainIpc} from 'src/shared/store/ipc'; +import { + loadMainConfig, + observeStore, + registerMainIpc, + startCloudServicesWebsocket, +} from 'src/shared/store/ipc'; import connectNetworkStore from 'src/shared/store/network'; import theme from 'src/theme'; @@ -119,6 +124,18 @@ app.on('ready', async () => { // await startOverlayServer(mainStore); + // Connect to app.prolink.tools when enabled + reaction( + () => mainStore.config.enableCloudApi, + enabled => { + if (enabled) { + const disconnect = startCloudServicesWebsocket(mainStore); + when(() => mainStore.config.enableCloudApi === false, disconnect); + } + }, + {fireImmediately: true} + ); + connectNetworkStore(mainStore, network); registerDebuggingEventsService(mainStore, network); }); diff --git a/src/renderer/views/settings/index.tsx b/src/renderer/views/settings/index.tsx index 10459fb..0e4381a 100644 --- a/src/renderer/views/settings/index.tsx +++ b/src/renderer/views/settings/index.tsx @@ -61,6 +61,27 @@ const Settings = observer(({store}: Props) => { onChange={e => set(store.config, {reportDebugEvents: e.target.checked})} /> + {process.env.RELEASE_CHANNEL !== 'stable' && ( + + Enables cloud access to Prolink Tools. Overlays will be accessible from + any network and additional features will be enabled. + + This feature is highly experimental! + + + } + > + set(store.config, {enableCloudApi: e.target.checked})} + /> + + )} ); diff --git a/src/shared/store/index.ts b/src/shared/store/index.ts index 5235b9e..e65abf2 100644 --- a/src/shared/store/index.ts +++ b/src/shared/store/index.ts @@ -165,6 +165,12 @@ export class AppConfig { @serializable @observable reportDebugEvents = false; + /** + * Should we publish state to app.prolink.tools? + */ + @serializable + @observable + enableCloudApi = false; /** * Mark tracks as 'IDs' using this string */ diff --git a/src/shared/store/ipc.ts b/src/shared/store/ipc.ts index 2478014..e2aa823 100644 --- a/src/shared/store/ipc.ts +++ b/src/shared/store/ipc.ts @@ -351,3 +351,23 @@ export const registerWebsocketListener = ( ws.on('store-update', (change: SerializedChange) => applyChanges(store, change)); ws.on('store-init', (data: any) => set(store, deserialize(AppStore, data))); }; + +/** + * Pushes updates to the API server running on app.prolink.tools. + * + * Returns a function to disconnect. + */ +export const startCloudServicesWebsocket = (store: AppStore) => { + const host = process.env.USE_LOCAL_SERVER + ? 'http://localhost:8888' + : 'https://app.prolink.tools'; + + const key = 'test'; + + const conn = io(`${host}/ingest/${key}`, {transports: ['websocket']}); + + conn.emit('store-init', serialize(AppStore, store)); + changeHandlers.push(change => conn.emit('store-update', change)); + + return () => conn.disconnect(); +};