46 lines
1.4 KiB
Swift
46 lines
1.4 KiB
Swift
// AnalyticsExtensionService.swift
|
|
// OSGKeyboard · Keyboard Extension
|
|
//
|
|
// The extension only records into durable queues. The host app is the sole
|
|
// network uploader, avoiding extension-lifecycle and cross-process lock races.
|
|
|
|
import Foundation
|
|
import OSGKeyboardShared
|
|
|
|
final class AnalyticsExtensionService: Sendable {
|
|
static let shared = AnalyticsExtensionService()
|
|
|
|
let client: any AnalyticsClient
|
|
|
|
private init() {
|
|
let environment = Self.environment
|
|
let runtime = AnalyticsRuntime.keyboardExtension(
|
|
environment: environment,
|
|
uploadConfiguration: AnalyticsUploadConfiguration(endpoint: Self.endpoint)
|
|
)
|
|
client = runtime.client
|
|
}
|
|
|
|
func recordPresentation(hasFullAccess _: Bool) {
|
|
client.recordSessionActivity()
|
|
client.recordKeyboardActivated()
|
|
}
|
|
|
|
func keyboardWillDisappear() {}
|
|
|
|
private static let endpoint = URL(
|
|
string: "https://account.osglab.com/v1/analytics/events"
|
|
)!
|
|
|
|
private static var environment: AnalyticsEnvironment {
|
|
let appVersion = Bundle.main.object(
|
|
forInfoDictionaryKey: "CFBundleShortVersionString"
|
|
) as? String ?? "unknown"
|
|
let version = ProcessInfo.processInfo.operatingSystemVersion
|
|
return AnalyticsEnvironment(
|
|
appVersion: appVersion,
|
|
osVersion: "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
|
|
)
|
|
}
|
|
}
|