Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions plugin/src/features/ios/eas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { addApplicationGroupsEntitlement, getWidgetExtensionEntitlements } from
export interface ConfigureEasBuildProps {
bundleIdentifier: string
targetName: string
groupIdentifier: string
groupIdentifier?: string
}

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ export const configureEasBuild: ConfigPlugin<ConfigureEasBuildProps> = (
configIndex = (config.extra?.eas?.build?.experimental?.ios?.appExtensions?.length ?? 1) - 1
}

// Configure entitlements
// Configure entitlements (may be empty if no groupIdentifier)
if (configIndex != null && config.extra) {
const widgetsExtensionConfig = config.extra.eas.build.experimental.ios.appExtensions[configIndex]

Expand All @@ -64,11 +64,13 @@ export const configureEasBuild: ConfigPlugin<ConfigureEasBuildProps> = (
...getWidgetExtensionEntitlements(groupIdentifier),
}

config.ios = {
...config.ios,
entitlements: {
...addApplicationGroupsEntitlement(config.ios?.entitlements ?? {}, groupIdentifier),
},
if (groupIdentifier) {
config.ios = {
...config.ios,
entitlements: {
...addApplicationGroupsEntitlement(config.ios?.entitlements ?? {}, groupIdentifier),
},
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions plugin/src/features/ios/files/entitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ export function addApplicationGroupsEntitlement(
/**
* Gets the entitlements for the widget extension.
*/
export function getWidgetExtensionEntitlements(groupIdentifier: string): Record<string, any> {
export function getWidgetExtensionEntitlements(groupIdentifier?: string): Record<string, any> {
const entitlements: Record<string, any> = {}
addApplicationGroupsEntitlement(entitlements, groupIdentifier)
if (groupIdentifier) {
addApplicationGroupsEntitlement(entitlements, groupIdentifier)
}
return entitlements
}

export interface GenerateEntitlementsOptions {
targetPath: string
targetName: string
groupIdentifier: string
groupIdentifier?: string
}

/**
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/features/ios/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateSwiftFiles } from './swift'
export interface GenerateWidgetExtensionFilesProps {
targetName: string
widgets?: WidgetConfig[]
groupIdentifier: string
groupIdentifier?: string
}

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export const generateWidgetExtensionFiles: ConfigPlugin<GenerateWidgetExtensionF
widgets,
})

// Generate entitlements file
// Generate entitlements file (may be empty if no groupIdentifier)
generateEntitlements({
targetPath,
targetName,
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/features/ios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface WithIOSProps {
bundleIdentifier: string
deploymentTarget: string
widgets?: WidgetConfig[]
groupIdentifier: string
groupIdentifier?: string
}

/**
Expand Down
8 changes: 6 additions & 2 deletions plugin/src/features/ios/plist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join as joinPath } from 'path'

export interface ConfigureMainAppPlistProps {
targetName: string
groupIdentifier: string
groupIdentifier?: string
}

/**
Expand Down Expand Up @@ -41,7 +41,11 @@ export const configureMainAppPlist: ConfigPlugin<ConfigureMainAppPlistProps> = (
CFBundleURLSchemes: [scheme],
},
]
;(content as any)['Voltra_AppGroupIdentifier'] = groupIdentifier

// Only set group identifier if provided
if (groupIdentifier) {
;(content as any)['Voltra_AppGroupIdentifier'] = groupIdentifier
}

writeFileSync(filePath, plist.build(content))
}
Expand Down
18 changes: 6 additions & 12 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ import { validateProps } from './validation'
* - Home Screen Widgets
* - Push Notifications for Live Activities (optional)
*/
const withVoltra: VoltraConfigPlugin = (config, props) => {
const withVoltra: VoltraConfigPlugin = (config, props = {}) => {
// Validate props at entry point
validateProps(props)

// After validation, props is guaranteed to be defined and have groupIdentifier
if (!props) {
throw new Error(
'Voltra plugin requires configuration. Please provide at least groupIdentifier in your plugin config.'
)
}

// Use deploymentTarget from props if provided, otherwise fall back to default
const deploymentTarget = props.deploymentTarget || IOS.DEPLOYMENT_TARGET
const targetName = `${IOSConfig.XcodeUtils.sanitizedName(config.name)}LiveActivity`
Expand All @@ -41,9 +34,10 @@ const withVoltra: VoltraConfigPlugin = (config, props) => {
...config.ios?.infoPlist,
NSSupportsLiveActivities: true,
NSSupportsLiveActivitiesFrequentUpdates: false,
Voltra_AppGroupIdentifier: props.groupIdentifier,
// Only add group identifier if provided
...(props?.groupIdentifier ? { Voltra_AppGroupIdentifier: props.groupIdentifier } : {}),
// Store widget IDs in Info.plist for native module to access
...(props.widgets && props.widgets.length > 0 ? { Voltra_WidgetIds: props.widgets.map((w) => w.id) } : {}),
...(props?.widgets && props.widgets.length > 0 ? { Voltra_WidgetIds: props.widgets.map((w) => w.id) } : {}),
},
}

Expand All @@ -52,8 +46,8 @@ const withVoltra: VoltraConfigPlugin = (config, props) => {
targetName,
bundleIdentifier,
deploymentTarget,
widgets: props.widgets,
groupIdentifier: props.groupIdentifier,
widgets: props?.widgets,
...(props?.groupIdentifier ? { groupIdentifier: props.groupIdentifier } : {}),
})

// Optionally enable push notifications
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ConfigPluginProps {
/**
* App group identifier for sharing data between app and widget extension
*/
groupIdentifier: string
groupIdentifier?: string
/**
* Configuration for home screen widgets
* Each widget will be available in the widget gallery
Expand All @@ -39,7 +39,7 @@ export interface IOSPluginProps {
bundleIdentifier: string
deploymentTarget: string
widgets?: WidgetConfig[]
groupIdentifier: string
groupIdentifier?: string
projectRoot: string
platformProjectRoot: string
}
27 changes: 9 additions & 18 deletions plugin/src/validation/validateProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ import { validateWidgetConfig } from './validateWidget'
* Validates the plugin props at entry point.
* Throws an error if validation fails.
*/
export function validateProps(props: ConfigPluginProps | undefined): void {
if (!props) {
throw new Error(
'Voltra plugin requires configuration. Please provide at least groupIdentifier in your plugin config.'
)
}

// Validate group identifier is provided
if (!props.groupIdentifier) {
throw new Error('groupIdentifier is required. Please provide a groupIdentifier in your Voltra plugin config.')
}

// Validate group identifier format
if (typeof props.groupIdentifier !== 'string') {
throw new Error('groupIdentifier must be a string')
}
export function validateProps(props: ConfigPluginProps): void {
// Validate group identifier format if provided
if (props.groupIdentifier !== undefined) {
if (typeof props.groupIdentifier !== 'string') {
throw new Error('groupIdentifier must be a string')
}

if (!props.groupIdentifier.startsWith('group.')) {
throw new Error(`groupIdentifier '${props.groupIdentifier}' must start with 'group.'`)
if (!props.groupIdentifier.startsWith('group.')) {
throw new Error(`groupIdentifier '${props.groupIdentifier}' must start with 'group.'`)
}
}

// Validate widgets if provided
Expand Down
Loading