summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/foundation/dependencies/active-intent.js
blob: 5270dd40a7a641ad489f81b1463329e20c62ff71 (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
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
import { isSome } from "@jet/environment/types/optional";
import { makeMetatype } from "@jet/environment/util/metatype";
import { unreachable } from "../util/errors";
export const ActiveIntentMetaType = makeMetatype("app-store:active-intent");
/**
 * Executes {@linkcode callback} with an {@linkcode AppStoreObjectGraph} that has been prepared with an
 * {@linkcode ActiveIntent} dependency
 *
 * This will allow code running within {@linkcode callback} to access meta-data about the active
 * {@linkcode Intent} without needing that information to be passed through every layer of the code
 */
export function withActiveIntent(objectGraph, intent, callback) {
    const objectGraphWithActiveIntent = objectGraph.addingActiveIntent({
        previewPlatform: intent.platform,
    });
    return callback(objectGraphWithActiveIntent);
}
/**
 * Ephemeral storage of `Intent`-specific details that need to be accessible
 * throughout the process of building that `Intent`'s result
 */
export class ActiveIntent {
    constructor(implementation) {
        this.implementation = implementation;
        this.inferredPreviewPlatform = undefined;
    }
    /**
     * Explicitly set a {@linkcode PreviewPlatform} for the active intent
     *
     * This might be a value derrived from an API response, in cases where the original `Intent`
     * was not specific about which platform to display
     */
    setInferredPreviewPlatform(platform) {
        this.inferredPreviewPlatform = platform;
    }
    /**
     * The {@linkcode PreviewPlatform} value of the current {@linkcode Intent}
     */
    get previewPlatform() {
        var _a;
        return (_a = this.inferredPreviewPlatform) !== null && _a !== void 0 ? _a : this.implementation.previewPlatform;
    }
    /**
     * The {@linkcode Platform} equivalent of the active {@linkcode PreviewPlatform}
     *
     * This translates the user-facing {@linkcode PreviewPlatform} into the "internal"
     * Media API {@linkcode Platform}
     */
    get platform() {
        if (isSome(this.previewPlatform)) {
            switch (this.previewPlatform) {
                case "ipad":
                case "iphone":
                case "mac":
                case "watch":
                    return this.previewPlatform;
                case "tv":
                    return "appletv";
                case "vision":
                    return "realityDevice";
                default:
                    unreachable(this.previewPlatform);
            }
        }
        return undefined;
    }
    /**
     * The {@linkcode AttributePlatform} equivalent of the active {@linkcode PreviewPlatform}
     *
     * This translates the user-facing {@linkcode PreviewPlatform} into the "internal"
     * {@linkcode AttributePlatform}
     */
    get attributePlatform() {
        if (isSome(this.previewPlatform)) {
            switch (this.previewPlatform) {
                case "iphone":
                case "ipad":
                    return "ios";
                case "mac":
                    return "osx";
                case "tv":
                    return "appletvos";
                case "vision":
                    return "xros";
                case "watch":
                    return "watch";
                default:
                    unreachable(this.previewPlatform);
            }
        }
        return undefined;
    }
    /**
     * The {@linkcode AppPlatform} equivalent of the active {@linkcode PreviewPlatform}
     *
     * This translates the user-facing {@linkcode PreviewPlatform} into the "internal"
     * {@linkcode AppPlatform}
     */
    get appPlatform() {
        if (isSome(this.previewPlatform)) {
            switch (this.previewPlatform) {
                case "ipad":
                    return "pad";
                case "iphone":
                    return "phone";
                case "mac":
                    return "mac";
                case "tv":
                    return "tv";
                case "vision":
                    return "vision";
                case "watch":
                    return "watch";
                default:
                    unreachable(this.previewPlatform);
            }
        }
        return undefined;
    }
}
//# sourceMappingURL=active-intent.js.map