| 1 | import { EXTENSION_NAME } from "core/control-plane/env"; |
| 2 | import * as vscode from "vscode"; |
| 3 | |
| 4 | import { getUserToken } from "./auth"; |
| 5 | import { RemoteConfigSync } from "./remoteConfig"; |
| 6 | |
| 7 | export async function setupRemoteConfigSync(reloadConfig: () => void) { |
| 8 | const settings = vscode.workspace.getConfiguration(EXTENSION_NAME); |
| 9 | const remoteConfigServerUrl = settings.get<string | null>( |
| 10 | "remoteConfigServerUrl", |
| 11 | null, |
| 12 | ); |
| 13 | if ( |
| 14 | remoteConfigServerUrl === null || |
| 15 | remoteConfigServerUrl === undefined || |
| 16 | remoteConfigServerUrl.trim() === "" |
| 17 | ) { |
| 18 | return; |
| 19 | } |
| 20 | getUserToken().then(async (token) => { |
| 21 | await vscode.workspace |
| 22 | .getConfiguration(EXTENSION_NAME) |
| 23 | .update("userToken", token, vscode.ConfigurationTarget.Global); |
| 24 | try { |
| 25 | const configSync = new RemoteConfigSync(reloadConfig, token); |
| 26 | configSync.setup(); |
| 27 | } catch (e) { |
| 28 | console.warn(`Failed to sync remote config: ${e}`); |
| 29 | } |
| 30 | }); |
| 31 | } |