Skip to content

Commit

Permalink
added config for disabling auto flow detection
Browse files Browse the repository at this point in the history
  • Loading branch information
srzainab committed Jan 17, 2024
1 parent b3c4ba4 commit 456b336
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@
"type": "boolean",
"default": true,
"markdownDescription": "Allow Pullflow to send product usage telemetry.\n\n_**Note:** For Pullflow to send any telemetry BOTH this setting and VS Code telemetry must be enabled. If either one is disabled no telemetry will be sent._"
},
"pullflow.automaticFlowDetection.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Alow Pullflow to automatically detect flow state based on keystrokes.\n\n_**Note:** Extension must be reloaded for this to take affect._"
}
}
}
Expand Down Expand Up @@ -227,4 +232,4 @@
"ts-jest": "^29.1.0",
"uuidv4": "^6.2.13"
}
}
}
9 changes: 9 additions & 0 deletions src/userPresence/trackUserPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export const trackUserPresence = (
context: ExtensionContext,
statusBar: StatusBarItem
) => {
const flowEnabled = Store.get(context)?.isFlowDetectionEnabled
if (!flowEnabled) {
log.info(`user disabled flow detection`, module)
return {
clearFlowInterval: () => {},
disposeTextEditorEvent: () => {},
}
}

log.info(`started tracking user flow`, module)
const userFlowIntervalId = setInterval(async () => {
await UserPresence.update(context, statusBar)
Expand Down
25 changes: 20 additions & 5 deletions src/utils/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const initialize = async ({
}) => {
log.info('initializing extension', module)

await initializeTelemetry(context)
await initializeConfiguration(context)

const errorCount = { count: 0 }
await PullRequestState.update({
Expand Down Expand Up @@ -122,16 +122,17 @@ const setSpaceUsers = async ({
}

const extensionTelemetryFlag = () =>
workspace
.getConfiguration('pullflow.telemetry.enabled')
.get<boolean>('pullflow.telemetry.enabled', true)
getPullflowConfig('telemetry.enabled', true)

const vscodeTelemetryFlag = () =>
workspace.getConfiguration('telemetry').get<boolean>('enableTelemetry')

const initializeTelemetry = async (context: ExtensionContext) => {
const initializeConfiguration = async (context: ExtensionContext) => {
await Store.set(context, {
isTelemetryEnabled: vscodeTelemetryFlag() && extensionTelemetryFlag(),
isFlowDetectionEnabled: !!getPullflowConfig(
'automaticFlowDetection.enabled'
),
})

const disposable = workspace.onDidChangeConfiguration(async (event) => {
Expand All @@ -143,6 +144,20 @@ const initializeTelemetry = async (context: ExtensionContext) => {
isTelemetryEnabled: vscodeTelemetryFlag() && extensionTelemetryFlag(),
})
}

if (event.affectsConfiguration('pullflow.automaticFlowDetection.enabled')) {
await Store.set(context, {
isFlowDetectionEnabled: !!getPullflowConfig(
'automaticFlowDetection.enabled'
),
})
}
})
context.subscriptions.push(disposable)
}

const getPullflowConfig = (key: string, defaultValue?: boolean) => {
const config = workspace.getConfiguration('pullflow')
const value = config.get<boolean>(key)
return value ?? defaultValue
}
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type CacheObject = {
lastKeyStrokeTime?: number | null
previousPresenceStatus?: PresenceStatus
isTelemetryEnabled?: boolean
isFlowDetectionEnabled?: boolean
}
export enum StatusBarState {
Loading,
Expand Down

0 comments on commit 456b336

Please sign in to comment.