summaryrefslogtreecommitdiff
path: root/shared/apps-common/src/jet/dependencies/host.ts
blob: 85a03f0c3610cbcf52499423d0a90ea6a8679310 (plain)
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
import type {
    ClientIdentifier,
    Host as NativeHost,
    ProcessPlatform,
} from '@jet/environment';
import type {} from '@jet/engine'; // For ClientIdentifier.Unknown

export class Host implements NativeHost {
    platform: ProcessPlatform = 'web';

    get osBuild(): never {
        throw makeWebDoesNotImplementException('osBuild');
    }

    get deviceModel(): string {
        return 'web';
    }

    get devicePhysicalModel(): never {
        throw makeWebDoesNotImplementException('devicePhysicalModel');
    }

    get deviceLocalizedModel() {
        return '';
    }

    get deviceModelFamily(): never {
        throw makeWebDoesNotImplementException('deviceModelFamily');
    }

    get clientIdentifier(): ClientIdentifier {
        // We can't directly use the `ClientIdentifier.Unknown` enum member value
        // because we cannot access "ambient const enums" with our TypeScript config.
        // Enum handling is known to be tough in TypeScript and, for reasons like
        // this, they are generally avoided.
        // This returns a value defined on this enum by `@jet/engine`'s type definition
        return 'unknown' as ClientIdentifier.Unknown;
    }

    get clientVersion(): never {
        throw makeWebDoesNotImplementException('clientVersion');
    }

    isOSAtLeast(
        _majorVersion: number,
        _minorVersion: number,
        _patchVersion: number,
    ): boolean {
        return true;
    }
}

export function makeWebDoesNotImplementException(property: keyof NativeHost) {
    return new Error(
        `\`Host\` property \`${property}\` is not implemented for the "web" platform`,
    );
}