readCapacitorAppID reads the "appId" field from capacitor.config.json or capacitor.config.ts in dir. Capacitor v3+ defaults to the TypeScript config. Returns empty string if neither file is present or the field is missing.
(dir string)
| 610 | // capacitor.config.ts in dir. Capacitor v3+ defaults to the TypeScript config. |
| 611 | // Returns empty string if neither file is present or the field is missing. |
| 612 | func readCapacitorAppID(dir string) string { |
| 613 | // Try JSON config first (Capacitor v2 and v3+ both support it). |
| 614 | if data, err := os.ReadFile(filepath.Join(dir, "capacitor.config.json")); err == nil { |
| 615 | var cfg struct { |
| 616 | AppID string `json:"appId"` |
| 617 | } |
| 618 | if jsonErr := json.Unmarshal(data, &cfg); jsonErr == nil && cfg.AppID != "" { |
| 619 | return cfg.AppID |
| 620 | } |
| 621 | } |
| 622 | // Fall back to TypeScript config (Capacitor v3+ default). |
| 623 | // Process line-by-line to skip comment lines that may contain an appId value |
| 624 | // (e.g. "// appId: 'old.value'") which would otherwise be matched first. |
| 625 | if data, err := os.ReadFile(filepath.Join(dir, "capacitor.config.ts")); err == nil { |
| 626 | for _, line := range strings.Split(string(data), "\n") { |
| 627 | if strings.HasPrefix(strings.TrimSpace(line), "//") { |
| 628 | continue |
| 629 | } |
| 630 | if m := capacitorTSAppIDRegex.FindStringSubmatch(line); len(m) >= 3 { |
| 631 | // M[1] = single-quoted match, m[2] = double-quoted match. |
| 632 | if m[1] != "" { |
| 633 | return m[1] |
| 634 | } |
| 635 | if m[2] != "" { |
| 636 | return m[2] |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | return "" |
| 642 | } |
| 643 | |
| 644 | // readDotnetMobileBundleID extracts the <ApplicationId> element from .csproj content. |
| 645 | // Used for MAUI and .NET Mobile apps to generate callback URL guidance. |
no outgoing calls