Skip to content

Commit

Permalink
Merge branch 'feature/disable-telemetry' of github.com:pullflow/vscod…
Browse files Browse the repository at this point in the history
…e-pullflow into feature/disable-telemetry
  • Loading branch information
srzainab committed Jan 24, 2024
2 parents 70e5204 + 31fc0d3 commit 2e1f2a2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@
"pullflow.telemetry.enabled": {
"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._"
"markdownDescription": "Enable Pullflow to transmit product usage telemetry. \n\n_**Important:** To activate telemetry transmission, both this setting and the VS Code telemetry option must be enabled. Telemetry will not be sent if either of these settings is disabled._"
},
"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"
}
}
}
8 changes: 4 additions & 4 deletions src/commands/signOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export const SignOut = async ({
pollIntervalId: ReturnType<typeof setInterval>
focusStateEvent: ReturnType<typeof window.onDidChangeWindowState>
presenceInterval: {
userFlowIntervalId: ReturnType<typeof setInterval>
textEditorEvent: ReturnType<typeof window.onDidChangeTextEditorSelection>
clearFlowInterval: Function
disposeTextEditorEvent: Function
}
}) => {
await context.secrets.store(AppConfig.app.sessionSecret, '')
await Store.clear(context)
StatusBar.update({ context, statusBar, state: StatusBarState.SignedOut })
clearInterval(pollIntervalId) // stopping polling interval
clearInterval(presenceInterval.userFlowIntervalId) // stopping user flow interval
focusStateEvent.dispose() // removing focus event listener
presenceInterval.textEditorEvent.dispose() // removing text editor event listener
presenceInterval.clearFlowInterval() // stopping user flow interval
presenceInterval.disposeTextEditorEvent() // removing text editor event listener
}
14 changes: 13 additions & 1 deletion 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 All @@ -18,7 +27,10 @@ export const trackUserPresence = (
incrementKeyStrokeCount(context)
})

return { userFlowIntervalId, textEditorEvent }
return {
clearFlowInterval: () => clearInterval(userFlowIntervalId),
disposeTextEditorEvent: () => textEditorEvent.dispose(),
}
}

const incrementKeyStrokeCount = (context: ExtensionContext) => {
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 2e1f2a2

Please sign in to comment.