Skip to content

Commit

Permalink
app: Add hidden setting to enable cloud API
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jan 12, 2021
1 parent 6fab96c commit ed1e0b6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/main.ts
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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);
});
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/views/settings/index.tsx
Expand Up @@ -61,6 +61,27 @@ const Settings = observer(({store}: Props) => {
onChange={e => set(store.config, {reportDebugEvents: e.target.checked})}
/>
</Field>
{process.env.RELEASE_CHANNEL !== 'stable' && (
<Field
top
size="sm"
name="Enable Cloud Services"
description={
<React.Fragment>
Enables cloud access to Prolink Tools. Overlays will be accessible from
any network and additional features will be enabled.
<InfoBox>
This feature is <em>highly</em> experimental!
</InfoBox>
</React.Fragment>
}
>
<Checkbox
checked={config.enableCloudApi}
onChange={e => set(store.config, {enableCloudApi: e.target.checked})}
/>
</Field>
)}
</Section>
</React.Fragment>
);
Expand Down
6 changes: 6 additions & 0 deletions src/shared/store/index.ts
Expand Up @@ -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
*/
Expand Down
20 changes: 20 additions & 0 deletions src/shared/store/ipc.ts
Expand Up @@ -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();
};

1 comment on commit ed1e0b6

@vercel
Copy link

@vercel vercel bot commented on ed1e0b6 Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.