Skip to content

Commit

Permalink
Fix features flags loading (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso authored Dec 20, 2024
1 parent 79dd5b7 commit 30bf0ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export class RunmeExtension {
const session = await StatefulAuthProvider.instance.ensureSession()
const nunmeIdentity = session ? RunmeIdentity.ALL : getServerLifecycleIdentity()
await commands.executeCommand('runme.lifecycleIdentitySelection', nunmeIdentity)
kernel.updateFeatureContext('statefulAuth', !!session)
} catch (error) {
let message
if (error instanceof Error) {
Expand Down
63 changes: 30 additions & 33 deletions src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ import { CommandModeEnum } from './grpc/runner/types'
import { GrpcReporter } from './reporter'
import { EnvStoreMonitorWithSession } from './panels/notebook'
import { SignedIn } from './signedIn'
import { StatefulAuthProvider } from './provider/statefulAuth'

enum ConfirmationItems {
Yes = 'Yes',
Expand Down Expand Up @@ -203,44 +202,42 @@ export class Kernel implements Disposable {
this.#onlySignedIn = new SignedIn(this)
this.#disposables.push(this.#onlySignedIn)

StatefulAuthProvider.instance.currentSession().then((session) => {
const packageJSON = context?.extension?.packageJSON || {}
const featContext: FeatureContext = {
os: os.platform(),
vsCodeVersion: version as string,
extensionVersion: packageJSON?.version,
githubAuth: false,
statefulAuth: !!session,
extensionId: context?.extension?.id as ExtensionName,
}
const packageJSON = this.context?.extension?.packageJSON || {}
const featContext: FeatureContext = {
os: os.platform(),
vsCodeVersion: version as string,
extensionVersion: packageJSON?.version,
githubAuth: false,
statefulAuth: false,
extensionId: this.context?.extension?.id as ExtensionName,
}

const runmeFeatureSettings = workspace.getConfiguration('runme.features')
const featureNames = Object.keys(FeatureName)
const runmeFeatureSettings = workspace.getConfiguration('runme.features')
const featureNames = Object.keys(FeatureName)

featureNames.forEach((feature) => {
if (runmeFeatureSettings.has(feature)) {
const result = runmeFeatureSettings.get<boolean>(feature, false)
this.#featuresSettings.set(feature, result)
}
})
featureNames.forEach((feature) => {
if (runmeFeatureSettings.has(feature)) {
const result = runmeFeatureSettings.get<boolean>(feature, false)
this.#featuresSettings.set(feature, result)
}
})

this.featuresState$ = features.loadState(packageJSON, featContext, this.#featuresSettings)
this.featuresState$ = features.loadState(packageJSON, featContext, this.#featuresSettings)

if (this.featuresState$) {
const subscription = this.featuresState$
.pipe(map((_state) => features.getSnapshot(this.featuresState$)))
.subscribe((snapshot) => {
ContextState.addKey(FEATURES_CONTEXT_STATE_KEY, snapshot)
postClientMessage(this.messaging, ClientMessages.featuresUpdateAction, {
snapshot: snapshot,
})
if (this.featuresState$) {
const subscription = this.featuresState$
.pipe(map((_state) => features.getSnapshot(this.featuresState$)))
.subscribe((snapshot) => {
ContextState.addKey(FEATURES_CONTEXT_STATE_KEY, snapshot)
postClientMessage(this.messaging, ClientMessages.featuresUpdateAction, {
snapshot: snapshot,
})

this.#disposables.push({
dispose: () => subscription.unsubscribe(),
})
}
})

this.#disposables.push({
dispose: () => subscription.unsubscribe(),
})
}
}

get envProps() {
Expand Down

0 comments on commit 30bf0ce

Please sign in to comment.