forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-config.sh
More file actions
executable file
·85 lines (74 loc) · 2.52 KB
/
Copy pathapp-config.sh
File metadata and controls
executable file
·85 lines (74 loc) · 2.52 KB
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
#!/usr/bin/env bash
# Derive the macOS desktop dev app identity from OMI_APP_NAME.
# Sourced by run.sh and by tests; keep this file side-effect-light.
slugify_identifier() {
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-+/-/g'
}
derive_omi_app_config() {
local app_name="${1:-Omi Dev}"
local is_named_bundle="false"
local app_slug=""
local expected_bundle_id
local expected_url_scheme
local bundle_id
local url_scheme
if [ "$app_name" != "Omi Dev" ]; then
is_named_bundle="true"
fi
if [ "$is_named_bundle" = "false" ]; then
expected_bundle_id="com.omi.desktop-dev"
expected_url_scheme="omi-computer-dev"
else
app_slug="$(slugify_identifier "$app_name")"
if [ -z "$app_slug" ]; then
echo "ERROR: OMI_APP_NAME must contain at least one letter or number" >&2
return 1
fi
case "$app_slug" in
omi-*) ;;
*)
echo "ERROR: named OMI_APP_NAME values must use the omi- prefix (got '$app_name' -> '$app_slug')" >&2
return 1
;;
esac
expected_bundle_id="com.omi.$app_slug"
expected_url_scheme="omi-$app_slug"
fi
bundle_id="${OMI_BUNDLE_ID:-$expected_bundle_id}"
url_scheme="${OMI_URL_SCHEME:-$expected_url_scheme}"
if [ "$bundle_id" != "$expected_bundle_id" ]; then
echo "ERROR: APP_NAME '$app_name' must use bundle ID '$expected_bundle_id' (got '$bundle_id')" >&2
return 1
fi
if [ "$url_scheme" != "$expected_url_scheme" ]; then
echo "ERROR: APP_NAME '$app_name' must use URL scheme '$expected_url_scheme' (got '$url_scheme')" >&2
return 1
fi
APP_NAME="$app_name"
IS_NAMED_BUNDLE="$is_named_bundle"
APP_SLUG="$app_slug"
EXPECTED_BUNDLE_ID="$expected_bundle_id"
EXPECTED_URL_SCHEME="$expected_url_scheme"
BUNDLE_ID="$bundle_id"
URL_SCHEME="$url_scheme"
}
derive_omi_automation_ui_mode() {
local is_named_bundle="${1:-false}"
local requested_mode="${2:-}"
if [ -z "$requested_mode" ]; then
if [ "$is_named_bundle" = "true" ]; then
requested_mode="quiet"
else
requested_mode="normal"
fi
fi
case "$requested_mode" in
normal|quiet|interactive)
printf '%s\n' "$requested_mode"
;;
*)
echo "ERROR: OMI_AUTOMATION_UI_MODE must be normal, quiet, or interactive" >&2
return 1
;;
esac
}