diff --git a/src/constants.ts b/src/constants.ts index 8299929..fcfb15d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,6 +5,8 @@ export const shareExtensionEntitlementsFileName = `${shareExtensionName}.entitle export const shareExtensionStoryBoardFileName = 'MainInterface.storyboard'; export const shareExtensionViewControllerFileName = 'ShareViewController.swift'; +export type Parameters = { activationRules?: { [key: string]: number | boolean | string} } + export const getAppGroups = (identifier: string) => [`group.${identifier}`]; export const getShareExtensionBundledIdentifier = (appIdentifier: string) => diff --git a/src/index.ts b/src/index.ts index ece4ded..a9fae58 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { withPlugins, } from "@expo/config-plugins"; +import { Parameters } from "./constants"; import { withAppEntitlements } from "./withAppEntitlements"; import { withShareExtensionConfig } from "./withShareExtensionConfig"; import { withShareExtensionXcodeTarget } from "./withShareExtensionXcodeTarget"; @@ -13,12 +14,12 @@ let pkg: { name: string; version?: string } = { version: "UNVERSIONED", }; -const withShareMenu: ConfigPlugin = createRunOncePlugin( - (config) => { +const withShareMenu: ConfigPlugin = createRunOncePlugin( + (config, params) => { return withPlugins(config, [ withAppEntitlements, withShareExtensionConfig, - withShareExtensionXcodeTarget, + () => withShareExtensionXcodeTarget(config, params), ]); }, pkg.name, diff --git a/src/withShareExtensionXcodeTarget.ts b/src/withShareExtensionXcodeTarget.ts index 4cbdfd2..6296564 100644 --- a/src/withShareExtensionXcodeTarget.ts +++ b/src/withShareExtensionXcodeTarget.ts @@ -1,6 +1,6 @@ import { ConfigPlugin, withXcodeProject } from '@expo/config-plugins'; -import { getShareExtensionBundledIdentifier, shareExtensionName } from './constants'; +import { Parameters, getShareExtensionBundledIdentifier, shareExtensionName } from './constants'; import { getShareExtensionEntitlementsFilePath, getShareExtensionInfoFilePath, @@ -9,7 +9,7 @@ import { writeShareExtensionFiles, } from './writeShareExtensionFiles'; -export const withShareExtensionXcodeTarget: ConfigPlugin = (config) => { +export const withShareExtensionXcodeTarget: ConfigPlugin = (config, parameters) => { return withXcodeProject(config, async (config) => { const extensionName = shareExtensionName; const platformProjectRoot = config.modRequest.platformProjectRoot; @@ -24,7 +24,7 @@ export const withShareExtensionXcodeTarget: ConfigPlugin = (config) => { const viewControllerFilePath = getShareExtensionViewControllerPath(platformProjectRoot); const storyboardFilePath = getShareExtensionStoryboardFilePath(platformProjectRoot); - await writeShareExtensionFiles(platformProjectRoot, scheme, appIdentifier); + await writeShareExtensionFiles(platformProjectRoot, scheme, appIdentifier, parameters); const pbxProject = config.modResults; diff --git a/src/writeShareExtensionFiles.ts b/src/writeShareExtensionFiles.ts index 450adc1..99bac23 100644 --- a/src/writeShareExtensionFiles.ts +++ b/src/writeShareExtensionFiles.ts @@ -9,15 +9,17 @@ import { shareExtensionInfoFileName, shareExtensionStoryBoardFileName, shareExtensionViewControllerFileName, + Parameters, } from "./constants"; export async function writeShareExtensionFiles( platformProjectRoot: string, scheme: string, - appIdentifier: string + appIdentifier: string, + parameters: Parameters ) { const infoPlistFilePath = getShareExtensionInfoFilePath(platformProjectRoot); - const infoPlistContent = getShareExtensionInfoContent(); + const infoPlistContent = getShareExtensionInfoContent(parameters.activationRules); await fs.promises.mkdir(path.dirname(infoPlistFilePath), { recursive: true }); await fs.promises.writeFile(infoPlistFilePath, infoPlistContent); @@ -34,7 +36,7 @@ export async function writeShareExtensionFiles( const viewControllerFilePath = getShareExtensionViewControllerPath(platformProjectRoot); - const viewControllerContent = getShareExtensionViewControllerContent(scheme); + const viewControllerContent = getShareExtensionViewControllerContent(scheme, appIdentifier); await fs.promises.writeFile(viewControllerFilePath, viewControllerContent); } @@ -68,7 +70,7 @@ export function getShareExtensionInfoFilePath(platformProjectRoot: string) { ); } -export function getShareExtensionInfoContent() { +export function getShareExtensionInfoContent(activationRules: Parameters["activationRules"]) { return plist.build({ CFBundleName: "$(PRODUCT_NAME)", CFBundleDisplayName: "Share Extension", @@ -79,7 +81,7 @@ export function getShareExtensionInfoContent() { CFBundlePackageType: "$(PRODUCT_BUNDLE_PACKAGE_TYPE)", NSExtension: { NSExtensionAttributes: { - NSExtensionActivationRule: { + NSExtensionActivationRule: activationRules || { NSExtensionActivationSupportsWebURLWithMaxCount: 1, NSExtensionActivationSupportsWebPageWithMaxCount: 1, }, @@ -140,8 +142,8 @@ export function getShareExtensionViewControllerPath( ); } -export function getShareExtensionViewControllerContent(scheme: string) { - console.debug("************ scheme", scheme); +export function getShareExtensionViewControllerContent(scheme: string, appIdentifier: string) { + console.debug("************ scheme", scheme, "appIdentifier", appIdentifier); return `import MobileCoreServices import Social