File size: 5,377 Bytes
e079a73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import {Capabilities, DeviceTypes, HardwareRequirement, HardwareRequirementLevel, HardwareType, simulatedGlasses} from "../../types"

/**

 * Result of a hardware compatibility check

 */
export interface CompatibilityResult {
  isCompatible: boolean
  missingRequired: HardwareRequirement[]
  missingOptional: HardwareRequirement[]
  warnings: string[]
}

/**

 * Service for checking hardware compatibility between apps and glasses

 */
export class HardwareCompatibility {
  /**

   * Check if app is compatible with given device capabilities

   * @param app The app to check

   * @param capabilities The device capabilities (null if no device connected)

   * @returns Detailed compatibility result

   */
  static checkCompatibility(
    hardwareRequirements: HardwareRequirement[],
    capabilities: Capabilities | null,
  ): CompatibilityResult {
    const result: CompatibilityResult = {
      isCompatible: true,
      missingRequired: [],
      missingOptional: [],
      warnings: [],
    }

    // If no hardware requirements specified, app is compatible with any hardware
    if (hardwareRequirements.length === 0) {
      return result
    }

    // If no capabilities available assume simulated glasses:
    if (!capabilities) {
      capabilities = simulatedGlasses
    }

    // Check each hardware requirement
    for (const requirement of hardwareRequirements) {
      const hasHardware = this.checkHardwareAvailable(requirement.type, capabilities!)
      if (!hasHardware) {
        if (requirement.level === HardwareRequirementLevel.REQUIRED) {
          result.missingRequired.push(requirement)
          result.isCompatible = false
        } else {
          result.missingOptional.push(requirement)
        }
      }
    }

    return result
  }

  /**

   * Check if specific hardware is available in capabilities

   * @param hardwareType The type of hardware to check

   * @param capabilities The device capabilities

   * @returns true if hardware is available

   */
  private static checkHardwareAvailable(hardwareType: HardwareType, capabilities: Capabilities): boolean {
    if (hardwareType === HardwareType.EXIST) {
      if (capabilities.modelName === DeviceTypes.NONE) {
        return false
      }
      return true
    }

    switch (hardwareType) {
      case HardwareType.CAMERA:
        return capabilities.hasCamera

      case HardwareType.DISPLAY:
        return capabilities.hasDisplay

      case HardwareType.MICROPHONE:
        // MentraOS always provides an audio-input path. When the connected
        // glasses do not have an onboard microphone, the engine falls back to
        // the phone microphone. Keep `capabilities.hasMicrophone` reserved for
        // physical-device/source selection; app compatibility is about whether
        // the requested input is available to the miniapp.
        return true

      case HardwareType.SPEAKER:
        return capabilities.hasSpeaker

      case HardwareType.IMU:
        return capabilities.hasIMU

      case HardwareType.BUTTON:
        return capabilities.hasButton

      case HardwareType.LIGHT:
        return capabilities.hasLight

      case HardwareType.WIFI:
        return capabilities.hasWifi

      default:
        // Unknown hardware type - assume not available
        return false
    }
  }

  /**

   * Get human-readable compatibility message

   * @param result The compatibility check result

   * @returns User-friendly message about compatibility

   */
  static getCompatibilityMessage(result: CompatibilityResult): string {
    if (result.isCompatible) {
      if (result.missingOptional.length > 0) {
        const optionalHardware = result.missingOptional.map((req) => req.type.toLowerCase()).join(", ")
        return `This app works with your glasses but has optional features that require: ${optionalHardware}`
      }
      return "This app is fully compatible with your glasses"
    }

    const requiredHardware = result.missingRequired.map((req) => req.type.toLowerCase()).join(", ")

    if (result.missingRequired.length === 1) {
      return `This app requires a ${requiredHardware} which is not available on your connected glasses`
    } else {
      return `This app requires the following hardware which is not available on your connected glasses: ${requiredHardware}`
    }
  }

  /**

   * Get detailed compatibility messages including descriptions

   * @param result The compatibility check result

   * @returns Array of detailed messages

   */
  static getDetailedMessages(result: CompatibilityResult): string[] {
    const messages: string[] = []

    // Add warnings first
    messages.push(...result.warnings)

    // Add missing required hardware
    for (const req of result.missingRequired) {
      let message = `❌ Missing required ${req.type.toLowerCase()}`
      if (req.description) {
        message += `: ${req.description}`
      }
      messages.push(message)
    }

    // Add missing optional hardware
    for (const req of result.missingOptional) {
      let message = `⚠️ Missing optional ${req.type.toLowerCase()}`
      if (req.description) {
        message += `: ${req.description}`
      }
      messages.push(message)
    }

    return messages
  }
}