mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-07 04:38:32 +08:00
Task alerts on iPhone can now be acted on without opening the app: - A question the agent asked shows a custom card when the alert is expanded (task, full question, what each option means) with one system button per option, plus "Reply" and "Open task". - A finished task can be replied to from the alert. - A low-risk permission request whose whole operation fits the alert offers "Allow once" (unlocked device only) and "Deny". The press is handled in the background: the app reconnects, re-reads the pending request from the computer, and answers only the request the alert described. A press that does not get through is reported with a local alert. Login credentials become readable after first unlock so this works while the phone is locked; a locked background cold launch is held instead of being treated as signed out. The agent Live Activity also gains a compact layout for the Apple Watch Smart Stack. Protocol: NotifyPayload gains an optional `action`. Old servers and apps ignore it. Native changes (new content extension target, background-work module, notification categories, Keychain accessibility) change the mobile runtime fingerprint and need a native release. Assisted-by: Cindy (https://cindy.app) Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
95 lines
4.5 KiB
JavaScript
95 lines
4.5 KiB
JavaScript
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const plist = require('@expo/plist');
|
|
const { withXcodeProject } = require('@expo/config-plugins');
|
|
|
|
const TARGET = 'CindyNotificationContent';
|
|
/** Alerts under this category open the custom view; see docs/product-rules/notification-actions.md. */
|
|
const CATEGORY = 'cindy.question.card';
|
|
|
|
function extensionInfo() {
|
|
return {
|
|
CFBundleDisplayName: 'Cindy',
|
|
CFBundleIdentifier: '$(PRODUCT_BUNDLE_IDENTIFIER)',
|
|
CFBundleExecutable: '$(EXECUTABLE_NAME)',
|
|
CFBundleName: '$(PRODUCT_NAME)',
|
|
CFBundlePackageType: 'XPC!',
|
|
CFBundleShortVersionString: '$(MARKETING_VERSION)',
|
|
CFBundleVersion: '$(CURRENT_PROJECT_VERSION)',
|
|
NSExtension: {
|
|
NSExtensionAttributes: {
|
|
UNNotificationExtensionCategory: [CATEGORY],
|
|
// The view draws the task and the whole question itself.
|
|
UNNotificationExtensionDefaultContentHidden: true,
|
|
UNNotificationExtensionInitialContentSizeRatio: 0.4,
|
|
UNNotificationExtensionUserInteractionEnabled: false,
|
|
},
|
|
NSExtensionPointIdentifier: 'com.apple.usernotifications.content-extension',
|
|
NSExtensionPrincipalClass: '$(PRODUCT_MODULE_NAME).NotificationViewController',
|
|
},
|
|
};
|
|
}
|
|
|
|
function configureProject(project, config, platformRoot) {
|
|
const bundleId = `${config.ios.bundleIdentifier}.${TARGET}`;
|
|
const directory = path.join(platformRoot, TARGET);
|
|
fs.mkdirSync(directory, { recursive: true });
|
|
fs.copyFileSync(path.join(__dirname, 'notification-content/NotificationViewController.swift'), path.join(directory, 'NotificationViewController.swift'));
|
|
fs.writeFileSync(path.join(directory, 'Info.plist'), plist.default.build(extensionInfo()));
|
|
let target = Object.entries(project.pbxNativeTargetSection())
|
|
.find(([key, value]) => !key.endsWith('_comment') && value.name?.replaceAll('"', '') === TARGET);
|
|
if (!target) {
|
|
const added = project.addTarget(TARGET, 'app_extension', TARGET, bundleId);
|
|
target = [added.uuid, added.pbxNativeTarget];
|
|
project.addBuildPhase([`${TARGET}/NotificationViewController.swift`], 'PBXSourcesBuildPhase', 'Sources', added.uuid);
|
|
project.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', added.uuid);
|
|
project.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', added.uuid);
|
|
}
|
|
const [, nativeTarget] = target;
|
|
const configurations = project.pbxXCConfigurationList()[nativeTarget.buildConfigurationList].buildConfigurations;
|
|
for (const item of configurations) {
|
|
const settings = project.pbxXCBuildConfigurationSection()[item.value].buildSettings;
|
|
Object.assign(settings, {
|
|
PRODUCT_BUNDLE_IDENTIFIER: `"${bundleId}"`,
|
|
INFOPLIST_FILE: `"${TARGET}/Info.plist"`,
|
|
CODE_SIGN_STYLE: 'Automatic',
|
|
SWIFT_VERSION: '5.0',
|
|
IPHONEOS_DEPLOYMENT_TARGET: '15.0',
|
|
TARGETED_DEVICE_FAMILY: '"1,2"',
|
|
APPLICATION_EXTENSION_API_ONLY: 'YES',
|
|
CURRENT_PROJECT_VERSION: `"${config.ios.buildNumber ?? '1'}"`,
|
|
MARKETING_VERSION: `"${config.version ?? '1.0'}"`,
|
|
GENERATE_INFOPLIST_FILE: 'NO',
|
|
// The extension context class lives in UserNotificationsUI. The Swift source only adopts
|
|
// its protocol, which references no symbol, so the framework must be linked explicitly
|
|
// or the extension stops at launch ("Unable to find NSExtensionContextClass").
|
|
OTHER_LDFLAGS: '"-framework UserNotificationsUI -framework UserNotifications"',
|
|
...(config.ios.appleTeamId ? { DEVELOPMENT_TEAM: config.ios.appleTeamId } : {}),
|
|
});
|
|
}
|
|
return project;
|
|
}
|
|
|
|
/** Generates the notification content extension that shows a question with its options. */
|
|
module.exports = function withNotificationContent(config) {
|
|
// EAS needs extension credentials before prebuild creates the native target.
|
|
const experimental = config.extra?.eas?.build?.experimental ?? {};
|
|
config.extra = { ...config.extra, eas: { ...config.extra?.eas, build: {
|
|
...config.extra?.eas?.build,
|
|
experimental: { ...experimental, ios: {
|
|
...experimental.ios,
|
|
appExtensions: [
|
|
...(experimental.ios?.appExtensions ?? []).filter(item => item.targetName !== TARGET),
|
|
{ targetName: TARGET, bundleIdentifier: `${config.ios.bundleIdentifier}.${TARGET}` },
|
|
],
|
|
} },
|
|
} } };
|
|
return withXcodeProject(config, mod => {
|
|
configureProject(mod.modResults, mod, mod.modRequest.platformProjectRoot);
|
|
return mod;
|
|
});
|
|
};
|
|
module.exports.configureProject = configureProject;
|
|
module.exports.extensionInfo = extensionInfo;
|
|
module.exports.CATEGORY = CATEGORY;
|