2026-05-11 13:46:18 +02:00
|
|
|
import type { Settings, NoteWidthMode } from '../types'
|
|
|
|
|
import { trackEvent } from '../lib/telemetry'
|
|
|
|
|
import {
|
|
|
|
|
trackDateDisplayFormatChanged,
|
|
|
|
|
trackDefaultNoteWidthChanged,
|
|
|
|
|
trackSidebarTypePluralizationChanged,
|
|
|
|
|
} from '../lib/productAnalytics'
|
|
|
|
|
import {
|
|
|
|
|
DEFAULT_DATE_DISPLAY_FORMAT,
|
|
|
|
|
normalizeDateDisplayFormat,
|
|
|
|
|
type DateDisplayFormat,
|
|
|
|
|
} from '../utils/dateDisplay'
|
|
|
|
|
import { DEFAULT_NOTE_WIDTH_MODE, normalizeNoteWidthMode } from '../utils/noteWidth'
|
|
|
|
|
|
|
|
|
|
export interface SettingsPreferenceDraft {
|
|
|
|
|
analytics: boolean
|
|
|
|
|
dateDisplayFormat: DateDisplayFormat
|
|
|
|
|
defaultNoteWidth: NoteWidthMode
|
2026-05-11 16:37:06 +02:00
|
|
|
multiWorkspaceEnabled: boolean
|
2026-05-11 13:46:18 +02:00
|
|
|
sidebarTypePluralizationEnabled: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function trackTelemetryConsentChange(previousAnalytics: boolean, nextAnalytics: boolean): void {
|
|
|
|
|
if (!previousAnalytics && nextAnalytics) trackEvent('telemetry_opted_in')
|
|
|
|
|
if (previousAnalytics && !nextAnalytics) trackEvent('telemetry_opted_out')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function trackSettingsPreferenceChanges(settings: Settings, draft: SettingsPreferenceDraft): void {
|
|
|
|
|
const previousDateDisplayFormat = normalizeDateDisplayFormat(settings.date_display_format) ?? DEFAULT_DATE_DISPLAY_FORMAT
|
|
|
|
|
if (previousDateDisplayFormat !== draft.dateDisplayFormat) {
|
|
|
|
|
trackDateDisplayFormatChanged(draft.dateDisplayFormat)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const previousNoteWidth = normalizeNoteWidthMode(settings.note_width_mode) ?? DEFAULT_NOTE_WIDTH_MODE
|
|
|
|
|
if (previousNoteWidth !== draft.defaultNoteWidth) {
|
|
|
|
|
trackDefaultNoteWidthChanged(draft.defaultNoteWidth)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const previousPluralization = settings.sidebar_type_pluralization_enabled ?? true
|
|
|
|
|
if (previousPluralization !== draft.sidebarTypePluralizationEnabled) {
|
|
|
|
|
trackSidebarTypePluralizationChanged(draft.sidebarTypePluralizationEnabled)
|
|
|
|
|
}
|
2026-05-11 16:37:06 +02:00
|
|
|
|
|
|
|
|
const previousMultiWorkspaceEnabled = settings.multi_workspace_enabled === true
|
|
|
|
|
if (previousMultiWorkspaceEnabled !== draft.multiWorkspaceEnabled) {
|
|
|
|
|
trackEvent('multi_workspace_mode_changed', { enabled: draft.multiWorkspaceEnabled ? 1 : 0 })
|
|
|
|
|
}
|
2026-05-11 13:46:18 +02:00
|
|
|
}
|